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

@@ -35,13 +35,35 @@ type SubAccountCurrencyAsset struct {
Asset asset.Item
}
// Pair combines the base and quote into a pair
func (k *PairAsset) Pair() currency.Pair {
if k == nil || (k.Base == nil && k.Quote == nil) {
return currency.EMPTYPAIR
}
return currency.NewPair(k.Base.Currency(), k.Quote.Currency())
}
// Pair combines the base and quote into a pair
func (k *ExchangePairAsset) Pair() currency.Pair {
if k == nil || (k.Base == nil && k.Quote == nil) {
return currency.EMPTYPAIR
}
return currency.NewPair(k.Base.Currency(), k.Quote.Currency())
}
// MatchesExchangeAsset checks if the key matches the exchange and asset
func (k *ExchangePairAsset) MatchesExchangeAsset(exch string, item asset.Item) bool {
if k == nil {
return false
}
return strings.EqualFold(k.Exchange, exch) && k.Asset == item
}
// MatchesPairAsset checks if the key matches the pair and asset
func (k *ExchangePairAsset) MatchesPairAsset(pair currency.Pair, item asset.Item) bool {
if k == nil {
return false
}
return k.Base == pair.Base.Item &&
k.Quote == pair.Quote.Item &&
k.Asset == item
@@ -49,5 +71,8 @@ func (k *ExchangePairAsset) MatchesPairAsset(pair currency.Pair, item asset.Item
// MatchesExchange checks if the exchange matches
func (k *ExchangePairAsset) MatchesExchange(exch string) bool {
if k == nil {
return false
}
return strings.EqualFold(k.Exchange, exch)
}

View File

@@ -3,6 +3,7 @@ package key
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
)
@@ -70,3 +71,41 @@ func TestMatchesExchange(t *testing.T) {
t.Error("expected false")
}
}
func TestExchangePairAsset_Pair(t *testing.T) {
t.Parallel()
cp := currency.NewPair(currency.BTC, currency.USD)
k := ExchangePairAsset{
Base: currency.BTC.Item,
Quote: currency.USD.Item,
Asset: asset.Spot,
}
assert.Equal(t, cp, k.Pair())
cp = currency.NewPair(currency.BTC, currency.EMPTYCODE)
k.Quote = currency.EMPTYCODE.Item
assert.Equal(t, cp, k.Pair())
cp = currency.EMPTYPAIR
var epa *ExchangePairAsset
assert.Equal(t, cp, epa.Pair())
}
func TestPairAsset_Pair(t *testing.T) {
t.Parallel()
cp := currency.NewPair(currency.BTC, currency.USD)
k := PairAsset{
Base: currency.BTC.Item,
Quote: currency.USD.Item,
Asset: asset.Spot,
}
assert.Equal(t, cp, k.Pair())
cp = currency.NewPair(currency.BTC, currency.EMPTYCODE)
k.Quote = currency.EMPTYCODE.Item
assert.Equal(t, cp, k.Pair())
cp = currency.EMPTYPAIR
var pa *PairAsset
assert.Equal(t, cp, pa.Pair())
}