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

@@ -46,6 +46,8 @@ const (
accountTypeNormal = 0 // 0: regular account
accountTypeUnified = 1 // 1: unified trade account
longDatedFormat = "02Jan06"
)
var (
@@ -321,7 +323,7 @@ func (by *Bybit) GetTickers(ctx context.Context, category, symbol, baseCoin stri
params.Set("baseCoin", baseCoin)
}
if !expiryDate.IsZero() {
params.Set("expData", expiryDate.Format("02Jan06"))
params.Set("expData", expiryDate.Format(longDatedFormat))
}
var resp *TickerData
return resp, by.SendHTTPRequest(ctx, exchange.RestSpot, common.EncodeURLValues("market/tickers", params), defaultEPL, &resp)
@@ -377,8 +379,8 @@ func (by *Bybit) GetPublicTradingHistory(ctx context.Context, category, symbol,
return resp, by.SendHTTPRequest(ctx, exchange.RestSpot, common.EncodeURLValues("market/recent-trade", params), defaultEPL, &resp)
}
// GetOpenInterest retrieves open interest of each symbol.
func (by *Bybit) GetOpenInterest(ctx context.Context, category, symbol, intervalTime string, startTime, endTime time.Time, limit int64, cursor string) (*OpenInterest, error) {
// GetOpenInterestData retrieves open interest of each symbol.
func (by *Bybit) GetOpenInterestData(ctx context.Context, category, symbol, intervalTime string, startTime, endTime time.Time, limit int64, cursor string) (*OpenInterest, error) {
if category == "" {
return nil, errCategoryNotSet
} else if category != cLinear && category != cInverse {
@@ -1236,7 +1238,7 @@ func (by *Bybit) GetPreUpgradeOptionDeliveryRecord(ctx context.Context, category
return nil, errAPIKeyIsNotUnified
}
if !expiryDate.IsZero() {
params.Set("expData", expiryDate.Format("02Jan06"))
params.Set("expData", expiryDate.Format(longDatedFormat))
}
var resp *PreUpdateOptionDeliveryRecord
return resp, by.SendAuthHTTPRequestV5(ctx, exchange.RestSpot, http.MethodGet, "/v5/pre-upgrade/asset/delivery-record", params, nil, &resp, defaultEPL)
@@ -1478,7 +1480,7 @@ func (by *Bybit) GetDeliveryRecord(ctx context.Context, category, symbol, cursor
params.Set("symbol", symbol)
}
if !expiryDate.IsZero() {
params.Set("expData", expiryDate.Format("02Jan06"))
params.Set("expData", expiryDate.Format(longDatedFormat))
}
if cursor != "" {
params.Set("cursor", cursor)