okx-order-support-plan.json 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. {
  2. "report": "okx-order-support-plan",
  3. "scope": "static implementation plan only; no OKX request, no order, no cancel",
  4. "readiness_gap": "ETH-focused quasi-live portfolio needs a full order lifecycle before any submit-capable runner is valid.",
  5. "source_files_checked": [
  6. {
  7. "path": "okx_codex_trader/okx_client.py",
  8. "facts": [
  9. "Signed _request already supports GET/POST with params/json_body.",
  10. "place_order is a single-order submitter.",
  11. "place_order emits ordType=market or ordType=limit only.",
  12. "No batch-orders, orders-pending, cancel-order, order status, or fills method exists.",
  13. "get_positions reads exchange positions but is not tied to portfolio-owned state."
  14. ]
  15. },
  16. {
  17. "path": "tests/test_okx_client.py",
  18. "facts": [
  19. "DummySession records request path/body and can support endpoint-level client tests.",
  20. "Existing tests cover request signing, live/demo header, contract sizing, leverage validation, single order payload, and position parsing.",
  21. "No tests cover post_only payloads, batch payloads, order list/cancel/status/fills, or state persistence."
  22. ]
  23. },
  24. {
  25. "path": "okx_codex_trader/cli.py",
  26. "facts": [
  27. "okx-account is read-only and returns balance plus positions.",
  28. "okx-order is submit-capable and calls place_order.",
  29. "No read-only ETH order-intent/state command exists.",
  30. "No quasi-live state path or append-only lifecycle log is wired."
  31. ]
  32. }
  33. ],
  34. "official_okx_api_surface": [
  35. {
  36. "capability": "single post-only limit order payload",
  37. "endpoint": "POST /api/v5/trade/order",
  38. "boundary": "submit-capable only after read-only payload rendering is tested",
  39. "required_fields": [
  40. "instId",
  41. "tdMode",
  42. "side",
  43. "posSide",
  44. "ordType",
  45. "px",
  46. "sz",
  47. "clOrdId"
  48. ],
  49. "fixed_eth_values": {
  50. "instId": "ETH-USDT-SWAP",
  51. "tdMode": "isolated",
  52. "side": "buy",
  53. "posSide": "long",
  54. "ordType": "post_only"
  55. }
  56. },
  57. {
  58. "capability": "batch entry orders",
  59. "endpoint": "POST /api/v5/trade/batch-orders",
  60. "boundary": "submit-capable; read-only stage renders the exact array only",
  61. "required_shape": "list of three post_only entry payloads with deterministic clOrdId values"
  62. },
  63. {
  64. "capability": "list open orders",
  65. "endpoint": "GET /api/v5/trade/orders-pending",
  66. "boundary": "read-only",
  67. "minimum_params": {
  68. "instType": "SWAP",
  69. "instId": "ETH-USDT-SWAP"
  70. }
  71. },
  72. {
  73. "capability": "cancel open order",
  74. "endpoint": "POST /api/v5/trade/cancel-order",
  75. "boundary": "submit-capable; read-only stage renders cancel intents only",
  76. "required_fields": [
  77. "instId",
  78. "ordId or clOrdId"
  79. ]
  80. },
  81. {
  82. "capability": "cancel open orders in batch",
  83. "endpoint": "POST /api/v5/trade/cancel-batch-orders",
  84. "boundary": "submit-capable; read-only stage renders cancel intent array only",
  85. "required_shape": "list of tracked open order ids for ETH strategy-owned orders"
  86. },
  87. {
  88. "capability": "order status",
  89. "endpoint": "GET /api/v5/trade/order",
  90. "boundary": "read-only",
  91. "minimum_params": {
  92. "instId": "ETH-USDT-SWAP",
  93. "ordId_or_clOrdId": "tracked order identity"
  94. }
  95. },
  96. {
  97. "capability": "recent fills",
  98. "endpoint": "GET /api/v5/trade/fills",
  99. "boundary": "read-only",
  100. "minimum_params": {
  101. "instType": "SWAP",
  102. "instId": "ETH-USDT-SWAP"
  103. }
  104. }
  105. ],
  106. "state_persistence": {
  107. "boundary": "local read/write only; not an OKX API call",
  108. "minimum_file": "state/eth_robust_twap_15m_live.json",
  109. "fields": [
  110. "strategy_id",
  111. "symbol",
  112. "bar",
  113. "td_mode",
  114. "pos_side",
  115. "leverage",
  116. "last_confirmed_candle_ts",
  117. "last_signal_candle_ts",
  118. "orders",
  119. "fills",
  120. "position",
  121. "planned_margin_usdt",
  122. "max_margin_usdt",
  123. "updated_at"
  124. ],
  125. "event_log": "append-only JSONL for signal, order-intent, cancel-intent, order-status, fills, and state-transition events"
  126. },
  127. "minimum_patch_plan_by_file": [
  128. {
  129. "file": "okx_codex_trader/okx_client.py",
  130. "patch_plan": [
  131. "Add small dataclasses or typed dicts only if needed by return values: OkxOrder, OkxFill, OkxOrderAck.",
  132. "Add render_post_only_limit_order_payload(...) as a non-submitting function using existing _format_number and build_contract_size.",
  133. "Add render_eth_entry_batch_payloads(...) that returns exactly three post_only payloads for offsets 0.003, 0.006, 0.009.",
  134. "Add list_open_orders(symbol) calling GET /api/v5/trade/orders-pending with instType=SWAP and instId=symbol.",
  135. "Add get_order(symbol, ord_id=None, client_order_id=None) calling GET /api/v5/trade/order.",
  136. "Add list_fills(symbol) calling GET /api/v5/trade/fills with instType=SWAP and instId=symbol.",
  137. "Add cancel_order(symbol, ord_id=None, client_order_id=None) and cancel_batch_orders(symbol, order_ids) only when moving past read-only intent.",
  138. "Do not change existing place_order semantics for the first patch; it is not suitable for the ETH portfolio lifecycle."
  139. ]
  140. },
  141. {
  142. "file": "okx_codex_trader/cli.py",
  143. "patch_plan": [
  144. "Add read-only eth-robust-twap-order-intent command that prints signal, three entry payloads, expiry, and state transition preview.",
  145. "Add read-only eth-robust-twap-open-orders command that lists current OKX pending orders for ETH-USDT-SWAP.",
  146. "Add read-only eth-robust-twap-reconcile command that reads state, queries open orders/status/fills, and writes a new local state snapshot plus JSONL audit event.",
  147. "Keep okx-order unchanged and do not route portfolio intents through it.",
  148. "Only after read-only commands pass tests, add explicit submit commands for batch entry and cancellation."
  149. ]
  150. },
  151. {
  152. "file": "tests/test_okx_client.py",
  153. "patch_plan": [
  154. "Add tests for post_only payload shape: ETH-USDT-SWAP, isolated, buy, long, post_only, px, sz, deterministic clOrdId.",
  155. "Add tests for batch payload shape: exactly three orders, offsets 0.003/0.006/0.009, each level sized independently and rounded to lotSz.",
  156. "Add tests for GET /api/v5/trade/orders-pending params and normalized open-order state values.",
  157. "Add tests for POST /api/v5/trade/cancel-order and /cancel-batch-orders request bodies before enabling submit commands.",
  158. "Add tests for GET /api/v5/trade/order by ordId and by clOrdId.",
  159. "Add tests for GET /api/v5/trade/fills parsing fillSz, fillPx, tradeId, ordId, clOrdId, fee, and fillTime.",
  160. "Add tests that malformed OKX lifecycle payloads raise the existing stable invalid-payload error."
  161. ]
  162. },
  163. {
  164. "file": "new okx_codex_trader/eth_robust_twap_state.py",
  165. "patch_plan": [
  166. "Add only the dedicated state schema and load/save functions needed by the ETH quasi-live lifecycle.",
  167. "Persist exchange order ids, client order ids, fills, position, last confirmed candle, active state, and audit cursor.",
  168. "Reject state whose symbol/bar/strategy_id does not match the command arguments."
  169. ]
  170. },
  171. {
  172. "file": "new tests/test_eth_robust_twap_state.py",
  173. "patch_plan": [
  174. "Add load empty state test.",
  175. "Add save/read roundtrip for one signal with three open orders and one partial fill.",
  176. "Add state mismatch rejection tests for symbol, bar, and strategy_id."
  177. ]
  178. }
  179. ],
  180. "readonly_boundary": [
  181. "Render post_only single and batch order payloads without calling POST /api/v5/trade/order or /batch-orders.",
  182. "Read account balance, positions, pending orders, order details, and fills.",
  183. "Write local state snapshots and append-only JSONL audit events.",
  184. "Render cancel intents without calling cancel endpoints."
  185. ],
  186. "submit_capable_boundary": [
  187. "POST /api/v5/trade/order with ordType=post_only.",
  188. "POST /api/v5/trade/batch-orders.",
  189. "POST /api/v5/trade/cancel-order.",
  190. "POST /api/v5/trade/cancel-batch-orders.",
  191. "Any reduce-only market close path."
  192. ],
  193. "test_checklist": [
  194. "Existing tests: rtk .venv/bin/pytest tests/test_okx_client.py",
  195. "New client tests for render-only post_only payloads make no DummySession requests.",
  196. "New client tests for list_open_orders/get_order/list_fills assert method/path/params and parsed output.",
  197. "New cancel tests assert request body shape but stay behind commands that are not wired in the read-only phase.",
  198. "New CLI tests assert read-only order-intent/reconcile commands do not call submit/cancel endpoints.",
  199. "New state tests assert deterministic state roundtrip and event append order."
  200. ],
  201. "sources": [
  202. "https://www.okx.com/docs-v5/en/",
  203. "reports/eth-exploration/eth-focused-portfolio-live-readiness.md",
  204. "reports/eth-exploration/eth-robust-twap-live-plan.md"
  205. ]
  206. }