okxr is an R package for working with the OKX REST API
from R. It provides typed wrappers for market data, account endpoints,
asset history, trading, and copy trading, with shared request signing
and schema-based response parsing.
okxr is a CRAN-targeted release candidate. It has not
been submitted to CRAN yet; until acceptance, install the development
release from GitHub.
Current release: v0.2.4
set_okxr_options()# Development release
# install.packages("devtools")
devtools::install_github("OliverLDS/okxr")After CRAN acceptance, installation will use:
install.packages("okxr")config <- list(
api_key = "your_api_key",
secret_key = "your_secret_key",
passphrase = "your_passphrase"
)Public market and public reference endpoints can be called without credentials. Private account, asset, trade, and copy-trading endpoints require signed OKX API credentials.
Do not store real credentials in committed R scripts, examples, or
tests. For interactive use, load them from environment variables or
another local secret store. If you use OKX simulated trading, set
demo = TRUE in config.
config <- list(
api_key = Sys.getenv("OKX_API_KEY"),
secret_key = Sys.getenv("OKX_SECRET_KEY"),
passphrase = Sys.getenv("OKX_PASSPHRASE"),
demo = TRUE,
timeout = 10
)By default, wrappers return parsed data.table objects
with typed columns and variable labels where schemas are defined. Use
set_okxr_options(raw_data = TRUE) to return the raw OKX
data payload instead.
Network failures, request timeouts, OKX error responses, or empty API
data payloads may return NULL with a warning.
Request timeout defaults to 10 seconds and can be set globally with
set_okxr_options(timeout = 15) or per request with
config$timeout.
Public market examples require network access but no OKX credentials. Private account, trading, asset, and copy-trading examples require valid OKX credentials; trading examples may have account side effects.
get_market_candles(
inst_id = "BTC-USDT",
bar = "1m",
limit = 100
)get_account_balance(config = config)
get_account_positions(config = config)post_trade_order(
inst_id = "BTC-USDT",
td_mode = "cross",
side = "buy",
ord_type = "market",
sz = "0.01",
config = config
)get_copy_trade_my_leaders(config = config)
get_copy_trade_current_subpos(config = config)| Category | Method | Example function |
|---|---|---|
| market | GET | get_market_candles() |
| market | GET | get_market_tickers() |
| market | GET | get_market_trades() |
| public | GET | get_public_time() |
| account | GET | get_account_balance() |
| account | GET | get_account_bills() |
| asset | GET | get_asset_balances() |
| asset | GET | get_asset_currencies() |
| trade | GET | get_trade_order() |
| trade | GET | get_trade_fills() |
| trade | POST | post_trade_order() |
| trade | POST | post_trade_cancel_order() |
| copy trading | GET | get_copy_trade_my_leaders() |
See NEWS.md for release history.
MIT
Oliver Zhou