ftx: cancel orders

This commit is contained in:
ycdesu 2021-03-16 22:31:17 +08:00
parent 7ecb17dbe2
commit 342b0dd1dd
3 changed files with 54 additions and 4 deletions

View File

@ -161,7 +161,19 @@ func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since,
} }
func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) error { func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) error {
panic("implement me") for _, o := range orders {
rest := e.newRest()
if len(o.ClientOrderID) > 0 {
if _, err := rest.CancelOrderByClientID(ctx, o.ClientOrderID); err != nil {
return err
}
continue
}
if _, err := rest.CancelOrderByOrderID(ctx, o.OrderID); err != nil {
return err
}
}
return nil
} }
func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error) { func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error) {

View File

@ -62,6 +62,39 @@ func (r *orderRequest) PlaceOrder(ctx context.Context, p PlaceOrderPayload) (ord
return o, nil return o, nil
} }
func (r *orderRequest) CancelOrderByOrderID(ctx context.Context, orderID uint64) (cancelOrderResponse, error) {
resp, err := r.
Method("DELETE").
ReferenceURL("api/orders").
Payloads(map[string]interface{}{"order_id": orderID}).
DoAuthenticatedRequest(ctx)
if err != nil {
return cancelOrderResponse{}, err
}
var co cancelOrderResponse
if err := json.Unmarshal(resp.Body, &r); err != nil {
return cancelOrderResponse{}, err
}
return co, nil
}
func (r *orderRequest) CancelOrderByClientID(ctx context.Context, clientID string) (cancelOrderResponse, error) {
resp, err := r.
Method("DELETE").
ReferenceURL("api/orders/by_client_id").
Payloads(map[string]interface{}{"client_order_id": clientID}).
DoAuthenticatedRequest(ctx)
if err != nil {
return cancelOrderResponse{}, err
}
var co cancelOrderResponse
if err := json.Unmarshal(resp.Body, &r); err != nil {
return cancelOrderResponse{}, err
}
return co, nil
}
func (r *orderRequest) OpenOrders(ctx context.Context, market string) (ordersResponse, error) { func (r *orderRequest) OpenOrders(ctx context.Context, market string) (ordersResponse, error) {
resp, err := r. resp, err := r.

View File

@ -3,7 +3,7 @@ package ftx
import "time" import "time"
type balances struct { type balances struct {
Success bool `json:"Success"` Success bool `json:"success"`
Result []struct { Result []struct {
Coin string `json:"coin"` Coin string `json:"coin"`
@ -13,11 +13,16 @@ type balances struct {
} }
type ordersResponse struct { type ordersResponse struct {
Success bool `json:"Success"` Success bool `json:"success"`
Result []order `json:"result"` Result []order `json:"result"`
} }
type cancelOrderResponse struct {
Success bool `json:"success"`
Result string `json:"result"`
}
type order struct { type order struct {
CreatedAt time.Time `json:"createdAt"` CreatedAt time.Time `json:"createdAt"`
FilledSize float64 `json:"filledSize"` FilledSize float64 `json:"filledSize"`
@ -39,7 +44,7 @@ type order struct {
} }
type orderResponse struct { type orderResponse struct {
Success bool `json:"Success"` Success bool `json:"success"`
Result order `json:"result"` Result order `json:"result"`
} }