MCPcopy
hub / github.com/thrasher-corp/gocryptotrader / TestGetKlineExtendedRequest

Function TestGetKlineExtendedRequest

exchanges/exchange_test.go:2165–2221  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2163}
2164
2165func TestGetKlineExtendedRequest(t *testing.T) {
2166 t.Parallel()
2167 b := Base{Name: "klineTest"}
2168 _, err := b.GetKlineExtendedRequest(currency.EMPTYPAIR, asset.Empty, 0, time.Time{}, time.Time{})
2169 assert.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
2170
2171 p := currency.NewBTCUSDT()
2172 _, err = b.GetKlineExtendedRequest(p, asset.Empty, 0, time.Time{}, time.Time{})
2173 assert.ErrorIs(t, err, asset.ErrNotSupported)
2174
2175 _, err = b.GetKlineExtendedRequest(p, asset.Spot, 0, time.Time{}, time.Time{})
2176 assert.ErrorIs(t, err, kline.ErrInvalidInterval)
2177
2178 _, err = b.GetKlineExtendedRequest(p, asset.Spot, kline.OneHour, time.Time{}, time.Time{})
2179 assert.ErrorIs(t, err, kline.ErrCannotConstructInterval)
2180
2181 b.Features.Enabled.Kline.Intervals = kline.DeployExchangeIntervals(kline.IntervalCapacity{Interval: kline.OneMin})
2182 b.Features.Enabled.Kline.GlobalResultLimit = 100
2183 start := time.Date(2020, 12, 1, 0, 0, 0, 0, time.UTC)
2184 end := start.AddDate(0, 0, 1)
2185 _, err = b.GetKlineExtendedRequest(p, asset.Spot, kline.OneHour, start, end)
2186 assert.ErrorIs(t, err, currency.ErrPairManagerNotInitialised)
2187
2188 err = b.CurrencyPairs.Store(asset.Spot, &currency.PairStore{
2189 AssetEnabled: true,
2190 Enabled: []currency.Pair{p},
2191 Available: []currency.Pair{p},
2192 })
2193 require.NoError(t, err, "CurrencyPairs.Store must not error")
2194
2195 _, err = b.GetKlineExtendedRequest(p, asset.Spot, kline.OneHour, start, end)
2196 assert.ErrorIs(t, err, currency.ErrPairFormatIsNil, "GetKlineExtendedRequest should error correctly")
2197
2198 err = b.CurrencyPairs.Store(asset.Spot, &currency.PairStore{
2199 AssetEnabled: true,
2200 Enabled: []currency.Pair{p},
2201 Available: []currency.Pair{p},
2202 RequestFormat: &currency.PairFormat{Uppercase: true},
2203 })
2204 require.NoError(t, err, "CurrencyPairs.Store must not error")
2205
2206 // The one hour interval is not supported by the exchange. This scenario
2207 // demonstrates the conversion from the supported 1 minute candles into
2208 // one hour candles
2209 r, err := b.GetKlineExtendedRequest(p, asset.Spot, kline.OneHour, start, end)
2210 require.NoError(t, err, "GetKlineExtendedRequest must not error")
2211
2212 assert.Equal(t, "klineTest", r.Exchange, "Exchange name should match")
2213 assert.Equal(t, p, r.Pair, "Pair should match")
2214 assert.Equal(t, asset.Spot, r.Asset, "Asset should match")
2215 assert.Equal(t, kline.OneMin, r.ExchangeInterval, "ExchangeInterval should match")
2216 assert.Equal(t, kline.OneHour, r.ClientRequired, "ClientRequired should match")
2217 assert.Equal(t, start, r.Request.Start, "Request.Start should match")
2218 assert.Equal(t, end, r.Request.End, "Request.End should match")
2219 assert.Equal(t, "BTCUSDT", r.RequestFormatted.String(), "RequestFormatted should match")
2220 assert.Equal(t, 15, len(r.RangeHolder.Ranges), "RangeHolder.Ranges length should match")
2221}
2222

Callers

nothing calls this directly

Calls 6

NewBTCUSDTFunction · 0.92
DeployExchangeIntervalsFunction · 0.92
StoreMethod · 0.80
StringMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected