kucoin: implement QueryTrades

This commit is contained in:
c9s 2021-12-26 01:44:05 +08:00
parent 8c03147ff4
commit e3181202db
2 changed files with 39 additions and 4 deletions

View File

@ -213,3 +213,23 @@ func toGlobalOrder(o kucoinapi.Order) types.Order {
}
return order
}
func toGlobalTrade(fill kucoinapi.Fill) types.Trade {
var trade = types.Trade{
ID: hashStringID(fill.TradeId),
OrderID: hashStringID(fill.OrderId),
Exchange: types.ExchangeKucoin,
Price: fill.Price.Float64(),
Quantity: fill.Size.Float64(),
QuoteQuantity: fill.Funds.Float64(),
Symbol: toGlobalSymbol(fill.Symbol),
Side: toGlobalSide(string(fill.Side)),
IsBuyer: fill.Side == kucoinapi.SideTypeBuy,
IsMaker: fill.Liquidity == kucoinapi.LiquidityTypeMaker,
Time: types.Time{},
Fee: fill.Fee.Float64(),
FeeCurrency: toGlobalSymbol(fill.FeeCurrency),
}
return trade
}

View File

@ -27,7 +27,6 @@ type Exchange struct {
client *kucoinapi.RestClient
}
func New(key, secret, passphrase string) *Exchange {
client := kucoinapi.NewClient()
@ -247,10 +246,26 @@ func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since,
return orders, err
}
func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *types.TradeQueryOptions) ([]types.Trade, error) {
panic("implement me")
}
func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *types.TradeQueryOptions) (trades []types.Trade, err error) {
req := e.client.TradeService.NewGetFillsRequest()
req.Symbol(toLocalSymbol(symbol))
if options.StartTime != nil {
req.StartAt(*options.StartTime)
} else if options.EndTime != nil {
req.EndAt(*options.EndTime)
}
response, err := req.Do(ctx)
if err != nil {
return trades, err
}
for _, fill := range response.Items {
trade := toGlobalTrade(fill)
trades = append(trades, trade)
}
return trades, nil
}
func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (errs error) {
for _, o := range orders {