mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 07:26: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:
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/key"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
@@ -182,6 +183,9 @@ func (b *Binance) SetDefaults() {
|
||||
FundingRateBatching: map[asset.Item]bool{
|
||||
asset.USDTMarginedFutures: true,
|
||||
},
|
||||
OpenInterest: exchange.OpenInterestSupport{
|
||||
Supported: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Enabled: exchange.FeaturesEnabled{
|
||||
@@ -3102,3 +3106,50 @@ func (b *Binance) GetFuturesContractDetails(ctx context.Context, item asset.Item
|
||||
}
|
||||
return nil, fmt.Errorf("%w %v", asset.ErrNotSupported, item)
|
||||
}
|
||||
|
||||
// GetOpenInterest returns the open interest rate for a given asset pair
|
||||
func (b *Binance) GetOpenInterest(ctx context.Context, k ...key.PairAsset) ([]futures.OpenInterest, error) {
|
||||
if len(k) == 0 {
|
||||
return nil, fmt.Errorf("%w requires pair", common.ErrFunctionNotSupported)
|
||||
}
|
||||
for i := range k {
|
||||
if k[i].Asset != asset.USDTMarginedFutures && k[i].Asset != asset.CoinMarginedFutures {
|
||||
// avoid API calls or returning errors after a successful retrieval
|
||||
return nil, fmt.Errorf("%w %v %v", asset.ErrNotSupported, k[i].Asset, k[i].Pair())
|
||||
}
|
||||
}
|
||||
result := make([]futures.OpenInterest, len(k))
|
||||
for i := range k {
|
||||
switch k[i].Asset {
|
||||
case asset.USDTMarginedFutures:
|
||||
oi, err := b.UOpenInterest(ctx, k[i].Pair())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result[i] = futures.OpenInterest{
|
||||
Key: key.ExchangePairAsset{
|
||||
Exchange: b.Name,
|
||||
Base: k[i].Base,
|
||||
Quote: k[i].Quote,
|
||||
Asset: k[i].Asset,
|
||||
},
|
||||
OpenInterest: oi.OpenInterest,
|
||||
}
|
||||
case asset.CoinMarginedFutures:
|
||||
oi, err := b.OpenInterest(ctx, k[i].Pair())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result[i] = futures.OpenInterest{
|
||||
Key: key.ExchangePairAsset{
|
||||
Exchange: b.Name,
|
||||
Base: k[i].Base,
|
||||
Quote: k[i].Quote,
|
||||
Asset: k[i].Asset,
|
||||
},
|
||||
OpenInterest: oi.OpenInterest,
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user