Get Full OrderBook (Implementation, Authenticated)
Source:R/impl_spottrading_market_data.R
get_full_orderbook_impl.Rd
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 toget_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
Header Preparation: Constructs authentication headers with
build_headers()
usingkeys
.Query Construction: Builds a query string with the
symbol
parameter usingbuild_query()
.URL Assembly: Combines
base_url
,/api/v3/market/orderbook/level2
, and the query string.HTTP Request: Sends a GET request with headers and a 10-second timeout via
httr::GET()
.Response Processing: Validates the response with
process_kucoin_response()
and extracts"data"
.Data Conversion: Converts bids and asks into
data.table
s, addsside
, combines them, and appends snapshot fields.
Usage
Utilised to fetch the complete orderbook for a trading symbol, requiring API authentication for detailed depth data.
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()
} # }