MyNixOS website logo
Description

R Interface to the 'OKX' REST API.

Provides lightweight R wrappers for the 'OKX' REST API, covering endpoints for market data, trading, account management, asset balances, and copy trading. The upstream API reference is available at <https://www.okx.com/docs-v5/en/>.

okxr: R Interface to the OKX API

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.

Status

okxr is available on CRAN. Install the stable release from CRAN or use the GitHub repository for development versions between CRAN releases.

Current development release: v0.4.5

Installation

Stable CRAN release:

install.packages("okxr")

Development release from GitHub:

# install.packages("devtools")
devtools::install_github("OliverLDS/okxr")

Features

  • Signed OKX REST requests with HMAC authentication
  • Typed parsing into tabular R objects with variable labels
  • Shared internal GET/POST generators backed by endpoint specs
  • User-facing wrappers for account, asset, market, trade, and copy-trading APIs
  • Configurable raw vs parsed return mode via set_okxr_options()

Setup

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
)

Return values

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.

Examples

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.

Market data

get_market_candles(
  inst_id = "BTC-USDT",
  bar = "1m",
  limit = 100
)

Account data

get_account_balance(config = config)
get_account_positions(config = config)

Place an order

post_trade_order(
  inst_id = "BTC-USDT",
  td_mode = "cross",
  side = "buy",
  ord_type = "market",
  sz = "0.01",
  config = config
)

Copy trading

get_copy_trade_my_leaders(config = config)
get_copy_trade_current_subpos(config = config)

Wrapper categories

CategoryMethodExample function
marketGETget_market_candles()
marketGETget_market_tickers()
marketGETget_market_trades()
marketGETget_market_mark_price_candles()
marketGETget_market_index_tickers()
marketGETget_market_index_candles()
marketGETget_market_index_components()
publicGETget_public_time()
publicGETget_public_underlying()
publicGETget_public_estimated_price()
publicGETget_public_estimated_settlement_info()
publicGETget_public_opt_summary()
publicGETget_public_position_tiers()
publicGETget_public_discount_rate_interest_free_quota()
publicGETget_public_interest_rate_loan_quota()
publicGETget_public_insurance_fund()
publicGETget_public_block_trades()
publicGETget_public_convert_contract_coin()
publicGETget_public_instrument_tick_bands()
publicGETget_public_premium_history()
publicGETget_public_option_trades()
accountGETget_account_balance()
accountGETget_account_instruments()
accountGETget_account_subtypes()
accountGETget_account_adjust_leverage_info()
accountGETget_account_position_risk()
accountGETget_account_max_loan()
accountGETget_account_max_size()
accountGETget_account_max_avail_size()
accountGETget_account_trade_fee()
accountGETget_account_interest_rate()
accountGETget_account_interest_accrued()
accountGETget_account_max_withdrawal()
accountGETget_account_risk_state()
accountGETget_account_interest_limits()
accountGETget_account_greeks()
accountGETget_account_position_tiers()
accountGETget_account_collateral_assets()
accountGETget_account_mmp_config()
accountGETget_account_move_positions_history()
accountGETget_account_precheck_set_delta_neutral()
accountGETget_account_bills_history_archive()
accountGETget_account_subaccount_balances()
accountGETget_account_subaccount_max_withdrawal()
accountGETget_account_set_account_switch_precheck()
accountGETget_account_spot_borrow_repay_history()
accountGETget_account_bills()
accountPOSTpost_account_set_leverage()
accountPOSTpost_account_set_position_mode()
accountPOSTpost_account_set_fee_type()
accountPOSTpost_account_set_greeks()
accountPOSTpost_account_set_auto_repay()
accountPOSTpost_account_set_auto_loan()
accountPOSTpost_account_set_account_level()
accountPOSTpost_account_set_collateral_assets()
accountPOSTpost_account_position_margin_balance()
accountPOSTpost_account_spot_manual_borrow_repay()
accountPOSTpost_account_account_level_switch_preset()
accountPOSTpost_account_mmp_reset()
accountPOSTpost_account_mmp_config()
accountPOSTpost_account_move_positions()
assetGETget_asset_balances()
assetGETget_asset_deposit_history()
assetGETget_asset_withdrawal_history()
assetGETget_asset_currencies()
assetGETget_asset_non_tradable_assets()
assetGETget_asset_asset_valuation()
assetGETget_asset_bills()
assetGETget_asset_transfer_state()
assetGETget_asset_convert_history()
assetPOSTpost_asset_transfer()
assetPOSTpost_asset_withdrawal()
assetPOSTpost_asset_cancel_withdrawal()
assetPOSTpost_asset_convert_estimate_quote()
assetPOSTpost_asset_convert_trade()
tradeGETget_trade_order()
tradeGETget_trade_orders_history()
tradeGETget_trade_orders_algo_pending()
tradeGETget_trade_easy_convert_history()
tradeGETget_trade_one_click_repay_history_v2()
tradeGETget_trade_account_rate_limit()
tradeGETget_trade_fills()
tradePOSTpost_trade_order()
tradePOSTpost_trade_cancel_order()
tradePOSTpost_trade_batch_orders()
tradePOSTpost_trade_cancel_batch_orders()
tradePOSTpost_trade_amend_order()
tradePOSTpost_trade_amend_batch_orders()
tradePOSTpost_trade_order_precheck()
tradePOSTpost_trade_cancel_all_after()
tradePOSTpost_trade_cancel_algos()
tradePOSTpost_trade_amend_algos()
tradePOSTpost_trade_mass_cancel()
copy tradingGETget_copy_trade_my_leaders()
copy tradingGETget_copy_trade_settings()
copy tradingGETget_copy_trade_current_subpos()
copy tradingGETget_copy_trade_historical_subpos()
copy tradingGETget_copy_trade_instruments()
copy tradingGETget_copy_trade_public_config()
copy tradingGETget_copy_trade_public_lead_traders()
copy tradingGETget_copy_trade_public_copy_traders()
copy tradingGETget_copy_trade_public_preference_currency()
copy tradingGETget_copy_trade_public_current_subpositions()
copy tradingGETget_copy_trade_public_subpositions_history()
copy tradingGETget_copy_trade_public_pnl()
copy tradingGETget_copy_trade_public_stats()
copy tradingGETget_copy_trade_public_weekly_pnl()
copy tradingGETget_copy_trade_profit_sharing_details()
copy tradingGETget_copy_trade_total_profit_sharing()

Release notes

See NEWS.md for release history.

Development status

  • [x] GET support for major endpoints
  • [x] POST support for order, cancel, leverage, close position
  • [x] Copy trading wrappers
  • [x] Package metadata and generated documentation aligned for GitHub release
  • [x] Automated test suite foundation
  • [x] GitHub Actions package check workflow
  • [x] CRAN-safe package examples and package-level help
  • [x] Unsigned public endpoints and request timeout handling
  • [x] CRAN policy hygiene files and release metadata cleanup
  • [x] Mocked request/parser robustness tests
  • [x] CRAN release-candidate documentation alignment
  • [x] Manual CRAN preflight workflow for release checks
  • [x] CRAN submission checklist for final manual steps
  • [x] Final CRAN submission metadata update
  • [x] CRAN reviewer-requested DESCRIPTION and Rd fixes
  • [x] First CRAN release published
  • [x] First post-CRAN endpoint expansion batch
  • [x] Expanded public reference and index market coverage
  • [x] Broader account inspection and sub-account GET coverage for v0.3.2
  • [x] Broader trade history, algo-order, asset billing, and convert GET coverage for v0.3.3
  • [x] Broader copy-trading coverage plus expanded asset history filter support for v0.3.4
  • [x] Remaining copy-trading GET endpoints and copy-trading parameter completeness fixes for v0.3.5
  • [x] First trade action expansion batch for v0.4.0
  • [x] Advanced trade algo and mass-cancel action coverage for v0.4.1
  • [x] Account configuration action coverage for v0.4.2
  • [x] Account operational action coverage for v0.4.3
  • [x] Asset transfer, withdrawal, and convert action coverage for v0.4.4
  • [x] POST wrapper validation and cancellation parameter completeness for v0.4.5
  • [ ] Websocket support

License

MIT

Author

Oliver Zhou Lily Li.

Metadata

Version

0.4.5

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows