From bac6a6f32799eed59130b53f9e9137fc09a95438 Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 19 Jun 2020 09:57:15 +0800 Subject: [PATCH] move kline query into the exchange interface --- bbgo/binance_exchange.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bbgo/binance_exchange.go b/bbgo/binance_exchange.go index 483a24b94..ad61ca382 100644 --- a/bbgo/binance_exchange.go +++ b/bbgo/binance_exchange.go @@ -44,6 +44,31 @@ func (e *BinanceExchange) SubmitOrder(ctx context.Context, order Order) error { return err } +func (e *BinanceExchange) QueryKLines(ctx context.Context, symbol, interval string, limit int) ([]KLine, error) { + resp, err := e.Client.NewKlinesService().Symbol(symbol).Interval(interval).Limit(limit).Do(ctx) + if err != nil { + return nil, err + } + + var klines []KLine + for _, kline := range resp { + klines = append(klines, KLine{ + Symbol: symbol, + Interval: interval, + StartTime: kline.OpenTime, + EndTime: kline.CloseTime, + Open: kline.Open, + Close: kline.Close, + High: kline.High, + Low: kline.Low, + Volume: kline.Volume, + QuoteVolume: kline.QuoteAssetVolume, + NumberOfTrades: kline.TradeNum, + }) + } + return klines, nil +} + func (e *BinanceExchange) QueryTrades(ctx context.Context, market string, startTime time.Time) (trades []Trade, err error) { var lastTradeID int64 = 0 for {