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

@@ -1772,10 +1772,6 @@ func (f *FTX) LoadCollateralWeightings(ctx context.Context) error {
return nil
}
func (c CollateralWeightHolder) hasData() bool {
return len(c) > 0
}
func (c CollateralWeightHolder) loadTotal(code string, weighting float64) {
cc := currency.NewCode(code)
currencyCollateral := c[cc.Item]

View File

@@ -1309,14 +1309,13 @@ func TestGetFundingHistory(t *testing.T) {
func TestGetHistoricCandles(t *testing.T) {
t.Parallel()
currencyPair, err := currency.NewPairFromString("BTC/USD")
pair, err := currency.NewPairFromString("BTC/USD")
if err != nil {
t.Fatal(err)
}
start := time.Date(2019, 11, 12, 0, 0, 0, 0, time.UTC)
end := start.AddDate(0, 0, 2)
_, err = f.GetHistoricCandles(context.Background(),
currencyPair, asset.Spot, start, end, kline.OneDay)
_, err = f.GetHistoricCandles(context.Background(), pair, asset.Spot, kline.OneDay, start, end)
if err != nil {
t.Fatal(err)
}
@@ -1324,14 +1323,13 @@ func TestGetHistoricCandles(t *testing.T) {
func TestGetHistoricCandlesExtended(t *testing.T) {
t.Parallel()
currencyPair, err := currency.NewPairFromString("BTC/USD")
pair, err := currency.NewPairFromString("BTC/USD")
if err != nil {
t.Fatal(err)
}
start := time.Date(2019, 11, 12, 0, 0, 0, 0, time.UTC)
end := start.AddDate(0, 0, 2)
_, err = f.GetHistoricCandlesExtended(context.Background(),
currencyPair, asset.Spot, start, end, kline.OneDay)
_, err = f.GetHistoricCandlesExtended(context.Background(), pair, asset.Spot, kline.OneDay, start, end)
if err != nil {
t.Fatal(err)
}
@@ -2193,6 +2191,10 @@ func TestLoadCollateralWeightings(t *testing.T) {
}
}
func (c CollateralWeightHolder) hasData() bool {
return len(c) > 0
}
func TestLoadTotalIMF(t *testing.T) {
t.Parallel()
c := CollateralWeightHolder{}
@@ -2232,18 +2234,6 @@ func TestLoadCollateralWeight(t *testing.T) {
}
}
func TestCollateralWeightHasData(t *testing.T) {
t.Parallel()
c := CollateralWeightHolder{}
if c.hasData() {
t.Error("expected false")
}
c.load("test", 1, 2, 3)
if !c.hasData() {
t.Error("expected true")
}
}
func TestGetExpiredFutures(t *testing.T) {
t.Parallel()
_, err := f.GetExpiredFutures(context.Background())

View File

@@ -136,15 +136,15 @@ func (f *FTX) SetDefaults() {
Enabled: exchange.FeaturesEnabled{
AutoPairUpdates: true,
Kline: kline.ExchangeCapabilitiesEnabled{
Intervals: map[string]bool{
kline.FifteenSecond.Word(): true,
kline.OneMin.Word(): true,
kline.FiveMin.Word(): true,
kline.FifteenMin.Word(): true,
kline.OneHour.Word(): true,
kline.FourHour.Word(): true,
kline.OneDay.Word(): true,
},
Intervals: kline.DeployExchangeIntervals(
kline.FifteenSecond,
kline.OneMin,
kline.FiveMin,
kline.FifteenMin,
kline.OneHour,
kline.FourHour,
kline.OneDay,
),
ResultLimit: 5000,
},
},
@@ -1214,83 +1214,58 @@ func (f *FTX) ValidateCredentials(ctx context.Context, assetType asset.Item) err
}
// GetHistoricCandles returns candles between a time period for a set time interval
func (f *FTX) GetHistoricCandles(ctx context.Context, p currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
if err := f.ValidateKline(p, a, interval); err != nil {
return kline.Item{}, err
}
formattedPair, err := f.FormatExchangeCurrency(p, a)
func (f *FTX) GetHistoricCandles(ctx context.Context, pair currency.Pair, a asset.Item, interval kline.Interval, start, end time.Time) (*kline.Item, error) {
req, err := f.GetKlineRequest(pair, a, interval, start, end)
if err != nil {
return kline.Item{}, err
return nil, err
}
ohlcData, err := f.GetHistoricalData(ctx,
formattedPair.String(),
int64(interval.Duration().Seconds()),
req.RequestFormatted.String(),
int64(req.ExchangeInterval.Duration().Seconds()),
int64(f.Features.Enabled.Kline.ResultLimit),
start,
end)
req.Start,
req.End)
if err != nil {
return kline.Item{}, err
}
ret := kline.Item{
Exchange: f.Name,
Pair: p,
Asset: a,
Interval: interval,
return nil, err
}
timeSeries := make([]kline.Candle, len(ohlcData))
for x := range ohlcData {
ret.Candles = append(ret.Candles, kline.Candle{
timeSeries[x] = kline.Candle{
Time: ohlcData[x].StartTime,
Open: ohlcData[x].Open,
High: ohlcData[x].High,
Low: ohlcData[x].Low,
Close: ohlcData[x].Close,
Volume: ohlcData[x].Volume,
})
}
}
return ret, nil
return req.ProcessResponse(timeSeries)
}
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
func (f *FTX) GetHistoricCandlesExtended(ctx context.Context, p currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
if err := f.ValidateKline(p, a, interval); err != nil {
return kline.Item{}, err
}
ret := kline.Item{
Exchange: f.Name,
Pair: p,
Asset: a,
Interval: interval,
}
dates, err := kline.CalculateCandleDateRanges(start, end, interval, f.Features.Enabled.Kline.ResultLimit)
func (f *FTX) GetHistoricCandlesExtended(ctx context.Context, pair currency.Pair, a asset.Item, interval kline.Interval, start, end time.Time) (*kline.Item, error) {
req, err := f.GetKlineExtendedRequest(pair, a, interval, start, end)
if err != nil {
return kline.Item{}, err
return nil, err
}
formattedPair, err := f.FormatExchangeCurrency(p, a)
if err != nil {
return kline.Item{}, err
}
for x := range dates.Ranges {
timeSeries := make([]kline.Candle, 0, req.Size())
for x := range req.Ranges {
var ohlcData []OHLCVData
ohlcData, err = f.GetHistoricalData(ctx,
formattedPair.String(),
int64(interval.Duration().Seconds()),
req.RequestFormatted.String(),
int64(req.ExchangeInterval.Duration().Seconds()),
int64(f.Features.Enabled.Kline.ResultLimit),
dates.Ranges[x].Start.Time,
dates.Ranges[x].End.Time)
req.Ranges[x].Start.Time,
req.Ranges[x].End.Time)
if err != nil {
return kline.Item{}, err
return nil, err
}
for i := range ohlcData {
ret.Candles = append(ret.Candles, kline.Candle{
timeSeries = append(timeSeries, kline.Candle{
Time: ohlcData[i].StartTime,
Open: ohlcData[i].Open,
High: ohlcData[i].High,
@@ -1300,15 +1275,7 @@ func (f *FTX) GetHistoricCandlesExtended(ctx context.Context, p currency.Pair, a
})
}
}
dates.SetHasDataFromCandles(ret.Candles)
summary := dates.DataSummary(false)
if len(summary) > 0 {
log.Warnf(log.ExchangeSys, "%v - %v", f.Name, summary)
}
ret.RemoveDuplicateCandlesByTime()
ret.RemoveOutsideRange(start, end)
ret.SortCandlesByTimestamp(false)
return ret, nil
return req.ProcessResponse(timeSeries)
}
// UpdateOrderExecutionLimits sets exchange executions for a required asset type