Read the SWAP Definition
An OKX Spot order for 0.01 BTC and a perpetual order whose sz is 0.01 do not necessarily describe the same amount. For derivatives, the instrument's contract definition determines the meaning of size.
The connector also needs the account's position mode. An order direction does not identify a long or short position slot by itself.
The OKX SDK tutorial covers setup. This public request reads one perpetual instrument:
okx-swap-instrument.mjs
import { RestClient } from 'okx-api';
const client = new RestClient();
const response = await client.getInstruments({
instType: 'SWAP',
instId: 'BTC-USDT-SWAP',
});
console.log(response);
The OKX instrument reference defines fields including ctVal, ctValCcy, lotSz, and minSz. Interpret them together rather than assuming every contract value is denominated in BTC. Keep decimal values exact while applying the permitted increments.
Match Account and Order Settings
tdMode selects the order's supported margin arrangement. posSide identifies the applicable position side. Their valid combinations depend on the account and position configuration; a copied cash Spot request is not a perpetual request.
Read the account configuration and relevant positions before dispatch. A mismatch should block the affected workflow. Automatically calling a position-mode setter at startup can alter the account used by another process.
A request record should retain the instrument ID, contract quantity, direction, margin arrangement, position side, and client order ID. These fields let recovery distinguish an intended reduction from a command that would open exposure in another slot.
Follow the Order After Acceptance
The REST client and supported WebSocket command client can return acknowledgements. The application must inspect business results, including per-order result fields where provided. An accepted command does not establish a fill or synchronize the local position cache.
Private order updates can report partial execution and terminal status. Retain cumulative progress without adding it twice. A cancellation can race another fill, so the final remaining quantity must come from the established order facts.
After a lost reply, query by the recorded identifiers and retain uncertainty until the outcome can be established. The shared order-state workflow explains that recovery. The OKX connector owns the instrument conversion and account-specific request fields.
Related articles
Continue from here