ftx: define ordersHistory in rest client

This commit is contained in:
ycdesu 2021-03-17 08:18:37 +08:00
parent 28b5a14b5e
commit 54ca62ac5c
2 changed files with 38 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"time"
) )
type orderRequest struct { type orderRequest struct {
@ -114,3 +115,34 @@ func (r *orderRequest) OpenOrders(ctx context.Context, market string) (ordersRes
return o, nil return o, nil
} }
func (r *orderRequest) OrdersHistory(ctx context.Context, market string, start, end time.Time, limit int) (ordersHistoryResponse, error) {
p := map[string]interface{}{
"market": market,
"limit": limit,
}
if start != (time.Time{}) {
p["start_time"] = start.UnixNano() / int64(time.Second)
}
if end != (time.Time{}) {
p["end_time"] = start.UnixNano() / int64(time.Second)
}
resp, err := r.
Method("GET").
ReferenceURL("api/orders/history").
Payloads(p).
DoAuthenticatedRequest(ctx)
if err != nil {
return ordersHistoryResponse{}, err
}
var o ordersHistoryResponse
if err := json.Unmarshal(resp.Body, &o); err != nil {
return ordersHistoryResponse{}, fmt.Errorf("failed to unmarshal orders history response body to json: %w", err)
}
return o, nil
}

View File

@ -12,6 +12,12 @@ type balances struct {
} `json:"result"` } `json:"result"`
} }
type ordersHistoryResponse struct {
Success bool `json:"success"`
Result []order `json:"result"`
HasMoreData bool `json:"hasMoreData"`
}
type ordersResponse struct { type ordersResponse struct {
Success bool `json:"success"` Success bool `json:"success"`