new function IsFilledOrderState for maxapi

This commit is contained in:
kbearXD 2024-03-14 16:18:12 +08:00
parent fb2a46e1c4
commit 2b52211c1c
3 changed files with 9 additions and 9 deletions

View File

@ -46,6 +46,10 @@ const (
OrderStateFailed = OrderState("failed")
)
func IsFilledOrderState(state OrderState) bool {
return state == OrderStateDone || state == OrderStateFinalizing
}
type OrderType string
// Order types that the API can return.

View File

@ -82,8 +82,9 @@ func recoverState(ctx context.Context, maxOrderCount int, currentRound Round, or
// dca stop at take-profit order stage
if currentRound.TakeProfitOrder.OrderID != 0 {
if len(currentRound.OpenPositionOrders) != maxOrderCount {
return None, fmt.Errorf("there is take-profit order but the number of open-position orders (%d) is not the same as maxOrderCount(%d). Please check it", len(currentRound.OpenPositionOrders), maxOrderCount)
// the number of open-positions orders may not be equal to maxOrderCount, because the notional may not enough to open maxOrderCount orders
if len(currentRound.OpenPositionOrders) > maxOrderCount {
return None, fmt.Errorf("there is take-profit order but the number of open-position orders (%d) is greater than maxOrderCount(%d). Please check it", len(currentRound.OpenPositionOrders), maxOrderCount)
}
takeProfitOrder := currentRound.TakeProfitOrder

View File

@ -431,12 +431,7 @@ func (s *Strategy) CalculateAndEmitProfit(ctx context.Context, historyService ty
continue
}
} else {
switch maxapi.OrderState(order.OriginalStatus) {
case maxapi.OrderStateDone:
// the same as filled
case maxapi.OrderStateFinalizing:
// the same as filled
default:
if !maxapi.IsFilledOrderState(maxapi.OrderState(order.OriginalStatus)) {
s.logger.Infof("isMax and take-profit order is %s not done or finalizing, so this round is not finished. Skip it", order.OriginalStatus)
continue
}
@ -452,7 +447,7 @@ func (s *Strategy) CalculateAndEmitProfit(ctx context.Context, historyService ty
s.logger.Infof("there are %d rounds from order id #%d", len(rounds), s.ProfitStats.FromOrderID)
for _, round := range rounds {
debugRoundOrders(s.logger, "calculate", round)
debugRoundOrders(s.logger, strconv.FormatInt(s.ProfitStats.Round, 10), round)
var roundOrders []types.Order = round.OpenPositionOrders
roundOrders = append(roundOrders, round.TakeProfitOrder)
for _, order := range roundOrders {