[fix] midprice fix

This commit is contained in:
ying liu 2024-07-29 13:15:56 +08:00
parent 4cb31648ad
commit e0657fc9b4

View File

@ -149,11 +149,14 @@ func (s *Strategy) generateOrders(ctx context.Context, kline types.KLine) ([]typ
log.Infof(fmt.Sprintf("place order keline info: symbol %s, high %v, low %v, open %v, close %v", symbol,
kline.High.Float64(), kline.Low.Float64(), kline.Open.Float64(), kline.Close.Float64()))
placePrice := fixedpoint.Value(0)
midPrice := (kline.High.Add(kline.Low)).Div(fixedpoint.Value(2.0))
//midPrice := (kline.High.Add(kline.Low)).Div(fixedpoint.Value(2.0))
//midP := (kline.High + kline.Low) / 2
if s.TradeType[symbol] == "long" {
placePrice = midPrice
placePrice = kline.Low
//placePrice = midP
} else if s.TradeType[symbol] == "short" {
placePrice = midPrice
placePrice = kline.High
//placePrice = midP
} else {
return orders, nil
}
@ -360,12 +363,12 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor qbtrade.OrderExecutor,
if !s.Traded[symbol] {
// 如若在下一根k线未成交 则取消订单
if s.TradeType[symbol] != "" && s.TradeRetry[symbol] > 1 {
if s.TradeType[symbol] != "" && s.TradeRetry[symbol] > 10 {
qbtrade.Notify(fmt.Sprintf("交易信号未成交,取消订单: %s", symbol))
s.cancelOrders(ctx, symbol)
}
if s.TradeType[symbol] != "" && s.TradeRetry[symbol] <= 1 {
if s.TradeType[symbol] != "" && s.TradeRetry[symbol] <= 10 {
s.TradeRetry[symbol] = s.TradeRetry[symbol] + 1
}
}