Get Part OrderBook (Implementation)
Source:R/impl_spottrading_market_data.R
get_part_orderbook_impl.Rd
Retrieves partial orderbook depth data (20 or 100 levels) for a specified trading symbol from the KuCoin API asynchronously.
Usage
get_part_orderbook_impl(
base_url = get_base_url(),
symbol,
size,
.__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"
).- size
Integer; orderbook depth (20 or 100).
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
Input Validation: Ensures
size
is 20 or 100, aborting if invalid.Query Construction: Builds a query string with the
symbol
parameter usingbuild_query()
.URL Assembly: Combines
base_url
,/api/v1/market/orderbook/level2_{size}
, 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 bids and asks into separate
data.table
s, addsside
, combines them, and appends snapshot fields.
Usage
Utilised to obtain a snapshot of the orderbook for a trading symbol, showing aggregated bid and ask levels.
Examples
if (FALSE) { # \dontrun{
main_async <- coro::async(function() {
orderbook_20 <- await(get_part_orderbook_impl(symbol = "BTC-USDT", size = 20))
print(orderbook_20)
orderbook_100 <- await(get_part_orderbook_impl(symbol = "BTC-USDT", size = 100))
print(orderbook_100)
})
main_async()
while (!later::loop_empty()) later::run_now()
} # }