File tree 1 file changed +18
-1
lines changed
1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -144,17 +144,34 @@ func QueryClosedOrdersUntilSuccessfulLite(
144
144
return closedOrders , err
145
145
}
146
146
147
+ var ErrTradeFeeIsProcessing = errors .New ("trading fee is still processing" )
148
+ var ErrTradeNotExecutedYet = errors .New ("trades not executed yet" )
149
+
147
150
// QueryOrderTradesUntilSuccessful query order's trades until success (include the trading fee is not processing)
148
151
func QueryOrderTradesUntilSuccessful (
149
152
ctx context.Context , ex types.ExchangeOrderQueryService , q types.OrderQuery ,
150
153
) (trades []types.Trade , err error ) {
154
+ // sometimes the api might return empty trades without an error when we query the order too soon,
155
+ // so in the initial attempts, we should check the len(trades) and retry the query
156
+ var initialAttempts = 3
151
157
var op = func () (err2 error ) {
152
158
trades , err2 = ex .QueryOrderTrades (ctx , q )
159
+ if err2 != nil {
160
+ return err2
161
+ }
162
+
163
+ initialAttempts --
164
+
165
+ if initialAttempts > 0 && len (trades ) == 0 {
166
+ return ErrTradeNotExecutedYet
167
+ }
168
+
153
169
for _ , trade := range trades {
154
170
if trade .FeeProcessing {
155
- return fmt . Errorf ( "there are some trades which trading fee is not ready" )
171
+ return ErrTradeFeeIsProcessing
156
172
}
157
173
}
174
+
158
175
return err2
159
176
}
160
177
You can’t perform that action at this time.
0 commit comments