Skip to contents

Retrieves the full orderbook depth data for a specified trading symbol from the KuCoin API asynchronously, requiring authentication.

Usage

get_full_orderbook_impl(
  keys = get_api_keys(),
  base_url = get_base_url(),
  symbol,
  .__coro_env_parent__ = <environment>
)

Arguments

keys

List; API configuration parameters from get_api_keys(), including:

  • api_key (character): KuCoin API key.

  • api_secret (character): KuCoin API secret.

  • api_passphrase (character): KuCoin API passphrase.

  • key_version (character): API key version (e.g., "2"). Defaults to get_api_keys().

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.

  • sequence (character): Orderbook update sequence.

  • side (character): Order side ("bid" or "ask").

  • price (character): Aggregated price level.

  • size (character): Aggregated size at that price.

Details

Workflow Overview

  1. Header Preparation: Constructs authentication headers with build_headers() using keys.

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

  3. URL Assembly: Combines base_url, /api/v3/market/orderbook/level2, and the query string.

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

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

  6. Data Conversion: Converts bids and asks into data.tables, adds side, combines them, and appends snapshot fields.

API Endpoint

GET https://api.kucoin.com/api/v3/market/orderbook/level2

Usage

Utilised to fetch the complete orderbook for a trading symbol, requiring API authentication for detailed depth data.

Official Documentation

KuCoin Get Full OrderBook

Examples

if (FALSE) { # \dontrun{
main_async <- coro::async(function() {
  keys <- get_api_keys()
  orderbook <- await(get_full_orderbook_impl(keys = keys, symbol = "BTC-USDT"))
  print(orderbook)
})
main_async()
while (!later::loop_empty()) later::run_now()
} # }