Skip to contents

Retrieves 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

  1. Query Construction: Builds a query string with the symbol parameter using build_query().

  2. URL Assembly: Combines base_url, /api/v1/market/stats, and the query string.

  3. HTTP Request: Sends a GET request with a 10-second timeout via httr::GET().

  4. Response Processing: Validates the response with process_kucoin_response() and extracts "data".

  5. Data Conversion: Converts "data" to a data.table, renames time to time_ms, and adds a timestamp column via time_convert_from_kucoin().

API Endpoint

GET https://api.kucoin.com/api/v1/market/stats

Usage

Utilised to fetch a 24-hour snapshot of market statistics for a trading symbol, including volume and price changes.

Official Documentation

KuCoin Get 24hr Stats

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()
} # }