mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +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:
@@ -3,6 +3,7 @@ package sharedtestvalues
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -13,7 +14,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
|
||||
)
|
||||
|
||||
@@ -182,3 +185,44 @@ func TestFixtureToDataHandler(t *testing.T, seed, e exchange.IBotExchange, fixtu
|
||||
}
|
||||
assert.NoError(t, s.Err(), "Fixture Scanner should not error")
|
||||
}
|
||||
|
||||
// SetupCurrencyPairsForExchangeAsset enables an asset for an exchange
|
||||
// and adds the currency pair(s) to the available and enabled list of existing pairs
|
||||
// if it is already enabled or part of the pairs, no error is raised
|
||||
func SetupCurrencyPairsForExchangeAsset(t *testing.T, exch exchange.IBotExchange, a asset.Item, cp ...currency.Pair) {
|
||||
t.Helper()
|
||||
if len(cp) == 0 {
|
||||
return
|
||||
}
|
||||
b := exch.GetBase()
|
||||
err := b.CurrencyPairs.SetAssetEnabled(a, true)
|
||||
if err != nil && !errors.Is(err, currency.ErrAssetAlreadyEnabled) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
availPairs, err := b.CurrencyPairs.GetPairs(a, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
apLen := len(availPairs)
|
||||
enabledPairs, err := b.CurrencyPairs.GetPairs(a, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
epLen := len(enabledPairs)
|
||||
for i := range cp {
|
||||
availPairs = availPairs.Add(cp[i])
|
||||
enabledPairs = enabledPairs.Add(cp[i])
|
||||
}
|
||||
if len(availPairs) != apLen {
|
||||
err = b.CurrencyPairs.StorePairs(a, availPairs, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if len(enabledPairs) != epLen {
|
||||
err = b.CurrencyPairs.StorePairs(a, enabledPairs, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user