Skip to content
All library documents

Managing OKEx Futures Positions with Adaptive Limit Orders

Article Strategy library · Author: FawkesPan

Summary

This Python position-management utility wraps exchange operations for futures trading. It initializes a symbol and contract, rounds prices to the configured tick size, reads order-book depth, and selects quote prices using rules based on the bid-ask spread. It provides helpers to check positions and order status, and exposes methods to open or close long and short positions.

Orders run in background threads. The manager tracks order identifiers with locks, waits for completion, and can cancel and reprice resting orders when they are no longer near the best quote. It logs sent and canceled orders and supports a match-price option. The source is implementation material rather than a tested trading strategy: it supplies no entry signal, sizing model, backtest results, or risk analysis. Its behavior depends on the exchange API and the framework's data formats; the code's retries, locking, and fill checks would need careful review before use, particularly around partial fills, cancellations, and concurrent state changes.

Key ideas

  • The manager adapts quote prices to the observed bid-ask spread and rounds them to the instrument's tick size.
  • It exposes methods for opening and closing long and short futures positions.
  • Background threads, locks, and order tracking support waiting for fills and coordinating cancellation.
  • Resting orders may be canceled and repriced when they are no longer near the best quote.
  • The source is order-management infrastructure and provides no trading signal, sizing method, or performance evidence.

Tags

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