|
@@ -51,28 +51,29 @@ func NewOrder(
|
|
opts.TakeProfit = ToPtr(sentio.ToFixed(rm.TakeProfit(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))
|
|
opts.StopLoss = ToPtr(sentio.ToFixed(rm.StopLoss(opts.Symbol, bid), 2))
|
|
|
|
|
|
|
|
+ // Invert OrderOptions if we will do SHORT for BASE symbol
|
|
|
|
+ if sentio.SHORT == side && !canLeverage {
|
|
|
|
+ tmp := opts.StopLoss
|
|
|
|
+ opts.StopLoss = opts.TakeProfit
|
|
|
|
+ opts.TakeProfit = tmp
|
|
|
|
+
|
|
|
|
+ opts.Action = sentio.Action_SELL
|
|
|
|
+ }
|
|
|
|
+
|
|
// Prevent orders those have too small expected profit
|
|
// Prevent orders those have too small expected profit
|
|
- if *opts.TakeProfit < bid+TradingRange {
|
|
|
|
|
|
+ if (opts.Action == sentio.Action_BUY && *opts.TakeProfit < bid+TradingRange) ||
|
|
|
|
+ (opts.Action == sentio.Action_SELL && *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.Action == sentio.Action_BUY && *opts.StopLoss > bid-TradingRange {
|
|
err = sentio.ErrHighStoploss
|
|
err = sentio.ErrHighStoploss
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- // Invert OrderOptions if we will do SHORT for BASE symbol
|
|
|
|
- if sentio.SHORT == side && !canLeverage {
|
|
|
|
- tmp := opts.StopLoss
|
|
|
|
- opts.StopLoss = opts.TakeProfit
|
|
|
|
- opts.TakeProfit = tmp
|
|
|
|
-
|
|
|
|
- opts.Action = sentio.Action_SELL
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
var (
|
|
var (
|
|
account sentio.MarketAccount
|
|
account sentio.MarketAccount
|
|
cash float64
|
|
cash float64
|