mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* 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
112 lines
2.5 KiB
Go
112 lines
2.5 KiB
Go
package key
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
)
|
|
|
|
func TestMatchesExchangeAsset(t *testing.T) {
|
|
t.Parallel()
|
|
cp := currency.NewPair(currency.BTC, currency.USD)
|
|
k := ExchangePairAsset{
|
|
Exchange: "test",
|
|
Base: cp.Base.Item,
|
|
Quote: cp.Quote.Item,
|
|
Asset: asset.Spot,
|
|
}
|
|
if !k.MatchesExchangeAsset("test", asset.Spot) {
|
|
t.Error("expected true")
|
|
}
|
|
if k.MatchesExchangeAsset("TEST", asset.Futures) {
|
|
t.Error("expected false")
|
|
}
|
|
if k.MatchesExchangeAsset("test", asset.Futures) {
|
|
t.Error("expected false")
|
|
}
|
|
if !k.MatchesExchangeAsset("TEST", asset.Spot) {
|
|
t.Error("expected true")
|
|
}
|
|
}
|
|
|
|
func TestMatchesPairAsset(t *testing.T) {
|
|
t.Parallel()
|
|
cp := currency.NewPair(currency.BTC, currency.USD)
|
|
k := ExchangePairAsset{
|
|
Base: cp.Base.Item,
|
|
Quote: cp.Quote.Item,
|
|
Asset: asset.Spot,
|
|
}
|
|
if !k.MatchesPairAsset(cp, asset.Spot) {
|
|
t.Error("expected true")
|
|
}
|
|
if k.MatchesPairAsset(cp, asset.Futures) {
|
|
t.Error("expected false")
|
|
}
|
|
if k.MatchesPairAsset(currency.EMPTYPAIR, asset.Futures) {
|
|
t.Error("expected false")
|
|
}
|
|
if k.MatchesPairAsset(currency.NewPair(currency.BTC, currency.USDT), asset.Spot) {
|
|
t.Error("expected false")
|
|
}
|
|
}
|
|
|
|
func TestMatchesExchange(t *testing.T) {
|
|
t.Parallel()
|
|
k := ExchangePairAsset{
|
|
Exchange: "test",
|
|
}
|
|
if !k.MatchesExchange("test") {
|
|
t.Error("expected true")
|
|
}
|
|
if !k.MatchesExchange("TEST") {
|
|
t.Error("expected true")
|
|
}
|
|
if k.MatchesExchange("tèst") {
|
|
t.Error("expected false")
|
|
}
|
|
if k.MatchesExchange("") {
|
|
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())
|
|
}
|