mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
okex: fix kline query
This commit is contained in:
parent
f22327eb75
commit
d742aea633
|
@ -2,6 +2,7 @@ package okex
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -268,3 +269,10 @@ func toGlobalOrderType(orderType okexapi.OrderType) (types.OrderType, error) {
|
|||
}
|
||||
return "", fmt.Errorf("unknown or unsupported okex order type: %s", orderType)
|
||||
}
|
||||
|
||||
func toLocalInterval(src string, ) string {
|
||||
var re = regexp.MustCompile("\\d+[hdw]")
|
||||
return re.ReplaceAllStringFunc(src, func(w string) string {
|
||||
return strings.ToUpper(w)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -8,12 +8,15 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/exchange/okex/okexapi"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
var marketDataLimiter = rate.NewLimiter(rate.Every(time.Second/20), 1)
|
||||
|
||||
// OKB is the platform currency of OKEx, pre-allocate static string here
|
||||
const OKB = "OKB"
|
||||
|
||||
|
@ -272,15 +275,21 @@ func (e *Exchange) NewStream() types.Stream {
|
|||
}
|
||||
|
||||
func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error) {
|
||||
if err := marketDataLimiter.Wait(ctx) ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
intervalParam := toLocalInterval(interval.String())
|
||||
|
||||
req := e.client.MarketDataService.NewCandlesticksRequest(toLocalSymbol(symbol))
|
||||
req.Bar(interval.String())
|
||||
req.Bar(intervalParam)
|
||||
|
||||
if options.StartTime != nil {
|
||||
req.After(options.StartTime.UnixNano() / int64(time.Millisecond))
|
||||
req.After(options.StartTime.Unix())
|
||||
}
|
||||
|
||||
if options.EndTime != nil {
|
||||
req.Before(options.EndTime.UnixNano() / int64(time.Millisecond))
|
||||
req.Before(options.EndTime.Unix())
|
||||
}
|
||||
|
||||
candles, err := req.Do(ctx)
|
||||
|
|
|
@ -25,15 +25,15 @@ type Candle struct {
|
|||
type CandlesticksRequest struct {
|
||||
client *RestClient
|
||||
|
||||
instId string
|
||||
instId string `param:"instId"`
|
||||
|
||||
limit *int
|
||||
limit *int `param:"limit"`
|
||||
|
||||
bar *string
|
||||
bar *string `param:"bar"`
|
||||
|
||||
after *int64
|
||||
after *int64 `param:"after,seconds"`
|
||||
|
||||
before *int64
|
||||
before *int64 `param:"before,seconds"`
|
||||
}
|
||||
|
||||
func (r *CandlesticksRequest) After(after int64) *CandlesticksRequest {
|
||||
|
|
Loading…
Reference in New Issue
Block a user