@@ -6,10 +6,11 @@ import (
6
6
"strconv"
7
7
"time"
8
8
9
+ "github.com/pkg/errors"
10
+
9
11
"github.com/c9s/bbgo/pkg/bbgo"
10
12
"github.com/c9s/bbgo/pkg/exchange/retry"
11
13
"github.com/c9s/bbgo/pkg/types"
12
- "github.com/pkg/errors"
13
14
)
14
15
15
16
var recoverSinceLimit = time .Date (2024 , time .January , 29 , 12 , 0 , 0 , 0 , time .Local )
@@ -65,7 +66,7 @@ func recoverState(ctx context.Context, maxOrderCount int, currentRound Round, or
65
66
66
67
// dca stop at take-profit order stage
67
68
if len (currentRound .TakeProfitOrders ) > 0 {
68
- openedOrders , cancelledOrders , filledOrders , unexpectedOrders := classifyOrders (currentRound .TakeProfitOrders )
69
+ openedOrders , cancelledOrders , filledOrders , unexpectedOrders := types . ClassifyOrdersByStatus (currentRound .TakeProfitOrders )
69
70
70
71
if len (unexpectedOrders ) > 0 {
71
72
return None , fmt .Errorf ("there is unexpected status in orders %+v" , unexpectedOrders )
@@ -96,7 +97,7 @@ func recoverState(ctx context.Context, maxOrderCount int, currentRound Round, or
96
97
}
97
98
98
99
// collect open-position orders' status
99
- openedOrders , cancelledOrders , filledOrders , unexpectedOrders := classifyOrders (currentRound .OpenPositionOrders )
100
+ openedOrders , cancelledOrders , filledOrders , unexpectedOrders := types . ClassifyOrdersByStatus (currentRound .OpenPositionOrders )
100
101
if len (unexpectedOrders ) > 0 {
101
102
return None , fmt .Errorf ("there is unexpected status of orders %+v" , unexpectedOrders )
102
103
}
@@ -124,7 +125,9 @@ func recoverState(ctx context.Context, maxOrderCount int, currentRound Round, or
124
125
return OpenPositionOrdersCancelling , nil
125
126
}
126
127
127
- func recoverPosition (ctx context.Context , position * types.Position , currentRound Round , queryService types.ExchangeOrderQueryService ) error {
128
+ func recoverPosition (
129
+ ctx context.Context , position * types.Position , currentRound Round , queryService types.ExchangeOrderQueryService ,
130
+ ) error {
128
131
if position == nil {
129
132
return fmt .Errorf ("position is nil, please check it" )
130
133
}
@@ -191,20 +194,3 @@ func recoverStartTimeOfNextRound(ctx context.Context, currentRound Round, coolDo
191
194
192
195
return startTimeOfNextRound
193
196
}
194
-
195
- func classifyOrders (orders []types.Order ) (opened , cancelled , filled , unexpected []types.Order ) {
196
- for _ , order := range orders {
197
- switch order .Status {
198
- case types .OrderStatusNew , types .OrderStatusPartiallyFilled :
199
- opened = append (opened , order )
200
- case types .OrderStatusFilled :
201
- filled = append (filled , order )
202
- case types .OrderStatusCanceled :
203
- cancelled = append (cancelled , order )
204
- default :
205
- unexpected = append (unexpected , order )
206
- }
207
- }
208
-
209
- return opened , cancelled , filled , unexpected
210
- }
0 commit comments