[fix] notife

This commit is contained in:
ying liu 2024-07-29 18:35:12 +08:00
parent 7bb439f8d3
commit 2288f0ffe2
2 changed files with 17 additions and 5 deletions

View File

@ -47,6 +47,7 @@ exchangeStrategies:
profitRange: 2%
lossRange: 1%
amount: 20
place: true
# recalculate: false
# dry_run: false
# # quantity: 3

View File

@ -32,6 +32,7 @@ type Strategy struct {
Interval types.Interval `json:"interval"`
NrCount int `json:"nrCount"`
StrictMode bool `json:"strictMode"`
Place bool `json:"place"`
DryRun bool `json:"dryRun"`
CCIWindow int `json:"cciWindow"`
LongCCI fixedpoint.Value `json:"longCCI"`
@ -39,6 +40,7 @@ type Strategy struct {
Leverage fixedpoint.Value `json:"leverage"`
ProfitRange fixedpoint.Value `json:"profitRange"`
LossRange fixedpoint.Value `json:"lossRange"`
qbtrade.QuantityOrAmount
//Position *types.Position `persistence:"position"`
@ -151,10 +153,19 @@ func (s *Strategy) generateOrders(ctx context.Context, kline types.KLine) ([]typ
//midPrice := (kline.High.Add(kline.Low)).Div(fixedpoint.Value(2.0))
//midP := (kline.High + kline.Low) / 2
if s.TradeType[symbol] == "long" {
if s.Place {
placePrice = kline.High
} else {
placePrice = kline.Low
}
//placePrice = midP
} else if s.TradeType[symbol] == "short" {
if s.Place {
placePrice = kline.Low
} else {
placePrice = kline.High
}
//placePrice = midP
} else {
return orders, nil
@ -290,7 +301,7 @@ func (s *Strategy) notifyProfit(ctx context.Context, symbol string) {
}
msg := fmt.Sprintf("交易完成:\n 币种: %s, 方向:%v, 收益:%v, 手续费:%v \n Trade详情\n 开仓Trade\n %s\n 清仓Trade\n %s",
symbol, s.TradeType, profit, free.Float64(), strings.Join(openMsgs, "\n"), strings.Join(endMsgs, "\n"))
symbol, s.TradeType[symbol], profit, free.Float64(), strings.Join(openMsgs, "\n"), strings.Join(endMsgs, "\n"))
log.Infof(msg)
qbtrade.Notify(msg)
@ -412,7 +423,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor qbtrade.OrderExecutor,
order, order.OrderID, orderSymbol, order.Type, order.Status)
s.Traded[orderSymbol] = true
s.TradeRetry[orderSymbol] = 0
qbtrade.Notify("订单成交通知:\n 币种:%s, 方向:%s, 价格:%s, 数量:%s", order.Symbol, s.TradeType,
qbtrade.Notify("订单成交通知:\n 币种:%s, 方向:%s, 价格:%s, 数量:%s", order.Symbol, s.TradeType[orderSymbol],
order.Price, order.Quantity)
}
if order.Type == types.OrderTypeLimit && order.Side == types.SideTypeSell {
@ -420,7 +431,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor qbtrade.OrderExecutor,
order, order.OrderID, orderSymbol, order.Type, order.Status)
s.Traded[orderSymbol] = true
s.TradeRetry[orderSymbol] = 0
qbtrade.Notify("订单成交通知:\n 币种:%s, 方向:%s, 价格:%s, 数量:%s", order.Symbol, s.TradeType,
qbtrade.Notify("订单成交通知:\n 币种:%s, 方向:%s, 价格:%s, 数量:%s", order.Symbol, s.TradeType[orderSymbol],
order.Price, order.Quantity)
}