mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 23:16:53 +00:00
exchanges/futures: Implement open interest (#1417)
* adds open interest to exchanges * ADDS TESTING YEAH * New endpoints, BTSE, RPCS, cached * slight design change, begin gateio You will need to get cached for each exchange that supports it * gateio, huobi, rpc * fix up kraken, cache retrieval * okx, gateio * finalising all implementations and tests * definitely my final ever commit on this * Well, well, well * final v2 * quick fix of bug * test coverage, assert notempty, test helper Added a new testhelper for currency management because its very annoying in a parallel test setting which wastes so much space otherwise * minimises REST requests for Open Interest * types.Number merge misses * Minimises Kraken REST calls * len change, value -> pointer receiver * further fixup * fixes gateio, batch calculates open interest * single gateio, lint const fixes * rejig and more thorough oi for huobi * formatting expansion * minor fix for handling expiring contracts * rm unused Binance strings * add bybit support, fix bybit issues * oopsie doopsie, dont look at my whoopsie * Fix issue, remove feature * move an irrelevant function for the pr * mini bybit upgrades * fixes cli request bug
This commit is contained in:
@@ -10,7 +10,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/key"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/dispatch"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
@@ -448,3 +450,44 @@ func TestGetAssociation(t *testing.T) {
|
||||
|
||||
service.mux = cpyMux
|
||||
}
|
||||
|
||||
func TestGetExchangeTickersPublic(t *testing.T) {
|
||||
_, err := GetExchangeTickers("")
|
||||
assert.ErrorIs(t, err, errExchangeNameIsEmpty)
|
||||
}
|
||||
|
||||
func TestGetExchangeTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := Service{
|
||||
Tickers: make(map[key.ExchangePairAsset]*Ticker),
|
||||
Exchange: make(map[string]uuid.UUID),
|
||||
}
|
||||
|
||||
_, err := s.getExchangeTickers("")
|
||||
assert.ErrorIs(t, err, errExchangeNameIsEmpty)
|
||||
|
||||
_, err = s.getExchangeTickers("test")
|
||||
assert.ErrorIs(t, err, errExchangeNotFound)
|
||||
|
||||
s.Tickers[key.ExchangePairAsset{
|
||||
Exchange: "test",
|
||||
Base: currency.XBT.Item,
|
||||
Quote: currency.DOGE.Item,
|
||||
Asset: asset.Futures,
|
||||
}] = &Ticker{
|
||||
Price: Price{
|
||||
Pair: currency.NewPair(currency.XBT, currency.DOGE),
|
||||
ExchangeName: "test",
|
||||
AssetType: asset.Futures,
|
||||
OpenInterest: 1337,
|
||||
},
|
||||
}
|
||||
s.Exchange["test"] = uuid.Must(uuid.NewV4())
|
||||
|
||||
resp, err := s.getExchangeTickers("test")
|
||||
assert.NoError(t, err)
|
||||
if len(resp) != 1 {
|
||||
t.Fatal("unexpected length")
|
||||
}
|
||||
assert.Equal(t, resp[0].OpenInterest, 1337.0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user