Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions exchanges/binance/binance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2803,23 +2803,32 @@ func TestGetHistoricalFundingRates(t *testing.T) {

func TestGetLatestFundingRates(t *testing.T) {
t.Parallel()
cp := currency.NewBTCUSDT()

e := new(Exchange)
require.NoError(t, testexch.Setup(e), "Setup must not error for local exchange instance")
if mockTests {
require.NoError(t, testexch.MockHTTPInstance(e), "MockHTTPInstance must not error for local exchange instance")
}
testexch.UpdatePairsOnce(t, e)

usdtPerpetualPair := currency.NewBTCUSDT()
_, err := e.GetLatestFundingRates(t.Context(), &fundingrate.LatestRateRequest{
Asset: asset.USDTMarginedFutures,
Pair: cp,
Pair: usdtPerpetualPair,
IncludePredictedRate: true,
})
assert.ErrorIs(t, err, common.ErrFunctionNotSupported)

err = e.CurrencyPairs.EnablePair(asset.USDTMarginedFutures, cp)
err = e.CurrencyPairs.EnablePair(asset.USDTMarginedFutures, usdtPerpetualPair)
require.Truef(t, err == nil || errors.Is(err, currency.ErrPairAlreadyEnabled),
"EnablePair for asset %s and pair %s must not error: %s", asset.USDTMarginedFutures, cp, err)
"EnablePair for asset %s and pair %s must not error: %s", asset.USDTMarginedFutures, usdtPerpetualPair, err)

_, err = e.GetLatestFundingRates(t.Context(), &fundingrate.LatestRateRequest{
Asset: asset.USDTMarginedFutures,
Pair: cp,
Pair: usdtPerpetualPair,
})
assert.NoError(t, err, "GetLatestFundingRates should not error for USDTMarginedFutures")

_, err = e.GetLatestFundingRates(t.Context(), &fundingrate.LatestRateRequest{
Asset: asset.CoinMarginedFutures,
})
Expand Down
4 changes: 2 additions & 2 deletions exchanges/bitfinex/bitfinex.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ func (e *Exchange) GetFundingBook(ctx context.Context, symbol string) (FundingBo
response := FundingBook{}
path := bitfinexAPIVersion + bitfinexLendbook + symbol

if err := e.SendHTTPRequest(ctx, exchange.RestSpot, path, &response, fundingbook); err != nil {
if err := e.SendHTTPRequest(ctx, exchange.RestSpot, path, &response, fundingBook); err != nil {
return response, err
}

Expand Down Expand Up @@ -1202,7 +1202,7 @@ func (e *Exchange) GetKeyPermissions(ctx context.Context) (KeyPermissions, error
bitfinexKeyPermissions,
nil,
&response,
getAccountFees)
getKeyPermissions)
}

// GetMarginInfo shows your trading wallet information for margin trading
Expand Down
130 changes: 68 additions & 62 deletions exchanges/bitfinex/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,86 +8,92 @@ import (

const (
// Bitfinex rate limits - Public
requestLimitInterval = time.Minute
requestLimitInterval = time.Minute

undocumentedFallback5ReqRate = 5 // Fallback for undocumented legacy V1 endpoints that have historically used 5 req/min.
undocumentedFallback10ReqRate = 10 // Fallback for undocumented legacy V1 endpoints that have historically used 10 req/min.
undocumentedFallback15ReqRate = 15 // Fallback for undocumented legacy V1 endpoints that have historically used 15 req/min.
undocumentedFallback45ReqRate = 45 // Fallback for endpoints with no explicit per-endpoint value in current Bitfinex docs.

platformStatusReqRate = 15
tickerBatchReqRate = 30
tickerReqRate = 30
tradeReqRate = 30
orderbookReqRate = 30
statsReqRate = 90
candleReqRate = 60
candleReqRate = 30
configsReqRate = 15
statusReqRate = 15 // This is not specified just inputted WCS
liquidReqRate = 15 // This is not specified just inputted WCS
statusReqRate = undocumentedFallback15ReqRate
liquidReqRate = undocumentedFallback15ReqRate
leaderBoardReqRate = 90
marketAveragePriceReqRate = 20
fxReqRate = 20
fxReqRate = 90

// Bitfinex rate limits - Authenticated
// Wallets -
accountWalletBalanceReqRate = 45
accountWalletHistoryReqRate = 45
accountWalletBalanceReqRate = undocumentedFallback45ReqRate
accountWalletHistoryReqRate = undocumentedFallback45ReqRate
// Orders -
retrieveOrderReqRate = 45
submitOrderReqRate = 45 // This is not specified just inputted above
updateOrderReqRate = 45 // This is not specified just inputted above
cancelOrderReqRate = 45 // This is not specified just inputted above
orderBatchReqRate = 45 // This is not specified just inputted above
cancelBatchReqRate = 45 // This is not specified just inputted above
orderHistoryReqRate = 45
getOrderTradesReqRate = 45
getTradesReqRate = 45
getLedgersReqRate = 45
retrieveOrderReqRate = undocumentedFallback45ReqRate
submitOrderReqRate = undocumentedFallback45ReqRate
updateOrderReqRate = undocumentedFallback45ReqRate
cancelOrderReqRate = undocumentedFallback45ReqRate
orderBatchReqRate = undocumentedFallback45ReqRate
cancelBatchReqRate = undocumentedFallback45ReqRate
orderHistoryReqRate = undocumentedFallback45ReqRate
getOrderTradesReqRate = undocumentedFallback45ReqRate
getTradesReqRate = undocumentedFallback45ReqRate
getLedgersReqRate = undocumentedFallback45ReqRate
// Positions -
getAccountMarginInfoReqRate = 45
getActivePositionsReqRate = 45
claimPositionReqRate = 45 // This is not specified just inputted above
getPositionHistoryReqRate = 45
getPositionAuditReqRate = 45
updateCollateralOnPositionReqRate = 45 // This is not specified just inputted above
getAccountMarginInfoReqRate = undocumentedFallback45ReqRate
getActivePositionsReqRate = undocumentedFallback45ReqRate
claimPositionReqRate = undocumentedFallback45ReqRate
getPositionHistoryReqRate = undocumentedFallback45ReqRate
getPositionAuditReqRate = undocumentedFallback45ReqRate
updateCollateralOnPositionReqRate = undocumentedFallback45ReqRate
// Margin funding -
getMarginInfoRate = 90
getActiveFundingOffersReqRate = 45
submitFundingOfferReqRate = 45 // This is not specified just inputted above
cancelFundingOfferReqRate = 45
cancelAllFundingOfferReqRate = 45 // This is not specified just inputted above
closeFundingReqRate = 45 // This is not specified just inputted above
fundingAutoRenewReqRate = 45 // This is not specified just inputted above
keepFundingReqRate = 45 // This is not specified just inputted above
getOffersHistoryReqRate = 45
getFundingLoansReqRate = 45
getFundingLoanHistoryReqRate = 45
getFundingCreditsReqRate = 45
getFundingCreditsHistoryReqRate = 45
getFundingTradesReqRate = 45
getFundingInfoReqRate = 45
getActiveFundingOffersReqRate = undocumentedFallback45ReqRate
submitFundingOfferReqRate = undocumentedFallback45ReqRate
cancelFundingOfferReqRate = undocumentedFallback45ReqRate
cancelAllFundingOfferReqRate = undocumentedFallback45ReqRate
closeFundingReqRate = undocumentedFallback45ReqRate
fundingAutoRenewReqRate = undocumentedFallback45ReqRate
keepFundingReqRate = undocumentedFallback45ReqRate
getOffersHistoryReqRate = undocumentedFallback45ReqRate
getFundingLoansReqRate = undocumentedFallback45ReqRate
getFundingLoanHistoryReqRate = undocumentedFallback45ReqRate
getFundingCreditsReqRate = undocumentedFallback45ReqRate
getFundingCreditsHistoryReqRate = undocumentedFallback45ReqRate
getFundingTradesReqRate = undocumentedFallback45ReqRate
getFundingInfoReqRate = undocumentedFallback45ReqRate
// Account actions
getUserInfoReqRate = 45
transferBetweenWalletsReqRate = 45 // This is not specified just inputted above
getDepositAddressReqRate = 45 // This is not specified just inputted above
withdrawalReqRate = 45 // This is not specified just inputted above
getMovementsReqRate = 45
getAlertListReqRate = 45
setPriceAlertReqRate = 45 // This is not specified just inputted above
deletePriceAlertReqRate = 45 // This is not specified just inputted above
getBalanceForOrdersOffersReqRate = 30
userSettingsWriteReqRate = 45 // This is not specified just inputted general count
userSettingsReadReqRate = 45
userSettingsDeleteReqRate = 45 // This is not specified just inputted above
getUserInfoReqRate = undocumentedFallback45ReqRate
transferBetweenWalletsReqRate = undocumentedFallback45ReqRate
getDepositAddressReqRate = undocumentedFallback45ReqRate
withdrawalReqRate = undocumentedFallback45ReqRate
getMovementsReqRate = undocumentedFallback45ReqRate
getAlertListReqRate = undocumentedFallback45ReqRate
setPriceAlertReqRate = 90
deletePriceAlertReqRate = 90
getBalanceForOrdersOffersReqRate = 90
userSettingsWriteReqRate = 90
userSettingsReadReqRate = 90
userSettingsDeleteReqRate = 90
// Account V1 endpoints
getAccountFeesReqRate = 5
getWithdrawalFeesReqRate = 5
getAccountSummaryReqRate = 5 // This is not specified just inputted above
newDepositAddressReqRate = 5 // This is not specified just inputted above
getKeyPermissionsReqRate = 5 // This is not specified just inputted above
getMarginInfoReqRate = 5 // This is not specified just inputted above
getAccountSummaryReqRate = undocumentedFallback5ReqRate
newDepositAddressReqRate = undocumentedFallback5ReqRate
getKeyPermissionsReqRate = undocumentedFallback5ReqRate
getMarginInfoReqRate = undocumentedFallback5ReqRate
getAccountBalanceReqRate = 10
walletTransferReqRate = 10 // This is not specified just inputted above
withdrawV1ReqRate = 10 // This is not specified just inputted above
orderV1ReqRate = 10 // This is not specified just inputted above
orderMultiReqRate = 10 // This is not specified just inputted above
walletTransferReqRate = undocumentedFallback10ReqRate
withdrawV1ReqRate = undocumentedFallback10ReqRate
orderV1ReqRate = undocumentedFallback10ReqRate
orderMultiReqRate = undocumentedFallback10ReqRate
statsV1ReqRate = 10
fundingbookReqRate = 15
fundingBookReqRate = 15
lendsReqRate = 30

// Rate limit endpoint functionality declaration
Expand Down Expand Up @@ -168,7 +174,7 @@ const (
orderV1
orderMulti
statsV1
fundingbook
fundingBook
lends
)

Expand Down Expand Up @@ -205,7 +211,7 @@ func GetRateLimit() request.RateLimitDefinitions {
getAccountMarginInfo: request.NewRateLimitWithWeight(requestLimitInterval, getAccountMarginInfoReqRate, 1),
getActivePositions: request.NewRateLimitWithWeight(requestLimitInterval, getActivePositionsReqRate, 1),
claimPosition: request.NewRateLimitWithWeight(requestLimitInterval, claimPositionReqRate, 1),
getPositionHistory: request.NewRateLimitWithWeight(requestLimitInterval, getPositionAuditReqRate, 1),
getPositionHistory: request.NewRateLimitWithWeight(requestLimitInterval, getPositionHistoryReqRate, 1),
getPositionAudit: request.NewRateLimitWithWeight(requestLimitInterval, getPositionAuditReqRate, 1),
updateCollateralOnPosition: request.NewRateLimitWithWeight(requestLimitInterval, updateCollateralOnPositionReqRate, 1),
// Margin funding -
Expand All @@ -217,7 +223,7 @@ func GetRateLimit() request.RateLimitDefinitions {
fundingAutoRenew: request.NewRateLimitWithWeight(requestLimitInterval, fundingAutoRenewReqRate, 1),
keepFunding: request.NewRateLimitWithWeight(requestLimitInterval, keepFundingReqRate, 1),
getOffersHistory: request.NewRateLimitWithWeight(requestLimitInterval, getOffersHistoryReqRate, 1),
getFundingLoans: request.NewRateLimitWithWeight(requestLimitInterval, getOffersHistoryReqRate, 1),
getFundingLoans: request.NewRateLimitWithWeight(requestLimitInterval, getFundingLoansReqRate, 1),
getFundingLoanHistory: request.NewRateLimitWithWeight(requestLimitInterval, getFundingLoanHistoryReqRate, 1),
getFundingCredits: request.NewRateLimitWithWeight(requestLimitInterval, getFundingCreditsReqRate, 1),
getFundingCreditsHistory: request.NewRateLimitWithWeight(requestLimitInterval, getFundingCreditsHistoryReqRate, 1),
Expand Down Expand Up @@ -249,7 +255,7 @@ func GetRateLimit() request.RateLimitDefinitions {
orderV1: request.NewRateLimitWithWeight(requestLimitInterval, orderV1ReqRate, 1),
orderMulti: request.NewRateLimitWithWeight(requestLimitInterval, orderMultiReqRate, 1),
statsV1: request.NewRateLimitWithWeight(requestLimitInterval, statsV1ReqRate, 1),
fundingbook: request.NewRateLimitWithWeight(requestLimitInterval, fundingbookReqRate, 1),
fundingBook: request.NewRateLimitWithWeight(requestLimitInterval, fundingBookReqRate, 1),
lends: request.NewRateLimitWithWeight(requestLimitInterval, lendsReqRate, 1),
}
}
4 changes: 2 additions & 2 deletions exchanges/okx/okx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3888,8 +3888,8 @@ func TestGetHistoricCandles(t *testing.T) {
require.NoErrorf(t, err, "GetEnabledPairs for asset %s must not error", a)
require.NotEmptyf(t, pairs, "GetEnabledPairs for asset %s must not return empty pairs", a)
result, err := e.GetHistoricCandles(contextGenerate(), pairs[0], a, kline.OneMin, time.Now().Add(-time.Hour), time.Now())
if (a == asset.Spread || a == asset.Options) && err != nil { // Options and spread candles sometimes returns no data
continue
if (a == asset.Spread || a == asset.Options || a == asset.Futures) && errors.Is(err, kline.ErrNoTimeSeriesDataToConvert) {
continue // These market types can legitimately return no candles for some windows.
}
require.NoErrorf(t, err, "GetHistoricCandles for asset %s and pair %s must not error", a, pairs[0])
assert.NotNilf(t, result, "GetHistoricCandles for asset %s and pair %s should not return nil", a, pairs[0])
Expand Down
16 changes: 12 additions & 4 deletions exchanges/poloniex/poloniex_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,11 @@ func (e *Exchange) UpdateTickers(ctx context.Context, assetType asset.Item) erro
func (e *Exchange) UpdateTicker(ctx context.Context, pair currency.Pair, assetType asset.Item) (*ticker.Price, error) {
switch assetType {
case asset.Spot:
tickerResult, err := e.GetTicker(ctx, pair)
formattedPair, err := e.FormatExchangeCurrency(pair, assetType)
if err != nil {
return nil, err
}
tickerResult, err := e.GetTicker(ctx, formattedPair)
if err != nil {
return nil, err
}
Expand All @@ -393,7 +397,7 @@ func (e *Exchange) UpdateTicker(ctx context.Context, pair currency.Pair, assetTy
Open: tickerResult.Open.Float64(),
Close: tickerResult.Close.Float64(),
MarkPrice: tickerResult.MarkPrice.Float64(),
Pair: tickerResult.Symbol,
Pair: pair,
ExchangeName: e.Name,
AssetType: asset.Spot,
LastUpdated: tickerResult.Timestamp.Time(),
Expand All @@ -402,7 +406,11 @@ func (e *Exchange) UpdateTicker(ctx context.Context, pair currency.Pair, assetTy
}
return ticker.GetTicker(e.Name, pair, assetType)
case asset.Futures:
tickerResult, err := e.GetFuturesMarket(ctx, pair)
formattedPair, err := e.FormatExchangeCurrency(pair, assetType)
if err != nil {
return nil, err
}
tickerResult, err := e.GetFuturesMarket(ctx, formattedPair)
if err != nil {
return nil, err
}
Expand All @@ -421,7 +429,7 @@ func (e *Exchange) UpdateTicker(ctx context.Context, pair currency.Pair, assetTy
Open: tickerResult[0].OpeningPrice.Float64(),
Close: tickerResult[0].ClosingPrice.Float64(),
MarkPrice: tickerResult[0].MarkPrice.Float64(),
Pair: tickerResult[0].Symbol,
Pair: pair,
ExchangeName: e.Name,
AssetType: asset.Futures,
LastUpdated: tickerResult[0].Timestamp.Time(),
Expand Down
6 changes: 3 additions & 3 deletions exchanges/poloniex/testdata/http.json
Original file line number Diff line number Diff line change
Expand Up @@ -12428,7 +12428,7 @@
"mPx": "104271.54",
"o": "102850.98",
"qty": "161306",
"s": "ABC-DEF",
"s": "ABC_DEF",
"sT": 1734272820000,
"tC": 8527
},
Expand All @@ -12447,14 +12447,14 @@
"mPx": "104271.54",
"o": "102850.98",
"qty": "161306",
"s": "ABC-DEF",
"s": "ABC_DEF",
"sT": 1734272820000,
"tC": 8527
}
],
"msg": "Success"
},
"queryString": "symbol=ABC-DEF",
"queryString": "symbol=ABC_DEF",
"bodyParams": "",
"headers": {}
},
Expand Down
Loading