Get 24-Hour Statistics (Implementation)
Source:R/impl_spottrading_market_data.R
get_24hr_stats_impl.RdRetrieves 24-hour market statistics for a specified trading symbol from the KuCoin API asynchronously.
Usage
get_24hr_stats_impl(
base_url = get_base_url(),
symbol,
.__coro_env_parent__ = <environment>
)Arguments
- base_url
Character string; base URL for the KuCoin API. Defaults to
get_base_url().- symbol
Character string; trading symbol (e.g.,
"BTC-USDT").
Value
Promise resolving to a data.table containing:
timestamp(POSIXct): Snapshot timestamp in UTC.time_ms(integer): Snapshot timestamp in milliseconds.symbol(character): Trading symbol.buy(character): Best bid price.sell(character): Best ask price.changeRate(character): 24-hour change rate.changePrice(character): 24-hour price change.high(character): 24-hour high price.low(character): 24-hour low price.vol(character): 24-hour trading volume.volValue(character): 24-hour turnover.last(character): Last traded price.averagePrice(character): 24-hour average price.takerFeeRate(character): Taker fee rate.makerFeeRate(character): Maker fee rate.takerCoefficient(character): Taker fee coefficient.makerCoefficient(character): Maker fee coefficient.
Details
Workflow Overview
Query Construction: Builds a query string with the
symbolparameter usingbuild_query().URL Assembly: Combines
base_url,/api/v1/market/stats, and the query string.HTTP Request: Sends a GET request with a 10-second timeout via
httr::GET().Response Processing: Validates the response with
process_kucoin_response()and extracts"data".Data Conversion: Converts
"data"to adata.table, renamestimetotime_ms, and adds atimestampcolumn viatime_convert_from_kucoin().
Usage
Utilised to fetch a 24-hour snapshot of market statistics for a trading symbol, including volume and price changes.
Examples
if (FALSE) { # \dontrun{
main_async <- coro::async(function() {
stats <- await(get_24hr_stats_impl(symbol = "BTC-USDT"))
print(stats)
})
main_async()
while (!later::loop_empty()) later::run_now()
} # }