Skip to content

Commit

Permalink
new function IsFilledOrderState for maxapi
Browse files Browse the repository at this point in the history
  • Loading branch information
kbearXD committed Mar 14, 2024
1 parent fb2a46e commit 2b52211
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 4 additions & 0 deletions pkg/exchange/max/maxapi/order.go
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions pkg/strategy/dca2/recover.go
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions pkg/strategy/dca2/strategy.go
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down

0 comments on commit 2b52211

Please sign in to comment.