mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
ftx: rewrite order cancel handling
This commit is contained in:
parent
dd76cfafa4
commit
86af4d2b40
|
@ -2,6 +2,7 @@ package ftx
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -560,18 +561,26 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) erro
|
|||
logrus.WithError(err).Error("rate limit error")
|
||||
}
|
||||
|
||||
var resp *ftxapi.APIResponse
|
||||
var err error
|
||||
if len(o.ClientOrderID) > 0 {
|
||||
req := e.client.NewCancelOrderByClientOrderIdRequest(o.ClientOrderID)
|
||||
_, err := req.Do(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err = req.Do(ctx)
|
||||
} else {
|
||||
req := e.client.NewCancelOrderRequest(strconv.FormatUint(o.OrderID, 10))
|
||||
_, err := req.Do(ctx)
|
||||
resp, err = req.Do(ctx)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !resp.Success {
|
||||
v, err := unmarshalResult(resp.Result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("cancel order failed: %v", v)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -655,3 +664,8 @@ func (e *Exchange) Transfer(ctx context.Context, coin string, size float64, dest
|
|||
}
|
||||
return resp.Result.String(), nil
|
||||
}
|
||||
|
||||
func unmarshalResult(result json.RawMessage) (a interface{}, err error) {
|
||||
err = json.Unmarshal(result, &a)
|
||||
return a, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user