desic-okx-agent 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/README.en.md +90 -10
  2. package/README.md +76 -10
  3. package/dist/account/private-websocket.js +4 -4
  4. package/dist/account/private-websocket.js.map +1 -1
  5. package/dist/account/service.d.ts +12 -1
  6. package/dist/account/service.js +18 -0
  7. package/dist/account/service.js.map +1 -1
  8. package/dist/bars/rate-limiter.d.ts +18 -0
  9. package/dist/bars/rate-limiter.js +84 -0
  10. package/dist/bars/rate-limiter.js.map +1 -0
  11. package/dist/bars/schema.d.ts +36 -0
  12. package/dist/bars/schema.js +134 -0
  13. package/dist/bars/schema.js.map +1 -0
  14. package/dist/bars/service.d.ts +60 -0
  15. package/dist/bars/service.js +120 -0
  16. package/dist/bars/service.js.map +1 -0
  17. package/dist/bars/store.d.ts +105 -0
  18. package/dist/bars/store.js +415 -0
  19. package/dist/bars/store.js.map +1 -0
  20. package/dist/bars/timeframe.d.ts +40 -0
  21. package/dist/bars/timeframe.js +146 -0
  22. package/dist/bars/timeframe.js.map +1 -0
  23. package/dist/bars/types.d.ts +68 -0
  24. package/dist/bars/types.js +13 -0
  25. package/dist/bars/types.js.map +1 -0
  26. package/dist/cli/data-render.d.ts +37 -0
  27. package/dist/cli/data-render.js +143 -0
  28. package/dist/cli/data-render.js.map +1 -0
  29. package/dist/cli/doctor.js +7 -3
  30. package/dist/cli/doctor.js.map +1 -1
  31. package/dist/cli/index.js +757 -26
  32. package/dist/cli/index.js.map +1 -1
  33. package/dist/cli/live-render.d.ts +24 -0
  34. package/dist/cli/live-render.js +85 -0
  35. package/dist/cli/live-render.js.map +1 -0
  36. package/dist/cli/range.d.ts +28 -0
  37. package/dist/cli/range.js +63 -0
  38. package/dist/cli/range.js.map +1 -0
  39. package/dist/cli/render.js +3 -0
  40. package/dist/cli/render.js.map +1 -1
  41. package/dist/cli/strategy-render.d.ts +36 -0
  42. package/dist/cli/strategy-render.js +391 -0
  43. package/dist/cli/strategy-render.js.map +1 -0
  44. package/dist/cli/width.d.ts +18 -0
  45. package/dist/cli/width.js +71 -0
  46. package/dist/cli/width.js.map +1 -0
  47. package/dist/config/loader.js +1 -1
  48. package/dist/config/schema.d.ts +7 -0
  49. package/dist/config/schema.js +24 -0
  50. package/dist/config/schema.js.map +1 -1
  51. package/dist/core/okx-client.d.ts +9 -1
  52. package/dist/core/okx-client.js +14 -5
  53. package/dist/core/okx-client.js.map +1 -1
  54. package/dist/i18n/locale.d.ts +24 -0
  55. package/dist/i18n/locale.js +65 -0
  56. package/dist/i18n/locale.js.map +1 -0
  57. package/dist/i18n/messages.d.ts +333 -0
  58. package/dist/i18n/messages.js +660 -0
  59. package/dist/i18n/messages.js.map +1 -0
  60. package/dist/live/account-snapshot.d.ts +30 -0
  61. package/dist/live/account-snapshot.js +130 -0
  62. package/dist/live/account-snapshot.js.map +1 -0
  63. package/dist/live/cutoff-queue.d.ts +42 -0
  64. package/dist/live/cutoff-queue.js +69 -0
  65. package/dist/live/cutoff-queue.js.map +1 -0
  66. package/dist/live/execution-key.d.ts +23 -0
  67. package/dist/live/execution-key.js +31 -0
  68. package/dist/live/execution-key.js.map +1 -0
  69. package/dist/live/failures.d.ts +37 -0
  70. package/dist/live/failures.js +57 -0
  71. package/dist/live/failures.js.map +1 -0
  72. package/dist/live/gates.d.ts +65 -0
  73. package/dist/live/gates.js +136 -0
  74. package/dist/live/gates.js.map +1 -0
  75. package/dist/live/loop.d.ts +56 -0
  76. package/dist/live/loop.js +197 -0
  77. package/dist/live/loop.js.map +1 -0
  78. package/dist/live/preconditions.d.ts +48 -0
  79. package/dist/live/preconditions.js +69 -0
  80. package/dist/live/preconditions.js.map +1 -0
  81. package/dist/live/reconcile.d.ts +46 -0
  82. package/dist/live/reconcile.js +104 -0
  83. package/dist/live/reconcile.js.map +1 -0
  84. package/dist/live/runner.d.ts +57 -0
  85. package/dist/live/runner.js +160 -0
  86. package/dist/live/runner.js.map +1 -0
  87. package/dist/live/schema.d.ts +18 -0
  88. package/dist/live/schema.js +91 -0
  89. package/dist/live/schema.js.map +1 -0
  90. package/dist/live/service.d.ts +144 -0
  91. package/dist/live/service.js +303 -0
  92. package/dist/live/service.js.map +1 -0
  93. package/dist/live/session.d.ts +85 -0
  94. package/dist/live/session.js +234 -0
  95. package/dist/live/session.js.map +1 -0
  96. package/dist/live/sizing.d.ts +62 -0
  97. package/dist/live/sizing.js +79 -0
  98. package/dist/live/sizing.js.map +1 -0
  99. package/dist/live/store.d.ts +123 -0
  100. package/dist/live/store.js +350 -0
  101. package/dist/live/store.js.map +1 -0
  102. package/dist/live/types.d.ts +82 -0
  103. package/dist/live/types.js +2 -0
  104. package/dist/live/types.js.map +1 -0
  105. package/dist/market/websocket.d.ts +16 -1
  106. package/dist/market/websocket.js +60 -5
  107. package/dist/market/websocket.js.map +1 -1
  108. package/dist/mcp/server.d.ts +1 -0
  109. package/dist/mcp/server.js +15 -1
  110. package/dist/mcp/server.js.map +1 -1
  111. package/dist/network/connectivity.d.ts +9 -1
  112. package/dist/network/connectivity.js +28 -1
  113. package/dist/network/connectivity.js.map +1 -1
  114. package/dist/report/chart-script.d.ts +12 -0
  115. package/dist/report/chart-script.js +146 -0
  116. package/dist/report/chart-script.js.map +1 -0
  117. package/dist/report/compare-html.d.ts +8 -0
  118. package/dist/report/compare-html.js +254 -0
  119. package/dist/report/compare-html.js.map +1 -0
  120. package/dist/report/compare-script.d.ts +12 -0
  121. package/dist/report/compare-script.js +109 -0
  122. package/dist/report/compare-script.js.map +1 -0
  123. package/dist/report/compare.d.ts +61 -0
  124. package/dist/report/compare.js +205 -0
  125. package/dist/report/compare.js.map +1 -0
  126. package/dist/report/fetch.d.ts +20 -0
  127. package/dist/report/fetch.js +56 -0
  128. package/dist/report/fetch.js.map +1 -0
  129. package/dist/report/html.d.ts +54 -0
  130. package/dist/report/html.js +641 -0
  131. package/dist/report/html.js.map +1 -0
  132. package/dist/report/open.d.ts +42 -0
  133. package/dist/report/open.js +114 -0
  134. package/dist/report/open.js.map +1 -0
  135. package/dist/runtime/server.d.ts +16 -1
  136. package/dist/runtime/server.js +112 -9
  137. package/dist/runtime/server.js.map +1 -1
  138. package/dist/setup/installer.d.ts +1 -0
  139. package/dist/setup/installer.js +8 -0
  140. package/dist/setup/installer.js.map +1 -1
  141. package/dist/setup/wizard.js +19 -22
  142. package/dist/setup/wizard.js.map +1 -1
  143. package/dist/strategy/constants.d.ts +23 -0
  144. package/dist/strategy/constants.js +24 -0
  145. package/dist/strategy/constants.js.map +1 -0
  146. package/dist/strategy/environment.d.ts +52 -0
  147. package/dist/strategy/environment.js +187 -0
  148. package/dist/strategy/environment.js.map +1 -0
  149. package/dist/strategy/instrument.d.ts +29 -0
  150. package/dist/strategy/instrument.js +39 -0
  151. package/dist/strategy/instrument.js.map +1 -0
  152. package/dist/strategy/optimize.d.ts +73 -0
  153. package/dist/strategy/optimize.js +113 -0
  154. package/dist/strategy/optimize.js.map +1 -0
  155. package/dist/strategy/parameter-space.d.ts +59 -0
  156. package/dist/strategy/parameter-space.js +221 -0
  157. package/dist/strategy/parameter-space.js.map +1 -0
  158. package/dist/strategy/python-bridge.d.ts +24 -0
  159. package/dist/strategy/python-bridge.js +114 -0
  160. package/dist/strategy/python-bridge.js.map +1 -0
  161. package/dist/strategy/schema.d.ts +9 -0
  162. package/dist/strategy/schema.js +91 -0
  163. package/dist/strategy/schema.js.map +1 -0
  164. package/dist/strategy/service.d.ts +138 -0
  165. package/dist/strategy/service.js +745 -0
  166. package/dist/strategy/service.js.map +1 -0
  167. package/dist/strategy/settings.d.ts +162 -0
  168. package/dist/strategy/settings.js +243 -0
  169. package/dist/strategy/settings.js.map +1 -0
  170. package/dist/strategy/store.d.ts +96 -0
  171. package/dist/strategy/store.js +367 -0
  172. package/dist/strategy/store.js.map +1 -0
  173. package/dist/strategy/templates.d.ts +11 -0
  174. package/dist/strategy/templates.js +134 -0
  175. package/dist/strategy/templates.js.map +1 -0
  176. package/dist/strategy/types.d.ts +111 -0
  177. package/dist/strategy/types.js +2 -0
  178. package/dist/strategy/types.js.map +1 -0
  179. package/dist/tools/catalog.d.ts +16 -0
  180. package/dist/tools/catalog.js +118 -17
  181. package/dist/tools/catalog.js.map +1 -1
  182. package/dist/trade/service.d.ts +12 -0
  183. package/dist/trade/service.js +24 -7
  184. package/dist/trade/service.js.map +1 -1
  185. package/dist/tui/app.d.ts +23 -0
  186. package/dist/tui/app.js +322 -0
  187. package/dist/tui/app.js.map +1 -0
  188. package/dist/tui/commands.d.ts +70 -0
  189. package/dist/tui/commands.js +313 -0
  190. package/dist/tui/commands.js.map +1 -0
  191. package/dist/tui/entries.d.ts +17 -0
  192. package/dist/tui/entries.js +24 -0
  193. package/dist/tui/entries.js.map +1 -0
  194. package/dist/tui/execute.d.ts +26 -0
  195. package/dist/tui/execute.js +664 -0
  196. package/dist/tui/execute.js.map +1 -0
  197. package/dist/tui/history.d.ts +17 -0
  198. package/dist/tui/history.js +48 -0
  199. package/dist/tui/history.js.map +1 -0
  200. package/dist/tui/index.d.ts +8 -0
  201. package/dist/tui/index.js +48 -0
  202. package/dist/tui/index.js.map +1 -0
  203. package/dist/tui/line-editor.d.ts +44 -0
  204. package/dist/tui/line-editor.js +98 -0
  205. package/dist/tui/line-editor.js.map +1 -0
  206. package/dist/tui/progress.d.ts +23 -0
  207. package/dist/tui/progress.js +46 -0
  208. package/dist/tui/progress.js.map +1 -0
  209. package/dist/tui/settings-editor.d.ts +18 -0
  210. package/dist/tui/settings-editor.js +115 -0
  211. package/dist/tui/settings-editor.js.map +1 -0
  212. package/docs/live-trading.md +455 -0
  213. package/docs/strategy-research.md +597 -0
  214. package/package.json +10 -1
  215. package/python/desic_strategy/__init__.py +34 -0
  216. package/python/desic_strategy/actions.py +158 -0
  217. package/python/desic_strategy/context.py +164 -0
  218. package/python/desic_strategy/engine.py +614 -0
  219. package/python/desic_strategy/indicators.py +159 -0
  220. package/python/desic_strategy/live.py +253 -0
  221. package/python/desic_strategy/policy.py +193 -0
  222. package/python/desic_strategy/portfolio.py +152 -0
  223. package/python/desic_strategy/report.py +319 -0
  224. package/python/desic_strategy/runner.py +574 -0
  225. package/python/desic_strategy/timeframe.py +150 -0
  226. package/python/main.py +18 -0
  227. package/skills/okx-live-trading/SKILL.md +117 -0
  228. package/skills/okx-live-trading/agents/openai.yaml +9 -0
  229. package/skills/okx-live-trading/references/lifecycle.md +128 -0
  230. package/skills/okx-strategy-research/SKILL.md +113 -0
  231. package/skills/okx-strategy-research/agents/openai.yaml +9 -0
  232. package/skills/okx-strategy-research/references/execution-semantics.md +107 -0
  233. package/skills/okx-strategy-research/references/field-traps.md +142 -0
  234. package/skills/okx-strategy-research/references/python-api.md +121 -0
  235. package/skills/okx-strategy-research/references/tools-and-data.md +192 -0
  236. package/skills/okx-trading/SKILL.md +11 -10
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/i18n/messages.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,CAAU,CAAC;AAI7C,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,OAAQ,OAA6B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAiWD,MAAM,EAAE,GAAa;IACnB,WAAW,EAAE,+BAA+B;IAC5C,WAAW,EAAE,+DAA+D;IAC5E,SAAS,EAAE,wBAAwB;IACnC,QAAQ,EAAE,sBAAsB;IAChC,cAAc,EAAE,kBAAkB;IAClC,sBAAsB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,mCAAmC;IAC9E,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,eAAe;IAC3B,cAAc,EAAE,wCAAwC;IAExD,cAAc,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAoB,IAAI,IAAI;IACtD,UAAU,EAAE,CAAC,IAAI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;IACpB,aAAa,EAAE,WAAW;IAC1B,WAAW,EAAE,WAAW;IACxB,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,KAAK,EAAE;IAEtC,eAAe,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,MAAM,kBAAkB;IAC/D,eAAe,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,MAAM,EAAE;IAC7C,aAAa,EAAE,wBAAwB;CACxC,CAAC;AAEF,MAAM,OAAO,GAA6B,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;AAErD,MAAM,UAAU,QAAQ,CAAC,MAAc;IACrC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { AccountService } from "../account/service.js";
2
+ import type { ContractSpec } from "../strategy/instrument.js";
3
+ import type { LivePortfolio } from "./session.js";
4
+ export interface AccountSnapshot {
5
+ portfolio: LivePortfolio;
6
+ /** Exchange-reported positions for this instrument, as the gates read them. */
7
+ positions: Array<Record<string, unknown>>;
8
+ /** Realized loss for the current UTC day, as a positive number. */
9
+ realizedLossUsdtToday: number;
10
+ }
11
+ /**
12
+ * Reads the account state one evaluation needs, from the exchange.
13
+ *
14
+ * Every figure comes from OKX rather than a local tally. A locally accumulated position or
15
+ * PnL drifts the moment something happens outside this process — a manual close, a partial
16
+ * fill, a liquidation — and a strategy deciding against a drifted figure is the failure the
17
+ * whole live design is arranged to avoid.
18
+ */
19
+ export declare function readAccountSnapshot(accounts: Pick<AccountService, "getBalances" | "getPositions" | "getFills">, account: string, instId: string, contract: ContractSpec, markPrice: number, nowMs: number): Promise<AccountSnapshot>;
20
+ /**
21
+ * Realized loss for the current UTC day, as a positive number.
22
+ *
23
+ * Summed from the exchange's own fills and bounded to the UTC day, which is the window the
24
+ * limit is expressed in. Fees count: a day spent entirely on costs is a real loss, and
25
+ * excluding them would let the limit be walked past by a high-turnover strategy.
26
+ *
27
+ * Returns zero when the day is up rather than negative, so a profitable day never widens
28
+ * the allowance.
29
+ */
30
+ export declare function realizedLossToday(fills: Array<Record<string, unknown>>, nowMs: number): number;
@@ -0,0 +1,130 @@
1
+ /** Settlement currency positions and budgets are measured in. */
2
+ const QUOTE_CURRENCY = "USDT";
3
+ /**
4
+ * Reads the account state one evaluation needs, from the exchange.
5
+ *
6
+ * Every figure comes from OKX rather than a local tally. A locally accumulated position or
7
+ * PnL drifts the moment something happens outside this process — a manual close, a partial
8
+ * fill, a liquidation — and a strategy deciding against a drifted figure is the failure the
9
+ * whole live design is arranged to avoid.
10
+ */
11
+ export async function readAccountSnapshot(accounts, account, instId, contract, markPrice, nowMs) {
12
+ const [balances, positions, fills] = await Promise.all([
13
+ accounts.getBalances(account, QUOTE_CURRENCY),
14
+ accounts.getPositions(account, instId),
15
+ // Fills rather than a running total: the exchange's own record of what was realized.
16
+ accounts.getFills(account, { instId, limit: 100 })
17
+ ]);
18
+ const equity = readEquity(balances.data);
19
+ const rows = positions.data.filter((row) => String(row.instId ?? "") === instId);
20
+ const mapped = rows.map((row) => toPosition(row, instId, contract, markPrice)).filter((row) => row !== undefined);
21
+ const usedMargin = mapped.reduce((total, row) => total + Number(row.usedMarginUsdt ?? 0), 0);
22
+ return {
23
+ portfolio: {
24
+ cashUsdt: equity.cash,
25
+ equityUsdt: equity.total,
26
+ usedMarginUsdt: usedMargin,
27
+ availableMarginUsdt: Math.max(0, equity.available - usedMargin),
28
+ positions: mapped,
29
+ openOrders: []
30
+ },
31
+ positions: mapped,
32
+ realizedLossUsdtToday: realizedLossToday(fills.data, nowMs)
33
+ };
34
+ }
35
+ /**
36
+ * Equity from the balance rows.
37
+ *
38
+ * The per-currency detail is used rather than the top-level summary: OKX leaves `availEq`
39
+ * empty on the account row for some account modes, and reading that as zero would make
40
+ * every entry look unaffordable.
41
+ */
42
+ function readEquity(rows) {
43
+ const row = (rows[0] ?? {});
44
+ const details = (row.details ?? []);
45
+ const quote = details.find((item) => String(item.ccy ?? "") === QUOTE_CURRENCY) ?? {};
46
+ const total = numeric(row.totalEq) ?? numeric(quote.eq) ?? 0;
47
+ const cash = numeric(quote.cashBal) ?? numeric(quote.eq) ?? total;
48
+ const available = numeric(quote.availEq) ?? numeric(row.availEq) ?? total;
49
+ return { total, cash, available };
50
+ }
51
+ /**
52
+ * Converts one OKX position row into the shape strategy code and the gates read.
53
+ *
54
+ * A row with no size is dropped: OKX reports a closed position by leaving `pos` at zero,
55
+ * and passing that through would look like an open position of nothing.
56
+ */
57
+ function toPosition(row, instId, contract, markPrice) {
58
+ const quantity = Math.abs(numeric(row.pos) ?? 0);
59
+ if (quantity <= 0)
60
+ return undefined;
61
+ const side = resolveSide(row);
62
+ if (!side)
63
+ return undefined;
64
+ const entry = numeric(row.avgPx) ?? markPrice;
65
+ const mark = numeric(row.markPx) ?? markPrice;
66
+ const base = contract.contractValue * contract.contractMultiplier;
67
+ return {
68
+ instrumentId: instId,
69
+ side,
70
+ quantity,
71
+ averageEntryPrice: entry,
72
+ markPrice: mark,
73
+ contractValue: contract.contractValue,
74
+ notionalUsdt: quantity * base * mark,
75
+ // `imr` is the initial margin OKX itself reserved, which is what the side budget has to
76
+ // measure. Deriving it locally would disagree with the exchange under cross margin.
77
+ usedMarginUsdt: numeric(row.imr) ?? numeric(row.margin) ?? 0,
78
+ leverage: numeric(row.lever) ?? 1,
79
+ unrealizedPnlUsdt: numeric(row.upl) ?? 0,
80
+ openedAtMs: numeric(row.cTime) ?? 0,
81
+ updatedAtMs: numeric(row.uTime) ?? 0
82
+ };
83
+ }
84
+ /**
85
+ * Which side a position row describes.
86
+ *
87
+ * Net mode reports `posSide: "net"` with a signed size, so the sign decides. Long/short
88
+ * mode names the side directly.
89
+ */
90
+ function resolveSide(row) {
91
+ const declared = String(row.posSide ?? "");
92
+ if (declared === "long" || declared === "short")
93
+ return declared;
94
+ const signed = numeric(row.pos) ?? 0;
95
+ if (signed > 0)
96
+ return "long";
97
+ if (signed < 0)
98
+ return "short";
99
+ return undefined;
100
+ }
101
+ /**
102
+ * Realized loss for the current UTC day, as a positive number.
103
+ *
104
+ * Summed from the exchange's own fills and bounded to the UTC day, which is the window the
105
+ * limit is expressed in. Fees count: a day spent entirely on costs is a real loss, and
106
+ * excluding them would let the limit be walked past by a high-turnover strategy.
107
+ *
108
+ * Returns zero when the day is up rather than negative, so a profitable day never widens
109
+ * the allowance.
110
+ */
111
+ export function realizedLossToday(fills, nowMs) {
112
+ const dayStart = Date.UTC(new Date(nowMs).getUTCFullYear(), new Date(nowMs).getUTCMonth(), new Date(nowMs).getUTCDate());
113
+ let net = 0;
114
+ for (const fill of fills) {
115
+ const timestamp = numeric(fill.ts) ?? 0;
116
+ if (timestamp < dayStart)
117
+ continue;
118
+ net += numeric(fill.fillPnl) ?? 0;
119
+ // OKX reports a fee as a negative number when charged.
120
+ net += numeric(fill.fee) ?? 0;
121
+ }
122
+ return net < 0 ? Math.abs(net) : 0;
123
+ }
124
+ function numeric(value) {
125
+ if (value === null || value === undefined || value === "")
126
+ return null;
127
+ const parsed = Number(value);
128
+ return Number.isFinite(parsed) ? parsed : null;
129
+ }
130
+ //# sourceMappingURL=account-snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-snapshot.js","sourceRoot":"","sources":["../../src/live/account-snapshot.ts"],"names":[],"mappings":"AAIA,iEAAiE;AACjE,MAAM,cAAc,GAAG,MAAM,CAAC;AAU9B;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,QAA2E,EAC3E,OAAe,EACf,MAAc,EACd,QAAsB,EACtB,SAAiB,EACjB,KAAa;IAEb,MAAM,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACrD,QAAQ,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,CAAC;QAC7C,QAAQ,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC;QACtC,qFAAqF;QACrF,QAAQ,CAAC,Q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CAAC,KAAK,CAAC,CAAC,cAAc,EAAE,EAChC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,EAC7B,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,CAC7B,CAAC;IACF,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,SAAS,GAAG,QAAQ;YAAE,SAAS;QACnC,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClC,uDAAuD;QACvD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IACvE,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7B,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACjD,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { Bar } from "../bars/types.js";
2
+ /**
3
+ * Collapses a burst of confirmed bars into one pending cutoff per instrument.
4
+ *
5
+ * The websocket can deliver several minutes at once — after a reconnect, or when a
6
+ * repair backfills a stretch of history. Evaluating each of them would emit a queue
7
+ * of decisions for minutes that have already passed, and by the time the oldest one
8
+ * reached the exchange the market would have moved on. Only the newest cutoff is a
9
+ * legitimate trading input.
10
+ *
11
+ * Older bars are not discarded from anywhere that matters: they are already stored,
12
+ * and the session reads its window from the store. What is dropped is the *trigger*,
13
+ * not the data.
14
+ */
15
+ export declare class CutoffQueue {
16
+ private readonly pending;
17
+ private readonly inFlight;
18
+ /**
19
+ * Records a bar as the instrument's pending trigger.
20
+ *
21
+ * An out-of-order arrival is ignored rather than replacing a newer bar: a late
22
+ * delivery must not walk the trigger backwards in time.
23
+ */
24
+ offer(instId: string, bar: Bar): void;
25
+ /**
26
+ * Claims the newest pending bar for one instrument, if it is free to evaluate.
27
+ *
28
+ * Returns `undefined` while an evaluation for that instrument is already in
29
+ * flight. Two concurrent evaluations of one instrument could each read the
30
+ * position before the other's order landed, and both would then open one.
31
+ */
32
+ claim(instId: string): Bar | undefined;
33
+ /** Releases the instrument. Any bar that arrived meanwhile stays pending. */
34
+ release(instId: string): void;
35
+ /** Instruments with a pending bar that is not currently being evaluated. */
36
+ ready(): string[];
37
+ isBusy(instId: string): boolean;
38
+ pendingCutoff(instId: string): number | undefined;
39
+ /** Forgets everything for one instrument, used when a profile stops. */
40
+ forget(instId: string): void;
41
+ get size(): number;
42
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Collapses a burst of confirmed bars into one pending cutoff per instrument.
3
+ *
4
+ * The websocket can deliver several minutes at once — after a reconnect, or when a
5
+ * repair backfills a stretch of history. Evaluating each of them would emit a queue
6
+ * of decisions for minutes that have already passed, and by the time the oldest one
7
+ * reached the exchange the market would have moved on. Only the newest cutoff is a
8
+ * legitimate trading input.
9
+ *
10
+ * Older bars are not discarded from anywhere that matters: they are already stored,
11
+ * and the session reads its window from the store. What is dropped is the *trigger*,
12
+ * not the data.
13
+ */
14
+ export class CutoffQueue {
15
+ pending = new Map();
16
+ inFlight = new Set();
17
+ /**
18
+ * Records a bar as the instrument's pending trigger.
19
+ *
20
+ * An out-of-order arrival is ignored rather than replacing a newer bar: a late
21
+ * delivery must not walk the trigger backwards in time.
22
+ */
23
+ offer(instId, bar) {
24
+ const existing = this.pending.get(instId);
25
+ if (existing && existing.closeTimeMs >= bar.closeTimeMs)
26
+ return;
27
+ this.pending.set(instId, bar);
28
+ }
29
+ /**
30
+ * Claims the newest pending bar for one instrument, if it is free to evaluate.
31
+ *
32
+ * Returns `undefined` while an evaluation for that instrument is already in
33
+ * flight. Two concurrent evaluations of one instrument could each read the
34
+ * position before the other's order landed, and both would then open one.
35
+ */
36
+ claim(instId) {
37
+ if (this.inFlight.has(instId))
38
+ return undefined;
39
+ const bar = this.pending.get(instId);
40
+ if (!bar)
41
+ return undefined;
42
+ this.pending.delete(instId);
43
+ this.inFlight.add(instId);
44
+ return bar;
45
+ }
46
+ /** Releases the instrument. Any bar that arrived meanwhile stays pending. */
47
+ release(instId) {
48
+ this.inFlight.delete(instId);
49
+ }
50
+ /** Instruments with a pending bar that is not currently being evaluated. */
51
+ ready() {
52
+ return [...this.pending.keys()].filter((instId) => !this.inFlight.has(instId));
53
+ }
54
+ isBusy(instId) {
55
+ return this.inFlight.has(instId);
56
+ }
57
+ pendingCutoff(instId) {
58
+ return this.pending.get(instId)?.closeTimeMs;
59
+ }
60
+ /** Forgets everything for one instrument, used when a profile stops. */
61
+ forget(instId) {
62
+ this.pending.delete(instId);
63
+ this.inFlight.delete(instId);
64
+ }
65
+ get size() {
66
+ return this.pending.size;
67
+ }
68
+ }
69
+ //# sourceMappingURL=cutoff-queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cutoff-queue.js","sourceRoot":"","sources":["../../src/live/cutoff-queue.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,WAAW;IACL,OAAO,GAAG,IAAI,GAAG,EAAe,CAAC;IACjC,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IAE9C;;;;;OAKG;IACH,KAAK,CAAC,MAAc,EAAE,GAAQ;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC1C,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AAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The idempotency key for one profile's decision at one closed minute.
3
+ *
4
+ * Derived rather than random, and that is the whole point: after a crash the recovery
5
+ * path has to ask the exchange about an order it never saw the response for. It can only
6
+ * do that if the key — and therefore the client order id — is reproducible from facts
7
+ * that survive in the database.
8
+ *
9
+ * `(profile, cutoff)` is also exactly the pair the signals table is unique on, so one
10
+ * closed minute maps to one key, one client order id, and at most one order, no matter
11
+ * how many times the bar is delivered or the process restarts.
12
+ */
13
+ export declare function liveExecutionKey(profileId: string, cutoffAt: number): string;
14
+ /**
15
+ * The client order id OKX will see for an execution key.
16
+ *
17
+ * This mirrors `clientId` in the trade service exactly. It is duplicated rather than
18
+ * exported from there because recovery needs to compute it without going through the
19
+ * order-placing path, and a test pins the two against each other — if they ever diverge,
20
+ * reconciliation would look up an id the exchange never received and conclude no order
21
+ * existed.
22
+ */
23
+ export declare function liveClientOrderId(executionKey: string): string;
@@ -0,0 +1,31 @@
1
+ import crypto from "node:crypto";
2
+ /**
3
+ * The idempotency key for one profile's decision at one closed minute.
4
+ *
5
+ * Derived rather than random, and that is the whole point: after a crash the recovery
6
+ * path has to ask the exchange about an order it never saw the response for. It can only
7
+ * do that if the key — and therefore the client order id — is reproducible from facts
8
+ * that survive in the database.
9
+ *
10
+ * `(profile, cutoff)` is also exactly the pair the signals table is unique on, so one
11
+ * closed minute maps to one key, one client order id, and at most one order, no matter
12
+ * how many times the bar is delivered or the process restarts.
13
+ */
14
+ export function liveExecutionKey(profileId, cutoffAt) {
15
+ return `live:${profileId}:${cutoffAt}`;
16
+ }
17
+ /**
18
+ * The client order id OKX will see for an execution key.
19
+ *
20
+ * This mirrors `clientId` in the trade service exactly. It is duplicated rather than
21
+ * exported from there because recovery needs to compute it without going through the
22
+ * order-placing path, and a test pins the two against each other — if they ever diverge,
23
+ * reconciliation would look up an id the exchange never received and conclude no order
24
+ * existed.
25
+ */
26
+ export function liveClientOrderId(executionKey) {
27
+ const readable = executionKey.replace(/[^a-zA-Z0-9]/g, "").slice(0, 18);
28
+ const digest = crypto.createHash("sha256").update(executionKey).digest("hex").slice(0, 10);
29
+ return `o${readable}${digest}`.slice(0, 32);
30
+ }
31
+ //# sourceMappingURL=execution-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-key.js","sourceRoot":"","sources":["../../src/live/execution-key.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAiB,EAAE,QAAgB;IAClE,OAAO,QAAQ,SAAS,IAAI,QAAQ,EAAE,CAAC;AACzC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAAoB;IACpD,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACxE,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3F,OAAO,IAAI,QAAQ,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Whether a failure should count toward stopping a profile.
3
+ *
4
+ * Not every failure means the same thing. A profile that cannot reach OKX for one minute
5
+ * is in a different position from one whose strategy throws on every bar, and counting
6
+ * them alike would either stop trading over a transient blip or keep a broken strategy
7
+ * running.
8
+ *
9
+ * The rule: count what will not fix itself. A missing dependency, invalid source, or
10
+ * revoked permission repeats identically on the next bar, so a run of them means something
11
+ * systemic. A timeout or a dropped connection may already be over.
12
+ *
13
+ * Transient failures are still recorded as signals — the minute is not silently dropped —
14
+ * they just do not push a profile toward being stopped.
15
+ */
16
+ export type FailureKind = "systemic" | "transient";
17
+ export declare function classifyFailure(error: unknown): FailureKind;
18
+ export interface StreakDecision {
19
+ /** Whether this failure advanced the streak. */
20
+ counted: boolean;
21
+ kind: FailureKind;
22
+ streak: number;
23
+ /** Whether the profile should now be stopped. */
24
+ shouldDisable: boolean;
25
+ }
26
+ /**
27
+ * Decides what one failure means for a profile's streak.
28
+ *
29
+ * Pure, so the policy can be read and tested without a database or an exchange.
30
+ */
31
+ export declare function evaluateStreak(input: {
32
+ error: unknown;
33
+ currentStreak: number;
34
+ limit: number;
35
+ }): StreakDecision;
36
+ /** Explains an automatic shutdown, for the profile's `last_error` and its signal trail. */
37
+ export declare function describeAutoDisable(streak: number, message: string): string;
@@ -0,0 +1,57 @@
1
+ import { RuntimeError } from "../core/errors.js";
2
+ /**
3
+ * Error codes that resolve on their own.
4
+ *
5
+ * `STALE_DATA` belongs here because it usually means the bar window needed a repair the
6
+ * next minute's sync will perform. `RATE_LIMIT` passes with time.
7
+ *
8
+ * `CAPABILITY_UNAVAILABLE` is deliberately absent: a missing Python interpreter or an
9
+ * unusable engine repeats identically forever, which is systemic however it is worded.
10
+ */
11
+ const TRANSIENT_CODES = new Set(["NETWORK", "RATE_LIMIT", "STALE_DATA"]);
12
+ /**
13
+ * Codes that count even when marked retryable.
14
+ *
15
+ * `AMBIGUOUS_WRITE` is the important one: it means an order may or may not exist at the
16
+ * exchange, and continuing to trade against an unknown position is exactly what should
17
+ * stop quickly. `AUTH` and `PERMISSION` will not change without someone editing a key.
18
+ */
19
+ const ALWAYS_SYSTEMIC = new Set(["AMBIGUOUS_WRITE", "VALIDATION", "AUTH", "PERMISSION"]);
20
+ export function classifyFailure(error) {
21
+ if (error instanceof RuntimeError) {
22
+ if (ALWAYS_SYSTEMIC.has(error.code))
23
+ return "systemic";
24
+ if (TRANSIENT_CODES.has(error.code))
25
+ return "transient";
26
+ // A retryable error is the exchange or the network saying "try again".
27
+ if (error.retryable)
28
+ return "transient";
29
+ return "systemic";
30
+ }
31
+ const message = error instanceof Error ? error.message : String(error);
32
+ // A plain Error carrying a socket failure is still a socket failure.
33
+ if (/ECONNRESET|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|socket hang up|fetch failed/i.test(message)) {
34
+ return "transient";
35
+ }
36
+ // Anything unrecognised counts. An unknown fault that repeats is precisely the case
37
+ // automatic shutdown exists for, and treating the unknown as harmless would defeat it.
38
+ return "systemic";
39
+ }
40
+ /**
41
+ * Decides what one failure means for a profile's streak.
42
+ *
43
+ * Pure, so the policy can be read and tested without a database or an exchange.
44
+ */
45
+ export function evaluateStreak(input) {
46
+ const kind = classifyFailure(input.error);
47
+ if (kind === "transient") {
48
+ return { counted: false, kind, streak: input.currentStreak, shouldDisable: false };
49
+ }
50
+ const streak = input.currentStreak + 1;
51
+ return { counted: true, kind, streak, shouldDisable: streak >= input.limit };
52
+ }
53
+ /** Explains an automatic shutdown, for the profile's `last_error` and its signal trail. */
54
+ export function describeAutoDisable(streak, message) {
55
+ return `Stopped automatically after ${streak} consecutive failures. Last error: ${message}`;
56
+ }
57
+ //# sourceMappingURL=failures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failures.js","sourceRoot":"","sources":["../../src/live/failures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAmBjD;;;;;;;;GAQG;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,iBAAiB,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AAEzF,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C,OAAO,EAAE,CAAC;AAC9F,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { ContractSpec } from "../strategy/instrument.js";
2
+ import type { GateName, LiveProfile } from "./types.js";
3
+ /**
4
+ * Risk gates, evaluated between a strategy's intent and an order.
5
+ *
6
+ * Every gate **refuses**. None of them adjusts. That distinction is the whole design:
7
+ * if an intent needing 80 USDT met a 50 USDT budget and the host quietly sized it to
8
+ * 50, the user would see a filled order and never learn their strategy is being
9
+ * rewritten every time it trades. A refusal is recorded with the gate that produced
10
+ * it, which is why blocked signals are kept as carefully as filled ones.
11
+ *
12
+ * Ordered cheapest first: a decision the profile's own settings already forbid never
13
+ * reaches the network calls that `precheck` needs.
14
+ */
15
+ export interface GateContext {
16
+ profile: LiveProfile;
17
+ /** Generation captured when this evaluation began. */
18
+ generation: number;
19
+ /** Current generation, re-read immediately before submitting. */
20
+ currentGeneration: number;
21
+ enabledNow: boolean;
22
+ action: string;
23
+ contract: ContractSpec;
24
+ /** Price the order will be sized against. */
25
+ price: number;
26
+ /** Exchange-reported positions for this instrument. */
27
+ positions: Array<Record<string, unknown>>;
28
+ /** Margin available on the account, as the exchange reports it. */
29
+ availableMarginUsdt: number;
30
+ /** Realized loss for the current UTC day, as a positive number. */
31
+ realizedLossUsdtToday: number;
32
+ /** Cutoff being evaluated. */
33
+ cutoffAt: number;
34
+ /** Cutoff of the last order this profile actually submitted. */
35
+ lastSubmittedAt?: number;
36
+ }
37
+ export interface GateRefusal {
38
+ gate: GateName;
39
+ message: string;
40
+ details: Record<string, unknown>;
41
+ }
42
+ export type GateOutcome = {
43
+ allowed: true;
44
+ contracts: number;
45
+ notionalUsdt: number;
46
+ marginUsdt: number;
47
+ side: "long" | "short";
48
+ } | {
49
+ allowed: false;
50
+ refusal: GateRefusal;
51
+ };
52
+ export declare function sideOf(action: string): "long" | "short";
53
+ export declare function isOpening(action: string): boolean;
54
+ export declare function isClosing(action: string): boolean;
55
+ /**
56
+ * Runs every gate in order and returns either a legal size or the refusal.
57
+ *
58
+ * Closing actions skip the budget, loss, and cooldown gates. Those exist to limit new
59
+ * exposure, and applying them to an exit would trap a position open precisely when
60
+ * risk control most wants it closed — a daily loss limit that prevented closing a
61
+ * losing position would make the loss worse.
62
+ */
63
+ export declare function evaluateGates(context: GateContext): GateOutcome;
64
+ /** Contracts held on one side, as the exchange reports them. */
65
+ export declare function holdingQuantity(positions: Array<Record<string, unknown>>, side: "long" | "short"): number;