Alexey Kim 3 тижнів тому
батько
коміт
05894d68ed
1 змінених файлів з 8 додано та 8 видалено
  1. 8 8
      strategy/alpaca/qqq15/strategy.go

+ 8 - 8
strategy/alpaca/qqq15/strategy.go

@@ -41,9 +41,15 @@ func (s alpacaQQQ) Handle(market sentio.Market, proba float64) ([]sentio.Strateg
 	var (
 		portfolio sentio.Portfolio
 		orders    []sentio.StrategyOrder
+		now       = market.Time().Now()
 		err       error
 	)
 
+	// skip too early trades
+	if now.Hour() == 9 && now.Minute() < 40 {
+		return orders, nil
+	}
+
 	if portfolio, err = market.Portfolio(); err != nil {
 		return nil, err
 	}
@@ -52,7 +58,6 @@ func (s alpacaQQQ) Handle(market sentio.Market, proba float64) ([]sentio.Strateg
 		var (
 			position sentio.Position
 			ok       bool
-			t        = market.Time().Now()
 		)
 
 		// no need to trade BASE quote
@@ -60,11 +65,6 @@ func (s alpacaQQQ) Handle(market sentio.Market, proba float64) ([]sentio.Strateg
 			continue
 		}
 
-		// skip too early trades
-		if t.Hour() == 9 && t.Minute() < 40 {
-			continue
-		}
-
 		if portfolio != nil {
 			position, ok = portfolio.Get(symbol)
 			ok = ok && position != nil && position.GetSize() != 0
@@ -73,7 +73,7 @@ func (s alpacaQQQ) Handle(market sentio.Market, proba float64) ([]sentio.Strateg
 		}
 
 		// Close positions before market closed
-		if ok && t.Hour() == 15 && t.Minute() > 45 {
+		if ok && now.Hour() == 15 && now.Minute() > 45 {
 			orders = append(orders, sentio.StrategyOrder{
 				Symbol: symbol,
 				Action: sentio.OrderSell,
@@ -105,7 +105,7 @@ func (s alpacaQQQ) Handle(market sentio.Market, proba float64) ([]sentio.Strateg
 			}}, nil
 		}
 
-		if t.Hour() == 15 && t.Minute() > 35 {
+		if now.Hour() == 15 && now.Minute() > 35 {
 			continue
 		}