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

@@ -493,7 +493,7 @@ func TestFullCycle(t *testing.T) {
bt.DataHolder = data.NewHandlerHolder()
k := &kline.DataFromKline{
Item: gctkline.Item{
Item: &gctkline.Item{
Exchange: ex,
Pair: cp,
Asset: a,
@@ -633,7 +633,7 @@ func TestFullCycleMulti(t *testing.T) {
bt.DataHolder = data.NewHandlerHolder()
k := &kline.DataFromKline{
Item: gctkline.Item{
Item: &gctkline.Item{
Exchange: ex,
Pair: cp,
Asset: a,
@@ -756,7 +756,7 @@ func TestTriggerLiquidationsForExchange(t *testing.T) {
t.Errorf("received: %v, expected: %v", err, nil)
}
da := &kline.DataFromKline{
Item: gctkline.Item{
Item: &gctkline.Item{
Exchange: testExchange,
Asset: a,
Pair: cp,
@@ -1008,7 +1008,7 @@ func TestProcessOrderEvent(t *testing.T) {
tt := time.Now()
bt.DataHolder = data.NewHandlerHolder()
k := &kline.DataFromKline{
Item: gctkline.Item{
Item: &gctkline.Item{
Exchange: testExchange,
Pair: cp,
Asset: a,
@@ -1121,7 +1121,7 @@ func TestProcessFillEvent(t *testing.T) {
}
bt.DataHolder = data.NewHandlerHolder()
k := &kline.DataFromKline{
Item: gctkline.Item{
Item: &gctkline.Item{
Exchange: testExchange,
Pair: cp,
Asset: a,
@@ -1230,7 +1230,7 @@ func TestProcessFuturesFillEvent(t *testing.T) {
tt := time.Now()
bt.DataHolder = data.NewHandlerHolder()
k := &kline.DataFromKline{
Item: gctkline.Item{
Item: &gctkline.Item{
Exchange: testExchange,
Pair: cp,
Asset: a,
@@ -1342,7 +1342,7 @@ func TestCloseAllPositions(t *testing.T) {
dataRequestRetryTolerance: 1,
pairCandles: &kline.DataFromKline{
Base: &data.Base{},
Item: gctkline.Item{
Item: &gctkline.Item{
Exchange: testExchange,
Pair: cp,
UnderlyingPair: cp,
@@ -1850,7 +1850,7 @@ func TestExecuteStrategy(t *testing.T) {
bt.m.Unlock()
err = bt.ExecuteStrategy(false)
if !errors.Is(err, nil) {
t.Errorf("received '%v' expected '%v'", err, nil)
t.Fatalf("received '%v' expected '%v'", err, nil)
}
bt.m.Lock()
@@ -1965,7 +1965,7 @@ func TestProcessSingleDataEvent(t *testing.T) {
tt := time.Now()
bt.DataHolder = data.NewHandlerHolder()
k := &kline.DataFromKline{
Item: gctkline.Item{
Item: &gctkline.Item{
Exchange: testExchange,
Pair: cp,
Asset: a,

View File

@@ -170,7 +170,7 @@ func (f fakeDataHolder) GetAllData() ([]data.Handler, error) {
cp := currency.NewPair(currency.BTC, currency.USD)
return []data.Handler{&kline.DataFromKline{
Base: &data.Base{},
Item: gctkline.Item{
Item: &gctkline.Item{
Exchange: testExchange,
Pair: cp,
UnderlyingPair: cp,

View File

@@ -304,7 +304,7 @@ func (d *dataChecker) AppendDataSource(dataSource *liveDataSourceSetup) error {
}
}
k := kline.NewDataFromKline()
k.Item = gctkline.Item{
k.Item = &gctkline.Item{
Exchange: exchName,
Pair: dataSource.pair,
UnderlyingPair: dataSource.underlyingPair,
@@ -386,7 +386,7 @@ func (d *dataChecker) FetchLatestData() (bool, error) {
if err != nil {
return false, err
}
err = d.report.SetKlineData(&d.sourcesToCheck[i].pairCandles.Item)
err = d.report.SetKlineData(d.sourcesToCheck[i].pairCandles.Item)
if err != nil {
return false, err
}
@@ -440,12 +440,12 @@ func (d *dataChecker) SetDataForClosingAllPositions(s ...signal.Event) error {
Close: s[x].GetClosePrice().InexactFloat64(),
Volume: s[x].GetVolume().InexactFloat64(),
})
err = d.sourcesToCheck[y].pairCandles.AppendResults(&d.sourcesToCheck[y].pairCandles.Item)
err = d.sourcesToCheck[y].pairCandles.AppendResults(d.sourcesToCheck[y].pairCandles.Item)
if err != nil {
log.Errorf(common.LiveStrategy, "%v %v %v issue appending kline data: %v", d.sourcesToCheck[y].exchangeName, d.sourcesToCheck[y].asset, d.sourcesToCheck[y].pair, err)
continue
}
err = d.report.SetKlineData(&d.sourcesToCheck[y].pairCandles.Item)
err = d.report.SetKlineData(d.sourcesToCheck[y].pairCandles.Item)
if err != nil {
log.Errorf(common.LiveStrategy, "%v %v %v issue processing kline data: %v", d.sourcesToCheck[y].exchangeName, d.sourcesToCheck[y].asset, d.sourcesToCheck[y].pair, err)
continue

View File

@@ -345,7 +345,7 @@ func TestFetchLatestData(t *testing.T) {
underlyingPair: cp,
pairCandles: &datakline.DataFromKline{
Base: &data.Base{},
Item: kline.Item{
Item: &kline.Item{
Exchange: testExchange,
Pair: cp,
UnderlyingPair: cp,
@@ -408,7 +408,7 @@ func TestLoadCandleData(t *testing.T) {
l.pair = cp
l.pairCandles = &datakline.DataFromKline{
Base: &data.Base{},
Item: kline.Item{
Item: &kline.Item{
Exchange: testExchange,
Asset: asset.Spot,
Pair: cp,
@@ -460,7 +460,7 @@ func TestSetDataForClosingAllPositions(t *testing.T) {
underlyingPair: cp,
pairCandles: &datakline.DataFromKline{
Base: &data.Base{},
Item: kline.Item{
Item: &kline.Item{
Exchange: testExchange,
Pair: cp,
UnderlyingPair: cp,

View File

@@ -740,7 +740,7 @@ func (bt *BackTest) loadData(cfg *config.Config, exch gctexchange.IBotExchange,
if err != nil {
return nil, fmt.Errorf("%v. Please check your GoCryptoTrader configuration", err)
}
resp.Item.RemoveDuplicateCandlesByTime()
resp.Item.RemoveDuplicates()
resp.Item.SortCandlesByTimestamp(false)
resp.RangeHolder, err = gctkline.CalculateCandleDateRanges(
resp.Item.Candles[0].Time,
@@ -783,7 +783,7 @@ func (bt *BackTest) loadData(cfg *config.Config, exch gctexchange.IBotExchange,
return nil, fmt.Errorf("unable to retrieve data from GoCryptoTrader database. Error: %v. Please ensure the database is setup correctly and has data before use", err)
}
resp.Item.RemoveDuplicateCandlesByTime()
resp.Item.RemoveDuplicates()
resp.Item.SortCandlesByTimestamp(false)
resp.RangeHolder, err = gctkline.CalculateCandleDateRanges(
cfg.DataSettings.DatabaseData.StartDate,
@@ -835,6 +835,7 @@ func (bt *BackTest) loadData(cfg *config.Config, exch gctexchange.IBotExchange,
resp.Item.UnderlyingPair = underlyingPair
err = b.ValidateKline(fPair, a, resp.Item.Interval)
if err != nil {
// TODO: In future allow custom candles.
if dataType != common.DataTrade || !strings.EqualFold(err.Error(), "interval not supported") {
return nil, err
}
@@ -844,7 +845,7 @@ func (bt *BackTest) loadData(cfg *config.Config, exch gctexchange.IBotExchange,
if err != nil {
return nil, err
}
err = bt.Reports.SetKlineData(&resp.Item)
err = bt.Reports.SetKlineData(resp.Item)
if err != nil {
return nil, err
}
@@ -902,7 +903,7 @@ func loadAPIData(cfg *config.Config, exch gctexchange.IBotExchange, fPair curren
candles.RemoveOutsideRange(cfg.DataSettings.APIData.StartDate, cfg.DataSettings.APIData.EndDate)
return &kline.DataFromKline{
Base: &data.Base{},
Item: *candles,
Item: candles,
RangeHolder: dates,
}, nil
}