Created
February 27, 2024 01:54
-
-
Save gloriousCode/4e67992ccf53e7bf79c186bb55deafc0 to your computer and use it in GitHub Desktop.
candle burnout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/exchanges/deribit/deribit_test.go b/exchanges/deribit/deribit_test.go | |
index 09c468c45..4761f54a1 100644 | |
--- a/exchanges/deribit/deribit_test.go | |
+++ b/exchanges/deribit/deribit_test.go | |
@@ -133,31 +133,43 @@ func TestFetchRecentTrades(t *testing.T) { | |
func TestGetHistoricCandles(t *testing.T) { | |
t.Parallel() | |
- _, err := d.GetHistoricCandles(context.Background(), futuresTradablePair, asset.Futures, kline.FifteenMin, time.Now().Add(-time.Minute*5), time.Now()) | |
+ start := time.Now().Add(-time.Hour) | |
+ end := time.Now() | |
+ resp, err := d.GetHistoricCandles(context.Background(), futuresTradablePair, asset.Futures, kline.FifteenMin, start, end) | |
require.NoError(t, err) | |
- _, err = d.GetHistoricCandles(context.Background(), spotTradablePair, asset.Spot, kline.FifteenMin, time.Now().Add(-time.Minute*5), time.Now()) | |
+ assert.NotEmpty(t, resp) | |
+ | |
+ resp, err = d.GetHistoricCandles(context.Background(), spotTradablePair, asset.Spot, kline.FifteenMin, start, end) | |
require.NoError(t, err) | |
+ assert.NotEmpty(t, resp) | |
+ | |
sleepUntilTradablePairsUpdated() | |
- _, err = d.GetHistoricCandles(context.Background(), optionsTradablePair, asset.Options, kline.FifteenMin, time.Now().Add(-time.Minute*5), time.Now()) | |
+ _, err = d.GetHistoricCandles(context.Background(), optionsTradablePair, asset.Options, kline.FifteenMin, start, end) | |
require.ErrorIs(t, err, asset.ErrNotSupported) | |
- _, err = d.GetHistoricCandles(context.Background(), futureComboTradablePair, asset.FutureCombo, kline.FifteenMin, time.Now().Add(-time.Hour), time.Now()) | |
+ _, err = d.GetHistoricCandles(context.Background(), futureComboTradablePair, asset.FutureCombo, kline.FifteenMin, start, end) | |
require.ErrorIs(t, err, asset.ErrNotSupported) | |
- _, err = d.GetHistoricCandles(context.Background(), optionComboTradablePair, asset.OptionCombo, kline.FifteenMin, time.Now().Add(-time.Hour), time.Now()) | |
+ _, err = d.GetHistoricCandles(context.Background(), optionComboTradablePair, asset.OptionCombo, kline.FifteenMin, start, end) | |
assert.ErrorIs(t, err, asset.ErrNotSupported) | |
} | |
func TestGetHistoricCandlesExtended(t *testing.T) { | |
t.Parallel() | |
- _, err := d.GetHistoricCandlesExtended(context.Background(), futuresTradablePair, asset.Futures, kline.FifteenMin, time.Now().Add(-time.Hour*550), time.Now().Add(-time.Hour*150)) | |
+ start := time.Now().Add(-time.Hour * 24 * 90).Truncate(kline.OneDay.Duration()).UTC() | |
+ end := time.Now().UTC() | |
+ resp, err := d.GetHistoricCandlesExtended(context.Background(), futuresTradablePair, asset.Futures, kline.OneDay, start, end) | |
assert.NoError(t, err) | |
- _, err = d.GetHistoricCandlesExtended(context.Background(), spotTradablePair, asset.Spot, kline.FifteenMin, time.Now().Add(-time.Hour*550), time.Now().Add(-time.Hour*150)) | |
+ assert.NotEmpty(t, resp) | |
+ | |
+ resp, err = d.GetHistoricCandlesExtended(context.Background(), spotTradablePair, asset.Spot, kline.OneDay, start, end) | |
assert.NoError(t, err) | |
+ assert.NotEmpty(t, resp) | |
+ | |
sleepUntilTradablePairsUpdated() | |
- _, err = d.GetHistoricCandlesExtended(context.Background(), optionsTradablePair, asset.Options, kline.FifteenMin, time.Now().Add(-time.Hour*550), time.Now().Add(-time.Hour*150)) | |
+ _, err = d.GetHistoricCandlesExtended(context.Background(), optionsTradablePair, asset.Options, kline.OneDay, start, end) | |
assert.ErrorIs(t, err, asset.ErrNotSupported) | |
- _, err = d.GetHistoricCandlesExtended(context.Background(), futureComboTradablePair, asset.FutureCombo, kline.FifteenMin, time.Now().Add(-time.Hour*550), time.Now().Add(-time.Hour*150)) | |
+ _, err = d.GetHistoricCandlesExtended(context.Background(), futureComboTradablePair, asset.FutureCombo, kline.OneDay, start, end) | |
assert.ErrorIs(t, err, asset.ErrNotSupported) | |
- _, err = d.GetHistoricCandlesExtended(context.Background(), optionComboTradablePair, asset.OptionCombo, kline.FifteenMin, time.Now().Add(-time.Hour*550), time.Now().Add(-time.Hour*150)) | |
+ _, err = d.GetHistoricCandlesExtended(context.Background(), optionComboTradablePair, asset.OptionCombo, kline.OneDay, start, end) | |
assert.ErrorIs(t, err, asset.ErrNotSupported) | |
} | |
diff --git a/exchanges/deribit/deribit_wrapper.go b/exchanges/deribit/deribit_wrapper.go | |
index c1d52bc80..fbf1a9953 100644 | |
--- a/exchanges/deribit/deribit_wrapper.go | |
+++ b/exchanges/deribit/deribit_wrapper.go | |
@@ -128,10 +128,15 @@ func (d *Deribit) SetDefaults() { | |
kline.IntervalCapacity{Interval: kline.ThirtyMin}, | |
kline.IntervalCapacity{Interval: kline.OneHour}, | |
kline.IntervalCapacity{Interval: kline.TwoHour}, | |
- kline.IntervalCapacity{Interval: kline.ThreeHour}, | |
- kline.IntervalCapacity{Interval: kline.SixHour}, | |
- kline.IntervalCapacity{Interval: kline.TwelveHour}, | |
- kline.IntervalCapacity{Interval: kline.OneDay}, | |
+ // NOTE: The supported time intervals below are returned | |
+ // offset to +8 hours. This may lead to | |
+ // issues with candle quality and conversion as the | |
+ // intervals may be broken up. The below intervals | |
+ // are therefore constructed from the intervals above. | |
+ //kline.IntervalCapacity{Interval: kline.ThreeHour}, | |
+ //kline.IntervalCapacity{Interval: kline.SixHour}, | |
+ //kline.IntervalCapacity{Interval: kline.TwelveHour}, | |
+ //kline.IntervalCapacity{Interval: kline.OneDay}, | |
), | |
GlobalResultLimit: 500, | |
}, | |
@@ -1108,7 +1113,7 @@ func (d *Deribit) GetHistoricCandles(ctx context.Context, pair currency.Pair, a | |
} | |
listCandles := make([]kline.Candle, 0, len(tradingViewData.Ticks)) | |
for x := range tradingViewData.Ticks { | |
- timeInfo := time.UnixMilli(tradingViewData.Ticks[x]) | |
+ timeInfo := time.UnixMilli(tradingViewData.Ticks[x]).UTC() | |
if timeInfo.Before(start) { | |
continue | |
} | |
@@ -1159,17 +1164,17 @@ func (d *Deribit) GetHistoricCandlesExtended(ctx context.Context, pair currency. | |
len(tradingViewData.Volume) != checkLen { | |
return nil, fmt.Errorf("%s - %v: invalid trading view chart data received", a, d.formatFuturesTradablePair(req.RequestFormatted)) | |
} | |
- timeInfo := time.UnixMilli(tradingViewData.Ticks[x]).UTC() | |
- if timeInfo.Before(start) { | |
- continue | |
- } | |
- for x := range tradingViewData.Ticks { | |
+ for i := range tradingViewData.Ticks { | |
+ timeInfo := time.UnixMilli(tradingViewData.Ticks[i]).UTC() | |
+ if timeInfo.Before(start) { | |
+ continue | |
+ } | |
timeSeries = append(timeSeries, kline.Candle{ | |
- Open: tradingViewData.Open[x], | |
- High: tradingViewData.High[x], | |
- Low: tradingViewData.Low[x], | |
- Close: tradingViewData.Close[x], | |
- Volume: tradingViewData.Volume[x], | |
+ Open: tradingViewData.Open[i], | |
+ High: tradingViewData.High[i], | |
+ Low: tradingViewData.Low[i], | |
+ Close: tradingViewData.Close[i], | |
+ Volume: tradingViewData.Volume[i], | |
Time: timeInfo, | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment