Skip to content
All library documents

Placing OKX V5 Conditional and OCO Futures Exit Orders

Article Strategy library · Author: 夏天不打你

Summary

This code example shows how to submit stop-loss, take-profit, and combined one-cancels-the-other orders through the OKX V5 algorithmic-order endpoint. It provides separate helpers for long and short positions, setting the closing side and position side accordingly, and builds swap instrument identifiers from symbols ending in USDT. The examples use cross margin mode and market execution for triggered orders by setting the order price to -1.

The document is an API usage snippet rather than a trading strategy: it gives no entry logic, market analysis, backtest, or outcome evidence. The helper functions log the exchange response but return success unconditionally, so callers cannot rely on that return value to confirm order acceptance. The example also hard-codes a sample call for an ETH-USDT swap. Users applying the pattern would need to handle API errors and verify instrument formatting, account mode, order parameters, and exchange behavior in their own integration.

Key ideas

  • The example submits conditional stop or target orders through the OKX V5 algorithmic-order endpoint.
  • It provides separate order-building functions for closing long and short swap positions.
  • Combined take-profit and stop-loss orders use an OCO order type.
  • Triggered orders specify a price of -1 to request market execution in the example.
  • The functions log responses but return true without checking whether the exchange accepted the order.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.