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