mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 17:13:51 +00:00
ftx: cancel orders
This commit is contained in:
parent
7ecb17dbe2
commit
342b0dd1dd
|
@ -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 {
|
||||
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) {
|
||||
|
|
|
@ -62,6 +62,39 @@ func (r *orderRequest) PlaceOrder(ctx context.Context, p PlaceOrderPayload) (ord
|
|||
|
||||
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) {
|
||||
resp, err := r.
|
||||
|
|
|
@ -3,7 +3,7 @@ package ftx
|
|||
import "time"
|
||||
|
||||
type balances struct {
|
||||
Success bool `json:"Success"`
|
||||
Success bool `json:"success"`
|
||||
|
||||
Result []struct {
|
||||
Coin string `json:"coin"`
|
||||
|
@ -13,11 +13,16 @@ type balances struct {
|
|||
}
|
||||
|
||||
type ordersResponse struct {
|
||||
Success bool `json:"Success"`
|
||||
Success bool `json:"success"`
|
||||
|
||||
Result []order `json:"result"`
|
||||
}
|
||||
|
||||
type cancelOrderResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Result string `json:"result"`
|
||||
}
|
||||
|
||||
type order struct {
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
FilledSize float64 `json:"filledSize"`
|
||||
|
@ -39,7 +44,7 @@ type order struct {
|
|||
}
|
||||
|
||||
type orderResponse struct {
|
||||
Success bool `json:"Success"`
|
||||
Success bool `json:"success"`
|
||||
|
||||
Result order `json:"result"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user