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:
Scott
2024-01-12 15:27:35 +11:00
committed by GitHub
parent 614042110a
commit b71bf1f3d1
62 changed files with 22660 additions and 10095 deletions

View File

@@ -7,18 +7,22 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/common/key"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/collateral"
"github.com/thrasher-corp/gocryptotrader/exchanges/futures"
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/margin"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
)
@@ -3209,3 +3213,59 @@ func TestIsPairEnabled(t *testing.T) {
t.Fatal("expected true")
}
}
func TestGetOpenInterest(t *testing.T) {
t.Parallel()
var b Base
if _, err := b.GetOpenInterest(context.Background()); !errors.Is(err, common.ErrFunctionNotSupported) {
t.Errorf("received: %v, expected: %v", err, common.ErrFunctionNotSupported)
}
}
// FakeBase is used to override functions
type FakeBase struct {
Base
}
func (f *FakeBase) GetOpenInterest(context.Context, ...key.PairAsset) ([]futures.OpenInterest, error) {
return []futures.OpenInterest{
{
Key: key.ExchangePairAsset{
Exchange: f.Name,
Base: currency.BTC.Item,
Quote: currency.BONK.Item,
Asset: asset.Futures,
},
OpenInterest: 1337,
},
}, nil
}
func TestGetCachedOpenInterest(t *testing.T) {
t.Parallel()
var b FakeBase
b.Features.Supports.FuturesCapabilities.OpenInterest = OpenInterestSupport{
Supported: true,
}
_, err := b.GetCachedOpenInterest(context.Background())
assert.ErrorIs(t, err, common.ErrFunctionNotSupported)
b.Features.Supports.FuturesCapabilities.OpenInterest.SupportedViaTicker = true
b.Name = "test"
err = ticker.ProcessTicker(&ticker.Price{
ExchangeName: "test",
Pair: currency.NewPair(currency.BTC, currency.BONK),
AssetType: asset.Futures,
OpenInterest: 1337,
})
assert.NoError(t, err)
_, err = b.GetCachedOpenInterest(context.Background())
assert.NoError(t, err)
_, err = b.GetCachedOpenInterest(context.Background(), key.PairAsset{
Base: currency.BTC.Item,
Quote: currency.BONK.Item,
Asset: asset.Futures,
})
assert.NoError(t, err)
}