kline/exchanges: automatic creation of unsupported candle intervals (#1091)

* kline: Add builder and testing

* Ideas

* kline: deploy builder functionality across GCT

* exchanges: implement across gct

* exchanges: Add tests and fix implementations before kline package testing and veri.

* kline: Add tests and start to fix ConvertToNewInterval

* kline: fix ConvertToNewInterval add tests

* kline: complete overarching tests now on to exchanges

* kline: finish exchange tests and implement limits

* exchanges: more fixes

* linter: fix

* engine: fix tests

* kraken: fix recent trades and other fixes

* zb: fix tests

* bithumb: fix empty insertion

* kline: refactor/optimize CreateKline function

* kline: remove the mooos!

* kline: prealloc CalculateCandleDateRanges

* linter: fix

* exchanges: prealloc extended

* fix whoopsie

* reverse fix because this is a whoopsie

* okx: fix risidual issues

* linter: fix

* kline: initial nits from @gloriouscode

* kline: rename builder -> request and cascade change

* linter: fix + test

* kline: update forced alignment on start and end times when CreateKlineRequest is called.

* nits: more more more

* NITS: Addressed

* tests: fix race issue

* Update exchanges/kline/request.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* kline: add method AddPadding() to automatically fill in holes in kline.Request functionality and reject if missing data when converting

* kline: Add params start and end to addPadding() to insert blanks in between block

* kline: remove test comment code as it's not needed anymore

* kline: fix lint and test

* kline: sort slice without extra bool check every iteration

* okx: fix issues with timeing and candles and such from niterinos & address typo

* Update exchanges/kline/kline.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: niterinos

* Update exchanges/poloniex/poloniex_wrapper.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: nits now onto conflicts YAYA!!!

* Update exchanges/exchange_test.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: nits again

* thrasher: nitters

* thrasher: niterinos - adds partial flag for incomplete recent candles and fetching.

* kline: rm fmtizzle packageizzle

* glorious: nitters

* glorious: more niterinos

* fix last niterinos

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
Ryan O'Hara-Reid
2023-01-17 16:22:33 +11:00
committed by GitHub
parent 72f36d70d1
commit 83cfefa45c
110 changed files with 11312 additions and 5768 deletions

View File

@@ -613,13 +613,12 @@ func TestGetCandleStick(t *testing.T) {
func TestGetHistoricCandles(t *testing.T) {
t.Parallel()
currencyPair, err := currency.NewPairFromString("BTCKRW")
pair, err := currency.NewPairFromString("BTCKRW")
if err != nil {
t.Fatal(err)
}
startTime := time.Now().Add(-time.Hour * 24)
_, err = b.GetHistoricCandles(context.Background(),
currencyPair, asset.Spot, startTime, time.Now(), kline.OneDay)
startTime := time.Now().AddDate(0, 0, -1)
_, err = b.GetHistoricCandles(context.Background(), pair, asset.Spot, kline.OneMin, startTime, time.Now())
if err != nil {
t.Fatal(err)
}
@@ -627,14 +626,13 @@ func TestGetHistoricCandles(t *testing.T) {
func TestGetHistoricCandlesExtended(t *testing.T) {
t.Parallel()
currencyPair, err := currency.NewPairFromString("BTCKRW")
pair, err := currency.NewPairFromString("BTCKRW")
if err != nil {
t.Fatal(err)
}
startTime := time.Now().Add(-time.Hour * 24)
_, err = b.GetHistoricCandlesExtended(context.Background(),
currencyPair, asset.Spot, startTime, time.Now(), kline.OneDay)
if err != nil {
_, err = b.GetHistoricCandlesExtended(context.Background(), pair, asset.Spot, kline.OneDay, startTime, time.Now())
if !errors.Is(err, common.ErrNotYetImplemented) {
t.Fatal(err)
}
}

View File

@@ -114,17 +114,18 @@ func (b *Bithumb) SetDefaults() {
Enabled: exchange.FeaturesEnabled{
AutoPairUpdates: true,
Kline: kline.ExchangeCapabilitiesEnabled{
Intervals: map[string]bool{
kline.OneMin.Word(): true,
kline.ThreeMin.Word(): true,
kline.FiveMin.Word(): true,
kline.TenMin.Word(): true,
kline.ThirtyMin.Word(): true,
kline.OneHour.Word(): true,
kline.SixHour.Word(): true,
kline.TwelveHour.Word(): true,
kline.OneDay.Word(): true,
},
Intervals: kline.DeployExchangeIntervals(
kline.OneMin,
kline.ThreeMin,
kline.FiveMin,
kline.TenMin,
kline.ThirtyMin,
kline.OneHour,
kline.SixHour,
kline.TwelveHour,
kline.OneDay,
),
ResultLimit: 1500,
},
},
}
@@ -781,67 +782,57 @@ func (b *Bithumb) FormatExchangeKlineInterval(in kline.Interval) string {
}
// GetHistoricCandles returns candles between a time period for a set time interval
func (b *Bithumb) GetHistoricCandles(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
if err := b.ValidateKline(pair, a, interval); err != nil {
return kline.Item{}, err
}
formattedPair, err := b.FormatExchangeCurrency(pair, a)
func (b *Bithumb) GetHistoricCandles(ctx context.Context, pair currency.Pair, a asset.Item, interval kline.Interval, start, end time.Time) (*kline.Item, error) {
req, err := b.GetKlineRequest(pair, a, interval, start, end)
if err != nil {
return kline.Item{}, err
return nil, err
}
candle, err := b.GetCandleStick(ctx, formattedPair.String(),
b.FormatExchangeKlineInterval(interval))
candle, err := b.GetCandleStick(ctx,
req.RequestFormatted.String(),
b.FormatExchangeKlineInterval(req.ExchangeInterval))
if err != nil {
return kline.Item{}, err
}
ret := kline.Item{
Exchange: b.Name,
Pair: pair,
Interval: interval,
return nil, err
}
timeSeries := make([]kline.Candle, 0, len(candle.Data))
for x := range candle.Data {
if len(candle.Data[x]) < 6 {
return kline.Item{}, errors.New("invalid candle length")
return nil, errors.New("invalid candle length")
}
var tempCandle kline.Candle
if tempCandle.Time, err = convert.TimeFromUnixTimestampFloat(candle.Data[x][0]); err != nil {
return kline.Item{}, fmt.Errorf("unable to convert timestamp: %w", err)
return nil, fmt.Errorf("unable to convert timestamp: %w", err)
}
if tempCandle.Time.Before(start) {
if tempCandle.Time.Before(req.Start) {
continue
}
if tempCandle.Time.After(end) {
if tempCandle.Time.After(req.End) {
break
}
if tempCandle.Open, err = convert.FloatFromString(candle.Data[x][1]); err != nil {
return kline.Item{}, fmt.Errorf("kline open conversion failed: %w", err)
return nil, fmt.Errorf("kline open conversion failed: %w", err)
}
if tempCandle.High, err = convert.FloatFromString(candle.Data[x][2]); err != nil {
return kline.Item{}, fmt.Errorf("kline high conversion failed: %w", err)
return nil, fmt.Errorf("kline high conversion failed: %w", err)
}
if tempCandle.Low, err = convert.FloatFromString(candle.Data[x][3]); err != nil {
return kline.Item{}, fmt.Errorf("kline low conversion failed: %w", err)
return nil, fmt.Errorf("kline low conversion failed: %w", err)
}
if tempCandle.Close, err = convert.FloatFromString(candle.Data[x][4]); err != nil {
return kline.Item{}, fmt.Errorf("kline close conversion failed: %w", err)
return nil, fmt.Errorf("kline close conversion failed: %w", err)
}
if tempCandle.Volume, err = convert.FloatFromString(candle.Data[x][5]); err != nil {
return kline.Item{}, fmt.Errorf("kline volume conversion failed: %w", err)
return nil, fmt.Errorf("kline volume conversion failed: %w", err)
}
ret.Candles = append(ret.Candles, tempCandle)
timeSeries = append(timeSeries, tempCandle)
}
ret.SortCandlesByTimestamp(false)
return ret, nil
return req.ProcessResponse(timeSeries)
}
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
func (b *Bithumb) GetHistoricCandlesExtended(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
return b.GetHistoricCandles(ctx, pair, a, start, end, interval)
func (b *Bithumb) GetHistoricCandlesExtended(_ context.Context, _ currency.Pair, _ asset.Item, _ kline.Interval, _, _ time.Time) (*kline.Item, error) {
return nil, common.ErrNotYetImplemented
}
// UpdateOrderExecutionLimits sets exchange executions for a required asset type