-
Notifications
You must be signed in to change notification settings - Fork 24
Limits and Restrictions
The API documentation and its quality varies significantly across
exchanges and, especially, between spot
- and futures
-markets.
BitMart, for example, doesn’t provide an upper limit of returned data in futures markets, but has a limit on 200 for the spot market.
A safe assumption in such cases is that the number of available data is limited by the listing date. Given this uncertainty, however, {cryptoQuotes} puts an upper limit on the date range for 200, to ensure consistency across exchanges
In this document the limits are inferred from the API documentation if declared; if this cant be inferred then the upper-limit is identified by extending the calls gradually until the API-endpoint produces an error.
Exchange | Spot | Futures |
---|---|---|
Binance | 1000 | 1500 |
BitMart | 200 | 1200 |
Bybit | 1000 | 1000 |
Crypto.com | 300 | 300 |
Huobi (HTX) | 2000 | 2000 |
Kraken | 720 | 5000 |
KuCoin | 1500 | 200 |
MEXC | 1000 | 2000 |
Each exchange handles API
-calls differently on calls that exceed the
allowed limits. Binance, for example, returns the first 1000 data points
while Bitmart throws an error. Below is an example from Bitmart,
## 1) Get BTC
## from Bitmart with
## wide dates to force
## error
ohlc <- try(
cryptoQuotes::get_quote(
ticker = "BTC_USDT",
source = "bitmart",
interval = "1m",
futures = FALSE,
from = Sys.Date() - 1000,
to = Sys.Date()
)
)
#> Error in rmarkdown::render("/home/serkan/Documents/Projects/cryptoQuotes.wiki/Limits and Restrictions.Rmd", :
#> ✖ Couldn't find "BTC_USDT" on "bitmart".
#> ✔ Run available_tickers(source = 'bitmart', futures = FALSE) to see available
#> tickers.
#> ℹ If the error persists please submit a bug report.
## 2) print the
## class
class(ohlc)
#> [1] "try-error"
As per version 1.3.0
there is no fix on this inconsistent behavior.
Therefore, if everything is correctly specified in your
get_*()
-function, the error is most likely on the API
-side.
Note
Submit a bug-report if there appears to be errors on the client-side
of the get_*()
-function.
Assume that you need 2000 of the latest datapoints that is only available on Binance, then one solution to the 1000-limit is the following,
## 1) generate a sequance
## of dates
dates <- seq(
from = as.POSIXct(Sys.time()),
by = "-15 mins",
length.out = 2000
)
## 2) split the sequence
## in multiples of 100
## by assigning numbers
## to each indices of 100
idx <- rep(
x = 1:2,
each = 1000
)
## 3) use the idx to split
## the dates into equal parts
split_dates <- lapply(
split(
x = dates,
f = idx
),
function(x) {
# 1) extract date range
date_range <- range(x)
# 2) round to nearest 15 minutes
as.POSIXct(
round(as.numeric(date_range) / 900) * 900,
origin="1970-01-01"
)
}
)
## 4) collect all all
## calls in a list
## using lapply
ohlc <- lapply(
X = split_dates,
FUN = function(dates){
Sys.sleep(1)
cryptoQuotes::get_quote(
ticker = "BTCUSDT",
source = "binance",
futures = FALSE,
interval = "15m",
from = dates[1],
to = dates[2]
)
}
)
## 4.1) rbind all
## elements
ohlc <- do.call(
what = rbind,
args = ohlc
)
## 4.2) print the
## number of rows
cat(
"OHLC has",nrow(ohlc), "rows!"
)
#> OHLC has 2000 rows!
There are other various restrictions on the returned data points that is
dependent on the endpoint and exchange, which are not documented by the
API
-documentations.
One such undocumented restriction is from the Kucoin exchange, that won’t return historical market on higher granularity like the 15 minute candles. See the example below,
## 1) extract
## old 15m data
## from Kucoin
ohlc <- try(
cryptoQuotes::get_quote(
ticker = "BTCUSDTM",
source = "kucoin",
futures = TRUE,
interval = "15m",
from = Sys.Date() - 365,
to = Sys.Date() - 363
)
)
#> Error in rmarkdown::render("/home/serkan/Documents/Projects/cryptoQuotes.wiki/Limits and Restrictions.Rmd", :
#> ✖ Couldn't find "BTCUSDTM" on "kucoin".
#> ✔ Run available_tickers(source = 'kucoin', futures = TRUE) to see available
#> tickers.
#> ℹ If the error persists please submit a bug report.
## 2) check class
## of the ohlv
class(ohlc)
#> [1] "try-error"
The error
-message indicates that the BTCUSDT
-pair doesn’t exist on
the perpetual futures market. This behavior is not documented on the
Kucoin API
-documentation.
It would be a safe assumption that Kucoin doesn’t support higher granularity from last year. However, the below example which extracts data from the spot-market shows otherwise,
## 1) extract
## old 15m data
## from Kucoin
ohlc <- try(
cryptoQuotes::get_quote(
ticker = "BTC-USDT",
source = "kucoin",
futures = FALSE,
interval = "15m",
from = Sys.Date() - 365,
to = Sys.Date() - 363
)
)
## 2) check class
## of the ohlv
class(ohlc)
#> [1] "xts" "zoo"
As all the inconsistencies across and within Exchanges can’t be determined a priori due to lack of documentation, it is recommended to switch between enpoints and exchanges like in the example above.
The same limits apply across other endpoints like get_lsratio()
- and
get_openinterest()
-functions, with some variation. Therefore if the
returned number of data points is not aligned with your expectations, it
is most likely an endpoint restriction.
However, please submit a bug report if you are convinced that it is a client-side issue.
Last updated 2024-07-05