| Title: | Streaming-Native Crypto Exchange Connectivity |
|---|---|
| Description: | R bindings for wickra-exchange over its C ABI hub: one synchronous, pull-based API over the ten largest crypto exchanges, plus offline paper and replay simulators that share the exact same API. The same strategy runs paper, replay and live by swapping the constructor. |
| Authors: | kingchenc [aut, cre] |
| Maintainer: | kingchenc <[email protected]> |
| License: | MIT + file LICENSE | Apache License 2.0 |
| Version: | 0.2.0 |
| Built: | 2026-10-07 08:57:59 UTC |
| Source: | https://github.com/wickra-lib/wickra-exchange |
Fails for a venue without an advanced-order surface (coinbase, upbit).
wkex_advanced( name, api_key, api_secret, passphrase = NULL, private_key = NULL, testnet = FALSE, futures = FALSE )wkex_advanced( name, api_key, api_secret, passphrase = NULL, private_key = NULL, testnet = FALSE, futures = FALSE )
name, api_key, api_secret
|
Venue and API credentials. |
passphrase, private_key
|
Optional extra credentials (NULL if unused). |
testnet |
Use the venue testnet. |
futures |
Select the USD-M futures market. |
A 'wickra_advanced' object.
Pass 'NA' for 'new_price' or 'new_quantity' to leave that field unchanged.
wkex_amend_order( adv, market, order_id, new_price = NA_real_, new_quantity = NA_real_ )wkex_amend_order( adv, market, order_id, new_price = NA_real_, new_quantity = NA_real_ )
adv |
A 'wickra_advanced' object. |
market |
Market symbol. |
order_id |
Venue order id. |
new_price, new_quantity
|
New values, or NA to leave unchanged. |
The refreshed order list.
The free balance of an asset.
wkex_balance(ex, asset)wkex_balance(ex, asset)
ex |
A 'wickra_exchange' object. |
asset |
Asset symbol, e.g. "BTC". |
The free balance as a number.
Cancel an open order by venue id.
wkex_cancel(ex, market, order_id)wkex_cancel(ex, market, order_id)
ex |
A 'wickra_exchange' object. |
market |
Market string. |
order_id |
The venue order id. |
Invisibly, 'ex'.
Cancel several orders on a market in one request.
wkex_cancel_batch(adv, market, order_ids)wkex_cancel_batch(adv, market, order_ids)
adv |
A 'wickra_advanced' object. |
market |
Market symbol. |
order_ids |
Character vector of venue order ids. |
Flatten the open position in a market with a reduce-only market order.
wkex_close_position(deriv, market)wkex_close_position(deriv, market)
deriv |
A 'wickra_derivatives' object. |
market |
Market symbol. |
The resulting order list.
The derivatives, advanced-orders, user-data and ws-execution constructors each connect internally, so this was the one missing door: without it R could reach those handles against a real venue while having no way to build a plain exchange for market data and order execution.
wkex_connect( name, api_key, api_secret, passphrase = NULL, private_key = NULL, testnet = FALSE, market = "spot", margin_mode = "cross", position_mode = "one_way" )wkex_connect( name, api_key, api_secret, passphrase = NULL, private_key = NULL, testnet = FALSE, market = "spot", margin_mode = "cross", position_mode = "one_way" )
name |
Venue identifier, e.g. "binance". |
api_key, api_secret
|
API credentials. |
passphrase, private_key
|
Optional extra credentials (NULL if unused). |
testnet |
Use the venue testnet. |
market |
Which market of the venue: "spot" (default) or "usdm_futures". A venue is several APIs behind one name, and this is the choice between them. Coin-margined and margin are not offered: no client routes them consistently, and Binance treats coin-margined as spot. |
margin_mode |
"cross" (default) or "isolated". Two venues carry it on every order, so it belongs here rather than in a later call. |
position_mode |
"one_way" (default) or "hedge". On a hedged account every order names the side of the account it acts on. |
A 'wickra_exchange' object.
Positions, leverage, margin mode and reduce-only close. Fails for a spot-only venue (coinbase, upbit).
wkex_derivatives( name, api_key, api_secret, passphrase = NULL, private_key = NULL, testnet = FALSE )wkex_derivatives( name, api_key, api_secret, passphrase = NULL, private_key = NULL, testnet = FALSE )
name, api_key, api_secret
|
Venue and API credentials. |
passphrase, private_key
|
Optional extra credentials (NULL if unused). |
testnet |
Use the venue testnet. |
A 'wickra_derivatives' object.
Refreshes the venue session / sends a heartbeat so the stream is not dropped for inactivity; call it periodically. A dropped stream is also recovered automatically on the next [wkex_user_data_poll()]. A no-op before [wkex_subscribe_user_data()].
wkex_keepalive_user_data(ud)wkex_keepalive_user_data(ud)
ud |
A 'wickra_user_data' object. |
Invisibly, 'ud'.
Historical candles for a market.
wkex_klines(ex, market, interval, limit)wkex_klines(ex, market, interval, limit)
ex |
A 'wickra_exchange' object. |
market |
Market symbol, e.g. "BTC/USDT". |
interval |
Candle interval, e.g. "1m". |
limit |
Maximum candles to return. |
A list of OHLCV lists ('open'/'high'/'low'/'close'/'volume'/'timestamp').
The venue identifier of an exchange.
wkex_name(ex)wkex_name(ex)
ex |
A 'wickra_exchange' object. |
The venue name ("paper", "replay", "binance", ...).
Open orders, optionally filtered to one market.
wkex_open_orders(ex, market = NULL)wkex_open_orders(ex, market = NULL)
ex |
A 'wickra_exchange' object. |
market |
Market symbol, or 'NULL' for all markets. |
A list of order lists.
Order-book depth snapshot for a market.
wkex_order_book(ex, market, depth)wkex_order_book(ex, market, depth)
ex |
A 'wickra_exchange' object. |
market |
Market symbol, e.g. "BTC/USDT". |
depth |
Maximum levels per side. |
A list with 'symbol' and 'bids'/'asks' lists of 'price, quantity'.
Open an offline paper account.
wkex_paper(balances, maker_bps = 0, taker_bps = 0, slippage_bps = 0)wkex_paper(balances, maker_bps = 0, taker_bps = 0, slippage_bps = 0)
balances |
Named numeric vector of starting balances (asset -> amount). |
maker_bps, taker_bps, slippage_bps
|
Costs in basis points. |
A 'wickra_exchange' object.
The orders are described by parallel vectors. 'prices' uses 'NA' for a market order and a finite value for a limit order.
wkex_place_batch(adv, markets, sides, quantities, prices)wkex_place_batch(adv, markets, sides, quantities, prices)
adv |
A 'wickra_advanced' object. |
markets |
Character vector of market symbols. |
sides |
Character or integer vector of sides ("buy"/"sell"). |
quantities |
Numeric vector of quantities. |
prices |
Numeric vector of prices (NA for a market order). |
A list of results, each 'list(order = , error = )': 'order' on success or 'error' (an integer status code) on a per-order rejection.
[wkex_place_batch()] can say only market, side, quantity and price, so a batched order from R could never be a stop-loss, an immediate-or-cancel or a post-only, however carefully the venue clients carried them. This takes the whole request, as parallel vectors: one element of each per order.
wkex_place_batch_full( adv, markets, sides, quantities, prices = NA_real_, stop_prices = NA_real_, times_in_force = "gtc", client_order_ids = NULL, reduce_onlys = FALSE, post_onlys = FALSE, stps = "none", quantity_texts = NA_character_, price_texts = NA_character_, stop_price_texts = NA_character_ )wkex_place_batch_full( adv, markets, sides, quantities, prices = NA_real_, stop_prices = NA_real_, times_in_force = "gtc", client_order_ids = NULL, reduce_onlys = FALSE, post_onlys = FALSE, stps = "none", quantity_texts = NA_character_, price_texts = NA_character_, stop_price_texts = NA_character_ )
adv |
A 'wickra_advanced' object. |
markets |
Character vector of market symbols. |
sides |
Character or integer vector of sides ("buy"/"sell"). |
quantities |
Numeric vector of quantities. |
prices |
Numeric vector of limit prices ('NA' for a market order). |
stop_prices |
Numeric vector of trigger prices ('NA' for none). |
times_in_force |
Character vector: "gtc", "ioc" or "fok". |
client_order_ids |
Character vector of ids, or 'NULL' for none. |
reduce_onlys |
Logical vector: close-only. |
post_onlys |
Logical vector: maker-only. |
stps |
Character vector: "none", "expire_maker", "expire_taker" or "expire_both". |
quantity_texts |
Character vector of exact quantities, or 'NA' per element to use the numeric beside it. R's numeric is a double and holds about fifteen significant digits; a string reaches the venue as written. |
price_texts |
Character vector of exact limit prices, or 'NA'. |
stop_price_texts |
Character vector of exact trigger prices, or 'NA'. |
Scalars are recycled to the number of markets, so the common case of "same time-in-force for every leg" needs one value rather than a repeated vector.
A list of results, each 'list(order = , error = )': 'order' on success or 'error' (an integer status code) on a per-order rejection.
Place a limit order.
wkex_place_limit(ex, market, side, quantity, price)wkex_place_limit(ex, market, side, quantity, price)
ex |
A 'wickra_exchange' object. |
market |
Market string. |
side |
"buy" or "sell". |
quantity |
Order quantity. |
price |
Limit price. |
The resulting order as a list.
Place a market order.
wkex_place_market(ex, market, side, quantity)wkex_place_market(ex, market, side, quantity)
ex |
A 'wickra_exchange' object. |
market |
Market string. |
side |
"buy" or "sell". |
quantity |
Order quantity. |
The resulting order as a list.
A take-profit limit leg at 'price' paired with a stop leg triggered at 'stop_price'. A finite 'stop_limit_price' makes the stop leg a stop-limit; 'NA' leaves it a stop-market.
wkex_place_oco( adv, market, side, quantity, price, stop_price, stop_limit_price = NA_real_ )wkex_place_oco( adv, market, side, quantity, price, stop_price, stop_limit_price = NA_real_ )
adv |
A 'wickra_advanced' object. |
market |
Market symbol. |
side |
"buy" or "sell". |
quantity |
Order quantity. |
price |
Take-profit limit price. |
stop_price |
Stop trigger price. |
stop_limit_price |
Stop-leg limit price, or NA for a stop-market. |
A list of the resulting order legs.
'wkex_place_market()' and 'wkex_place_limit()' take a market, a side, a quantity and a price, which is all an order could ever be from R. This is the call that can also carry the trigger price that makes a stop-loss a stop-loss, the time-in-force that says an order must not rest, post-only, reduce-only, self-trade prevention, and the client order id that makes a retried placement idempotent.
wkex_place_order( ex, market, side, quantity, price = NA_real_, stop_price = NA_real_, time_in_force = "gtc", client_order_id = NULL, reduce_only = FALSE, post_only = FALSE, stp = "none", quantity_text = NA_character_, price_text = NA_character_, stop_price_text = NA_character_ )wkex_place_order( ex, market, side, quantity, price = NA_real_, stop_price = NA_real_, time_in_force = "gtc", client_order_id = NULL, reduce_only = FALSE, post_only = FALSE, stp = "none", quantity_text = NA_character_, price_text = NA_character_, stop_price_text = NA_character_ )
ex |
A 'wickra_exchange' object. |
market |
Market string. |
side |
"buy" or "sell". |
quantity |
Order quantity. |
price |
Limit price, or 'NA' for a market order. |
stop_price |
Trigger price, or 'NA' for a non-trigger order. |
time_in_force |
"gtc" (the default), "ioc" or "fok". |
client_order_id |
An id of your choosing, or 'NULL'. |
reduce_only |
Close-only: the order may not increase a position. |
post_only |
Maker-only: cancelled rather than crossing the spread. |
stp |
"none" (the default), "expire_maker", "expire_taker" or "expire_both". |
quantity_text |
Exact quantity as a string, or 'NA' to use 'quantity'. R's numeric is a double and holds about fifteen significant digits, where this library holds every order number in an exact decimal. Written as a number, '12345678.90123456789' becomes '12345678.90123457' – a different order, placed without a word. A string reaches the venue as written. |
price_text |
Exact limit price as a string, or 'NA' to use 'price'. |
stop_price_text |
Exact trigger price as a string, or 'NA' to use 'stop_price'. |
The order type is derived rather than named: a 'price' makes it a limit order, a 'stop_price' promotes it into its trigger form.
A field the venue cannot express refuses the order rather than weakening it, which surfaces here as an error rather than as a differently-shaped order reaching the exchange.
The resulting order as a list.
Drain buffered events.
wkex_poll(ex, capacity = 16L)wkex_poll(ex, capacity = 16L)
ex |
A 'wickra_exchange' object. |
capacity |
Maximum events to return per call. |
A list of event lists.
The open position in a market.
wkex_position(deriv, market)wkex_position(deriv, market)
deriv |
A 'wickra_derivatives' object. |
market |
Market symbol, e.g. "BTC/USDT". |
A position list (errors if flat).
Pass a 'market' to scope to one symbol, or 'NULL' for all.
wkex_positions(deriv, market = NULL)wkex_positions(deriv, market = NULL)
deriv |
A 'wickra_derivatives' object. |
market |
Optional market symbol, or NULL for all positions. |
A list of position lists.
Look up a single order by venue id.
wkex_query_order(ex, market, order_id)wkex_query_order(ex, market, order_id)
ex |
A 'wickra_exchange' object. |
market |
Market symbol, e.g. "BTC/USDT". |
order_id |
Venue order id. |
The order as a list.
Open a replay account driven by a recorded tape of trades.
wkex_replay_trades( market, tape, balances, maker_bps = 0, taker_bps = 0, slippage_bps = 0 )wkex_replay_trades( market, tape, balances, maker_bps = 0, taker_bps = 0, slippage_bps = 0 )
market |
Market string, e.g. "BTC/USDT". |
tape |
Numeric vector of trade prices. |
balances |
Named numeric vector of starting balances. |
maker_bps, taker_bps, slippage_bps
|
Costs in basis points. |
A 'wickra_exchange' object.
Set the leverage for a market.
wkex_set_leverage(deriv, market, leverage)wkex_set_leverage(deriv, market, leverage)
deriv |
A 'wickra_derivatives' object. |
market |
Market symbol. |
leverage |
Integer leverage. |
Set the margin mode ("cross" or "isolated") for a market.
wkex_set_margin_mode(deriv, market, mode)wkex_set_margin_mode(deriv, market, mode)
deriv |
A 'wickra_derivatives' object. |
market |
Market symbol. |
mode |
"cross" or "isolated". |
Set the mark price a paper account fills against (paper backend only).
wkex_set_price(ex, market, price)wkex_set_price(ex, market, price)
ex |
A 'wickra_exchange' object. |
market |
Market string. |
price |
Mark price. |
Invisibly, 'ex'.
Subscribe to the order-book stream for a market.
wkex_subscribe_book(ex, market)wkex_subscribe_book(ex, market)
ex |
A 'wickra_exchange' object. |
market |
Market symbol, e.g. "BTC/USDT". |
Invisibly, 'ex'.
Subscribe to the ticker stream for a market.
wkex_subscribe_ticker(ex, market)wkex_subscribe_ticker(ex, market)
ex |
A 'wickra_exchange' object. |
market |
Market symbol, e.g. "BTC/USDT". |
Invisibly, 'ex'.
Subscribe to the public trade stream for a market.
wkex_subscribe_trades(ex, market)wkex_subscribe_trades(ex, market)
ex |
A 'wickra_exchange' object. |
market |
Market symbol, e.g. "BTC/USDT". |
Invisibly, 'ex'.
Open the private user-data stream.
wkex_subscribe_user_data(ud)wkex_subscribe_user_data(ud)
ud |
A 'wickra_user_data' object. |
Invisibly, 'ud'.
The current ticker for a market.
wkex_ticker(ex, market)wkex_ticker(ex, market)
ex |
A 'wickra_exchange' object. |
market |
Market symbol, e.g. "BTC/USDT". |
A list with 'symbol', 'last', 'bid', 'ask', 'volume'.
After [wkex_subscribe_user_data()], [wkex_user_data_poll()] surfaces the account's own order and balance updates. Fails for a spot-only venue.
wkex_user_data( name, api_key, api_secret, passphrase = NULL, private_key = NULL, testnet = FALSE, futures = FALSE )wkex_user_data( name, api_key, api_secret, passphrase = NULL, private_key = NULL, testnet = FALSE, futures = FALSE )
name, api_key, api_secret
|
Venue and API credentials. |
passphrase, private_key
|
Optional extra credentials (NULL if unused). |
testnet |
Use the venue testnet. |
futures |
Select the USD-M futures market. |
A 'wickra_user_data' object.
Drain buffered user-data events.
wkex_user_data_poll(ud, capacity = 16L)wkex_user_data_poll(ud, capacity = 16L)
ud |
A 'wickra_user_data' object. |
capacity |
Maximum events to return per call. |
A list of event lists.
The wickra-exchange library version.
wkex_version()wkex_version()
A version string.
Cancel an order over the WebSocket order API by venue id.
wkex_ws_cancel_order(wse, market, order_id)wkex_ws_cancel_order(wse, market, order_id)
wse |
A 'wickra_ws_execution' object. |
market |
Market string. |
order_id |
The venue order id. |
Invisibly, 'wse'.
Native on binance/bybit/okx/gateio/kraken; on bitget/kucoin/htx the methods error (no WebSocket order-entry API). Fails for a spot-only venue.
wkex_ws_execution( name, api_key, api_secret, passphrase = NULL, private_key = NULL, testnet = FALSE, futures = FALSE )wkex_ws_execution( name, api_key, api_secret, passphrase = NULL, private_key = NULL, testnet = FALSE, futures = FALSE )
name, api_key, api_secret
|
Venue and API credentials. |
passphrase, private_key
|
Optional extra credentials (NULL if unused). |
testnet |
Use the venue testnet. |
futures |
Select the USD-M futures market. |
A 'wickra_ws_execution' object.
Place an order over the WebSocket order API.
wkex_ws_place_order(wse, market, side, quantity, price = NA_real_)wkex_ws_place_order(wse, market, side, quantity, price = NA_real_)
wse |
A 'wickra_ws_execution' object. |
market |
Market string. |
side |
"buy" or "sell". |
quantity |
Order quantity. |
price |
Limit price, or NA for a market order. |
The resulting order as a list.
The [wkex_place_order()] form of [wkex_ws_place_order()], for the same reason the REST path has one: the narrow call cannot carry a trigger price, a time-in-force, or any of the flags that decide what the order actually is.
wkex_ws_place_order_full( wse, market, side, quantity, price = NA_real_, stop_price = NA_real_, time_in_force = "gtc", client_order_id = NULL, reduce_only = FALSE, post_only = FALSE, stp = "none", quantity_text = NA_character_, price_text = NA_character_, stop_price_text = NA_character_ )wkex_ws_place_order_full( wse, market, side, quantity, price = NA_real_, stop_price = NA_real_, time_in_force = "gtc", client_order_id = NULL, reduce_only = FALSE, post_only = FALSE, stp = "none", quantity_text = NA_character_, price_text = NA_character_, stop_price_text = NA_character_ )
wse |
A 'wickra_ws_execution' object. |
market |
Market string. |
side |
"buy" or "sell". |
quantity |
Order quantity. |
price |
Limit price, or 'NA' for a market order. |
stop_price |
Trigger price, or 'NA' for a non-trigger order. |
time_in_force |
"gtc" (the default), "ioc" or "fok". |
client_order_id |
An id of your choosing, or 'NULL'. |
reduce_only |
Close-only: the order may not increase a position. |
post_only |
Maker-only: cancelled rather than crossing the spread. |
stp |
"none" (the default), "expire_maker", "expire_taker" or "expire_both". |
quantity_text |
Exact quantity as a string, or 'NA' to use 'quantity'. R's numeric is a double and holds about fifteen significant digits, where this library holds every order number in an exact decimal. Written as a number, '12345678.90123456789' becomes '12345678.90123457' – a different order, placed without a word. A string reaches the venue as written. |
price_text |
Exact limit price as a string, or 'NA' to use 'price'. |
stop_price_text |
Exact trigger price as a string, or 'NA' to use 'stop_price'. |
The resulting order as a list.