Browse Source

refactoring

Alexey Kim 1 day ago
parent
commit
c606ececff
3 changed files with 9 additions and 30 deletions
  1. 2 0
      order.go
  2. 7 12
      strategy/alpaca/ppo_250625/strategy.go
  3. 0 18
      util/strategy.go

+ 2 - 0
order.go

@@ -35,4 +35,6 @@ type Order interface {
 	GetPnL() float64
 	GetCurrency() string
 	GetStatus() string
+	
+	Intent() Side
 }

+ 7 - 12
strategy/alpaca/ppo_250625/strategy.go

@@ -30,12 +30,12 @@ func (strategy qqq) PositionSymbols() map[sentio.Side]string {
 	return map[sentio.Side]string{
 		sentio.BASE:  "QQQ",
 		sentio.LONG:  "TQQQ",
-		sentio.SHORT: "SQQQ",
+		sentio.SHORT: "QQQ",
 	}
 }
 
 func (strategy qqq) MaxTradeDuration() time.Duration {
-	return time.Duration(strategy.Interval()) * time.Minute * 5
+	return time.Duration(strategy.Interval()) * time.Minute * 15
 }
 
 func (strategy qqq) Handle(turn *sentio.Turn, market sentio.Market, rs sentio.RiskManager) error {
@@ -70,15 +70,11 @@ func (strategy qqq) Handle(turn *sentio.Turn, market sentio.Market, rs sentio.Ri
 	}
 
 	// update stoplosses or close running orders
-	var (
-		ts              = turn.Time.AsTime().Round(time.Minute)
-		hasClosedOrders = false
-	)
+	var hasClosedOrders = false
 
 	for i := range orders {
-		if util.IsLongOrder(orders[i], strategy) &&
-			sentio.Action_SELL == turn.Action &&
-			ts.Before(time.Now()) {
+		if sentio.LONG == orders[i].Intent() &&
+			sentio.Action_SELL == turn.Action {
 			if _, err = market.CloseOrder(orders[i], nil); err != nil {
 				return err
 			}
@@ -87,9 +83,8 @@ func (strategy qqq) Handle(turn *sentio.Turn, market sentio.Market, rs sentio.Ri
 			continue
 		}
 
-		if util.IsShortOrder(orders[i], strategy) &&
-			sentio.Action_BUY == turn.Action &&
-			ts.Before(time.Now()) {
+		if sentio.SHORT == orders[i].Intent() &&
+			sentio.Action_BUY == turn.Action {
 			if _, err = market.CloseOrder(orders[i], nil); err != nil {
 				return err
 			}

+ 0 - 18
util/strategy.go

@@ -2,7 +2,6 @@ package util
 
 import (
 	"git.beejay.kim/Gshopper/sentio"
-	"strings"
 )
 
 func Symbols(strategy sentio.Strategy) []string {
@@ -22,20 +21,3 @@ func Symbols(strategy sentio.Strategy) []string {
 
 	return symbols
 }
-
-func isOrderPosition(order sentio.Order, strategy sentio.Strategy, position sentio.Side) bool {
-	symbol, ok := strategy.PositionSymbols()[position]
-	if !ok {
-		return false
-	}
-
-	return strings.ToLower(strings.TrimSpace(symbol)) == strings.ToLower(strings.TrimSpace(order.GetSymbol()))
-}
-
-func IsLongOrder(order sentio.Order, strategy sentio.Strategy) bool {
-	return isOrderPosition(order, strategy, sentio.LONG)
-}
-
-func IsShortOrder(order sentio.Order, strategy sentio.Strategy) bool {
-	return isOrderPosition(order, strategy, sentio.SHORT)
-}