Alexey Kim 2 днів тому
батько
коміт
8416660488
2 змінених файлів з 11 додано та 7 видалено
  1. 3 3
      order_options.go
  2. 8 4
      util/order.go

+ 3 - 3
order_options.go

@@ -3,8 +3,8 @@ package sentio
 type OrderOptions struct {
 	Symbol     string
 	Action     Action
-	Limit      float64
+	Limit      *float64
 	Size       uint
-	TakeProfit float64
-	StopLoss   float64
+	TakeProfit *float64
+	StopLoss   *float64
 }

+ 8 - 4
util/order.go

@@ -8,6 +8,10 @@ import (
 
 const TradingRange = .02
 
+func ToPtr[T any](x T) *T {
+	return &x
+}
+
 func NewOrder(
 	m sentio.Market,
 	s sentio.Strategy,
@@ -32,18 +36,18 @@ func NewOrder(
 
 	bid = sentio.ToFixed(quotes[opts.Symbol].BidPrice, 2)
 	opts.Action = sentio.Action_BUY
-	opts.TakeProfit = sentio.ToFixed(rm.TakeProfit(opts.Symbol, bid), 2)
-	opts.StopLoss = sentio.ToFixed(rm.StopLoss(opts.Symbol, bid), 2)
+	opts.TakeProfit = ToPtr(sentio.ToFixed(rm.TakeProfit(opts.Symbol, bid), 2))
+	opts.StopLoss = ToPtr(sentio.ToFixed(rm.StopLoss(opts.Symbol, bid), 2))
 
 	// Prevent orders those have too small expected profit
-	if opts.TakeProfit < bid+TradingRange {
+	if *opts.TakeProfit < bid+TradingRange {
 		err = sentio.ErrLowTakeProfit
 		return
 	}
 
 	// Prevent cases when order will be closed ASAP they were opened.
 	// Also, Alpaca requires at least 0.01 gap against base_price
-	if opts.StopLoss > bid-TradingRange {
+	if *opts.StopLoss > bid-TradingRange {
 		err = sentio.ErrHighStoploss
 		return
 	}