nexustrader.exchange.okx.rest_api

This module implements the REST API client for OKX exchange, providing methods to interact with various OKX API endpoints.

Class Overview

API Methods

Account Endpoints

nexustrader.exchange.okx.rest_api.get_api_v5_account_balance(ccy: str | None = None)

Get account balance information.

Parameters:

ccy – Currency code (optional)

Returns:

Account balance response

nexustrader.exchange.okx.rest_api.get_api_v5_account_positions(inst_type: str | None = None, inst_id: str | None = None, pos_id: str | None = None)

Get position information.

Parameters:
  • inst_type – Instrument type

  • inst_id – Instrument ID

  • pos_id – Position ID

Returns:

Position response

Trading Endpoints

nexustrader.exchange.okx.rest_api.post_api_v5_trade_order(inst_id: str, td_mode: str, side: str, ord_type: str, sz: str, **kwargs)

Place a new order.

Parameters:
  • inst_id – Instrument ID

  • td_mode – Trading mode

  • side – Order side

  • ord_type – Order type

  • sz – Order size

Returns:

Order placement response

nexustrader.exchange.okx.rest_api.post_api_v5_trade_cancel_order(inst_id: str, ord_id: str | None = None, cl_ord_id: str | None = None)

Cancel an existing order.

Parameters:
  • inst_id – Instrument ID

  • ord_id – Order ID

  • cl_ord_id – Client order ID

Returns:

Order cancellation response

Authentication

The client supports both API key and signature-based authentication:

  • API Key authentication

  • Timestamp-based signatures

  • Optional testnet support

  • Passphrase requirement