@senpi/runtime 3.0.22 → 3.0.24

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 (137) hide show
  1. package/README.md +7 -4
  2. package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
  3. package/dist/actions/close-position/close-position.action.js +8 -6
  4. package/dist/actions/close-position/close-position.action.js.map +1 -1
  5. package/dist/actions/decision-error-notification.d.ts +14 -0
  6. package/dist/actions/decision-error-notification.d.ts.map +1 -0
  7. package/dist/actions/decision-error-notification.js +36 -0
  8. package/dist/actions/decision-error-notification.js.map +1 -0
  9. package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
  10. package/dist/actions/open-position/open-position.action.js +8 -6
  11. package/dist/actions/open-position/open-position.action.js.map +1 -1
  12. package/dist/actions/types.d.ts +2 -0
  13. package/dist/actions/types.d.ts.map +1 -1
  14. package/dist/cli/guide-commands.d.ts.map +1 -1
  15. package/dist/cli/guide-commands.js +5 -7
  16. package/dist/cli/guide-commands.js.map +1 -1
  17. package/dist/cli/senpi-cli-config.d.ts +0 -17
  18. package/dist/cli/senpi-cli-config.d.ts.map +1 -1
  19. package/dist/cli/senpi-cli-config.js +0 -30
  20. package/dist/cli/senpi-cli-config.js.map +1 -1
  21. package/dist/cli/senpi-config-commands.d.ts +1 -1
  22. package/dist/cli/senpi-config-commands.d.ts.map +1 -1
  23. package/dist/cli/senpi-config-commands.js +1 -16
  24. package/dist/cli/senpi-config-commands.js.map +1 -1
  25. package/dist/constants/dsl/index.d.ts +1 -5
  26. package/dist/constants/dsl/index.d.ts.map +1 -1
  27. package/dist/constants/dsl/index.js +1 -5
  28. package/dist/constants/dsl/index.js.map +1 -1
  29. package/dist/dsl/engine-client/event-mapping.d.ts +1 -1
  30. package/dist/dsl/engine-client/event-mapping.d.ts.map +1 -1
  31. package/dist/dsl/events/build-closed-event.d.ts +1 -1
  32. package/dist/dsl/events/build-closed-event.js +1 -1
  33. package/dist/dsl/events/handlers.js +1 -1
  34. package/dist/dsl/monitor/process-one-position.js +3 -3
  35. package/dist/dsl/monitor/process-one-position.js.map +1 -1
  36. package/dist/dsl/notifications/format-utils.d.ts +1 -11
  37. package/dist/dsl/notifications/format-utils.d.ts.map +1 -1
  38. package/dist/dsl/notifications/format-utils.js +1 -48
  39. package/dist/dsl/notifications/format-utils.js.map +1 -1
  40. package/dist/dsl/notifications/formatter.d.ts +9 -25
  41. package/dist/dsl/notifications/formatter.d.ts.map +1 -1
  42. package/dist/dsl/notifications/formatter.js +20 -105
  43. package/dist/dsl/notifications/formatter.js.map +1 -1
  44. package/dist/dsl/notifications/index.d.ts +2 -8
  45. package/dist/dsl/notifications/index.d.ts.map +1 -1
  46. package/dist/dsl/notifications/index.js +60 -57
  47. package/dist/dsl/notifications/index.js.map +1 -1
  48. package/dist/dsl/plugin/index.d.ts.map +1 -1
  49. package/dist/dsl/plugin/index.js +1 -27
  50. package/dist/dsl/plugin/index.js.map +1 -1
  51. package/dist/dsl/plugin/options.d.ts +3 -2
  52. package/dist/dsl/plugin/options.d.ts.map +1 -1
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +16 -123
  55. package/dist/index.js.map +1 -1
  56. package/dist/prompt/session-context-seed-hook.d.ts +11 -0
  57. package/dist/prompt/session-context-seed-hook.d.ts.map +1 -0
  58. package/dist/prompt/session-context-seed-hook.js +99 -0
  59. package/dist/prompt/session-context-seed-hook.js.map +1 -0
  60. package/dist/runtime/auto-update/coordinator.d.ts +19 -7
  61. package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
  62. package/dist/runtime/auto-update/coordinator.js +122 -22
  63. package/dist/runtime/auto-update/coordinator.js.map +1 -1
  64. package/dist/runtime/create-action-context.d.ts.map +1 -1
  65. package/dist/runtime/create-action-context.js +1 -0
  66. package/dist/runtime/create-action-context.js.map +1 -1
  67. package/dist/runtime/create-runtime-context.d.ts +1 -0
  68. package/dist/runtime/create-runtime-context.d.ts.map +1 -1
  69. package/dist/runtime/create-runtime-context.js +1 -0
  70. package/dist/runtime/create-runtime-context.js.map +1 -1
  71. package/dist/runtime/decision-errors.d.ts +41 -53
  72. package/dist/runtime/decision-errors.d.ts.map +1 -1
  73. package/dist/runtime/decision-errors.js +48 -111
  74. package/dist/runtime/decision-errors.js.map +1 -1
  75. package/dist/runtime/notifications.d.ts +21 -14
  76. package/dist/runtime/notifications.d.ts.map +1 -1
  77. package/dist/runtime/notifications.js +192 -59
  78. package/dist/runtime/notifications.js.map +1 -1
  79. package/dist/runtime/runtime.d.ts +16 -2
  80. package/dist/runtime/runtime.d.ts.map +1 -1
  81. package/dist/runtime/runtime.js +106 -26
  82. package/dist/runtime/runtime.js.map +1 -1
  83. package/dist/runtime/strategy-lifecycle.d.ts +5 -5
  84. package/dist/runtime/strategy-lifecycle.d.ts.map +1 -1
  85. package/dist/runtime/strategy-lifecycle.js +96 -28
  86. package/dist/runtime/strategy-lifecycle.js.map +1 -1
  87. package/dist/runtime/supervisor/long-running-supervisor.js +3 -3
  88. package/dist/runtime/supervisor/long-running-supervisor.js.map +1 -1
  89. package/dist/runtime-api/lifecycle.d.ts +1 -1
  90. package/dist/runtime-api/lifecycle.js +1 -1
  91. package/dist/scripts/run-dsl-standalone-live.d.ts +7 -6
  92. package/dist/scripts/run-dsl-standalone-live.d.ts.map +1 -1
  93. package/dist/scripts/run-dsl-standalone-live.js +25 -21
  94. package/dist/scripts/run-dsl-standalone-live.js.map +1 -1
  95. package/dist/skills-manager/coordinator.d.ts +2 -2
  96. package/dist/skills-manager/coordinator.js +2 -2
  97. package/dist/test-setup.d.ts +2 -0
  98. package/dist/test-setup.d.ts.map +1 -0
  99. package/dist/test-setup.js +23 -0
  100. package/dist/test-setup.js.map +1 -0
  101. package/dist/types/dsl/index.d.ts +1 -1
  102. package/dist/types/notification.d.ts +95 -1
  103. package/dist/types/notification.d.ts.map +1 -1
  104. package/dist/types/notification.js +76 -1
  105. package/dist/types/notification.js.map +1 -1
  106. package/dist/types/runtime.d.ts +6 -0
  107. package/dist/types/runtime.d.ts.map +1 -1
  108. package/dist/types/session-context.d.ts +19 -0
  109. package/dist/types/session-context.d.ts.map +1 -0
  110. package/dist/types/session-context.js +20 -0
  111. package/dist/types/session-context.js.map +1 -0
  112. package/dist/utils/event-catalog.d.ts +73 -0
  113. package/dist/utils/event-catalog.d.ts.map +1 -1
  114. package/dist/utils/event-catalog.js +22 -0
  115. package/dist/utils/event-catalog.js.map +1 -1
  116. package/dist/utils/logger.d.ts +2 -18
  117. package/dist/utils/logger.d.ts.map +1 -1
  118. package/dist/utils/logger.js +2 -40
  119. package/dist/utils/logger.js.map +1 -1
  120. package/openclaw.plugin.json +1 -1
  121. package/package.json +1 -1
  122. package/dist/actions/notifications/formatter.d.ts +0 -39
  123. package/dist/actions/notifications/formatter.d.ts.map +0 -1
  124. package/dist/actions/notifications/formatter.js +0 -68
  125. package/dist/actions/notifications/formatter.js.map +0 -1
  126. package/dist/actions/notifications/index.d.ts +0 -37
  127. package/dist/actions/notifications/index.d.ts.map +0 -1
  128. package/dist/actions/notifications/index.js +0 -89
  129. package/dist/actions/notifications/index.js.map +0 -1
  130. package/dist/dsl/notifications/close-resolver.d.ts +0 -92
  131. package/dist/dsl/notifications/close-resolver.d.ts.map +0 -1
  132. package/dist/dsl/notifications/close-resolver.js +0 -309
  133. package/dist/dsl/notifications/close-resolver.js.map +0 -1
  134. package/dist/dsl/notifications/types.d.ts +0 -27
  135. package/dist/dsl/notifications/types.d.ts.map +0 -1
  136. package/dist/dsl/notifications/types.js +0 -5
  137. package/dist/dsl/notifications/types.js.map +0 -1
@@ -1,92 +0,0 @@
1
- /**
2
- * Deferred close notifications: match `discovery_get_trader_history` rows to closed DSL positions
3
- * and send enriched PnL / exit / fees, with a timeout fallback when history lags.
4
- */
5
- import type { DslClosedEvent } from "../../types/dsl/index.js";
6
- import type { PastTrade } from "../../types/strategy.js";
7
- import type { StrategyState } from "../../types/strategy.js";
8
- import type { PendingCloseNotification } from "./types.js";
9
- /**
10
- * Match tolerance (ms) between DSL timestamps and trade history `openTime` / `closedTime`.
11
- *
12
- * `MATCH_OPEN_TIME_MS` is wide (7 days) because scaled-in positions reset `createdAt` in
13
- * DSL state while the exchange keeps the original `openTime`. This is safe: a wallet holds
14
- * at most one directional position per asset, so `closedTime + coin + direction` is unique.
15
- * `MATCH_CLOSE_TIME_MS` (2 min) is the real discriminator.
16
- */
17
- export declare const MATCH_OPEN_TIME_MS: number;
18
- export declare const MATCH_CLOSE_TIME_MS = 120000;
19
- export interface CloseNotificationResolverOptions {
20
- /** Directory for `pending-close-notifications/*.json` (caller passes `{stateDir}/pending-close-notifications`). */
21
- pendingDir: string;
22
- getStrategy: (address: string) => StrategyState | undefined;
23
- /** Already includes `[recipe] ` prefix when strategy name is set. */
24
- notify: (message: string) => void;
25
- }
26
- /**
27
- * Finds the trade row that corresponds to a closed DSL position (coin/dex/direction + open/close times).
28
- *
29
- * Edge case: two closes for the same coin/direction within {@link MATCH_OPEN_TIME_MS} / {@link MATCH_CLOSE_TIME_MS}
30
- * could both score the same row; follow-up could track claimed trade IDs per resolver pass if needed.
31
- */
32
- export declare function matchTrade(pending: PendingCloseNotification, trades: PastTrade[]): PastTrade | undefined;
33
- /** Builds a pending record from a bus payload (also used for immediate fallback when no resolver). */
34
- export declare function buildPendingCloseFromEvent(e: DslClosedEvent, id: string): PendingCloseNotification;
35
- /**
36
- * Polls trade history and sends Telegram lines when a pending close is enriched or times out.
37
- */
38
- export declare class CloseNotificationResolver {
39
- private readonly pendingDir;
40
- private readonly getStrategy;
41
- private readonly notify;
42
- private readonly pending;
43
- private timer;
44
- private pollMs;
45
- /** Prevents overlapping `tick()` runs when a poll takes longer than `pollMs` (await yields). */
46
- private tickInFlight;
47
- constructor(opts: CloseNotificationResolverOptions);
48
- /**
49
- * Loads pending JSON from disk and starts the polling loop.
50
- * Awaits the first {@link tick} so callers (tests, plugin init) do not observe stale in-memory state.
51
- */
52
- start(pollIntervalMs?: number): Promise<void>;
53
- /**
54
- * Runs one poll pass; swallows errors so `setInterval` callbacks never surface as unhandled
55
- * rejections. The initial call from {@link start} is awaited so the first `tick` completes
56
- * before `start` resolves. Skips if the previous tick is still in progress so slow MCP calls
57
- * cannot overlap and double-notify.
58
- */
59
- private runTickSafe;
60
- stop(): void;
61
- /**
62
- * Queue a close for enrichment (writes disk, in-memory map).
63
- *
64
- * On disk failure after the in-memory enqueue, the row stays in `pending` so polling can still
65
- * resolve or time out; failures are logged and never propagate (subscriber uses fire-and-forget).
66
- */
67
- enqueue(event: DslClosedEvent): Promise<void>;
68
- private hydrateFromDisk;
69
- private persist;
70
- private removeFile;
71
- private tick;
72
- /**
73
- * Increments retry count and sends the no-PnL fallback once the enqueue age exceeds the timeout.
74
- * Used after unexpected errors so a pending row cannot wedge the resolver forever.
75
- */
76
- private bumpRetryAndMaybeFallback;
77
- /**
78
- * Paginates `fetchPastTrades` (sorted by closedTime DESC) until a match is found or
79
- * trades fall before the position's open time. Returns the matched trade, `undefined`
80
- * when no match was found across all pages, or `"error"` on fetch failure.
81
- *
82
- * NOTE: offset-based pagination with descending closedTime can skip or duplicate a row
83
- * when a new trade lands between page fetches (row shifts down by one). Cursor-style
84
- * pagination (closedTime < lastSeen) would avoid this but the upstream API does not
85
- * support it. At typical trade cadence and the ±120s match tolerance this is unlikely
86
- * to cause a missed notification.
87
- */
88
- private fetchAndMatch;
89
- private resolveOne;
90
- private finish;
91
- }
92
- //# sourceMappingURL=close-resolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"close-resolver.d.ts","sourceRoot":"","sources":["../../../src/dsl/notifications/close-resolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAO7D,OAAO,KAAK,EAAE,wBAAwB,E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;;;;;;;;OAUG;YACW,aAAa;YAsCb,UAAU;YAwCV,MAAM;CAKrB"}
@@ -1,309 +0,0 @@
1
- /**
2
- * Deferred close notifications: match `discovery_get_trader_history` rows to closed DSL positions
3
- * and send enriched PnL / exit / fees, with a timeout fallback when history lags.
4
- */
5
- import { randomUUID } from "node:crypto";
6
- import { mkdir, readdir, readFile, unlink, writeFile } from "node:fs/promises";
7
- import { join } from "node:path";
8
- import { CLOSE_RESOLVE_POLL_MS, CLOSE_RESOLVE_TIMEOUT_MS, } from "../../constants/dsl/index.js";
9
- import { normalizeDslCoinDex } from "../../utils/perp-coin.js";
10
- import { createLogger } from "../../utils/logger.js";
11
- import { formatDslClosedEnriched, formatDslClosedFallback } from "./formatter.js";
12
- const logger = createLogger("[senpi-core][dsl-close-resolver]");
13
- /**
14
- * Match tolerance (ms) between DSL timestamps and trade history `openTime` / `closedTime`.
15
- *
16
- * `MATCH_OPEN_TIME_MS` is wide (7 days) because scaled-in positions reset `createdAt` in
17
- * DSL state while the exchange keeps the original `openTime`. This is safe: a wallet holds
18
- * at most one directional position per asset, so `closedTime + coin + direction` is unique.
19
- * `MATCH_CLOSE_TIME_MS` (2 min) is the real discriminator.
20
- */
21
- export const MATCH_OPEN_TIME_MS = 7 * 24 * 60 * 60 * 1000;
22
- export const MATCH_CLOSE_TIME_MS = 120_000;
23
- /** Page size for paginated trade-history fetches. */
24
- const TRADE_PAGE_SIZE = 20;
25
- /** Safety cap on pages to prevent runaway pagination against a misbehaving API. */
26
- const MAX_TRADE_PAGES = 10;
27
- /**
28
- * Finds the trade row that corresponds to a closed DSL position (coin/dex/direction + open/close times).
29
- *
30
- * Edge case: two closes for the same coin/direction within {@link MATCH_OPEN_TIME_MS} / {@link MATCH_CLOSE_TIME_MS}
31
- * could both score the same row; follow-up could track claimed trade IDs per resolver pass if needed.
32
- */
33
- export function matchTrade(pending, trades) {
34
- const p = normalizeDslCoinDex(pending.asset, pending.dex);
35
- const createdMs = Date.parse(pending.createdAt);
36
- const closedMs = Date.parse(pending.closedAt);
37
- if (!Number.isFinite(createdMs) || !Number.isFinite(closedMs))
38
- return undefined;
39
- let best;
40
- let bestScore = Infinity;
41
- for (const t of trades) {
42
- const tcd = normalizeDslCoinDex(t.coin, t.dex ?? "");
43
- if (tcd.coin !== p.coin || tcd.dex !== p.dex)
44
- continue;
45
- if (t.direction !== pending.direction)
46
- continue;
47
- const openDelta = Math.abs(t.openTime * 1000 - createdMs);
48
- const closeDelta = Math.abs(t.closedTime * 1000 - closedMs);
49
- if (openDelta > MATCH_OPEN_TIME_MS || closeDelta > MATCH_CLOSE_TIME_MS)
50
- continue;
51
- const score = openDelta + closeDelta;
52
- if (score < bestScore) {
53
- bestScore = score;
54
- best = t;
55
- }
56
- }
57
- return best;
58
- }
59
- /** Builds a pending record from a bus payload (also used for immediate fallback when no resolver). */
60
- export function buildPendingCloseFromEvent(e, id) {
61
- const margin = e.margin ??
62
- (e.leverage && e.leverage > 0 && e.entryPrice != null && e.size != null
63
- ? (e.size * e.entryPrice) / e.leverage
64
- : 0);
65
- return {
66
- id,
67
- address: e.address,
68
- asset: e.asset,
69
- dex: e.dex ?? "",
70
- direction: e.direction ?? "LONG",
71
- entryPrice: e.entryPrice ?? 0,
72
- leverage: e.leverage ?? 1,
73
- margin,
74
- size: e.size ?? 0,
75
- closeReason: e.closeReason,
76
- createdAt: e.createdAt ?? e.timestamp,
77
- closedAt: e.timestamp,
78
- lastPrice: e.lastPrice ?? 0,
79
- currentROE: e.currentROE ?? 0,
80
- peakROE: e.peakROE ?? 0,
81
- currentTierIndex: e.currentTierIndex ?? null,
82
- enqueuedAt: Date.now(),
83
- retryCount: 0,
84
- resolved: false,
85
- };
86
- }
87
- /**
88
- * Polls trade history and sends Telegram lines when a pending close is enriched or times out.
89
- */
90
- export class CloseNotificationResolver {
91
- pendingDir;
92
- getStrategy;
93
- notify;
94
- pending = new Map();
95
- timer = null;
96
- pollMs = CLOSE_RESOLVE_POLL_MS;
97
- /** Prevents overlapping `tick()` runs when a poll takes longer than `pollMs` (await yields). */
98
- tickInFlight = false;
99
- constructor(opts) {
100
- this.pendingDir = opts.pendingDir;
101
- this.getStrategy = opts.getStrategy;
102
- this.notify = opts.notify;
103
- }
104
- /**
105
- * Loads pending JSON from disk and starts the polling loop.
106
- * Awaits the first {@link tick} so callers (tests, plugin init) do not observe stale in-memory state.
107
- */
108
- async start(pollIntervalMs = CLOSE_RESOLVE_POLL_MS) {
109
- this.pollMs = pollIntervalMs;
110
- await mkdir(this.pendingDir, { recursive: true });
111
- await this.hydrateFromDisk();
112
- if (this.timer)
113
- return;
114
- this.timer = setInterval(() => {
115
- void this.runTickSafe();
116
- }, this.pollMs);
117
- await this.runTickSafe();
118
- }
119
- /**
120
- * Runs one poll pass; swallows errors so `setInterval` callbacks never surface as unhandled
121
- * rejections. The initial call from {@link start} is awaited so the first `tick` completes
122
- * before `start` resolves. Skips if the previous tick is still in progress so slow MCP calls
123
- * cannot overlap and double-notify.
124
- */
125
- async runTickSafe() {
126
- if (this.tickInFlight)
127
- return;
128
- this.tickInFlight = true;
129
- try {
130
- await this.tick();
131
- }
132
- catch (err) {
133
- logger.warn("[dsl-close-resolver] tick failed", { err });
134
- }
135
- finally {
136
- this.tickInFlight = false;
137
- }
138
- }
139
- stop() {
140
- if (this.timer) {
141
- clearInterval(this.timer);
142
- this.timer = null;
143
- }
144
- }
145
- /**
146
- * Queue a close for enrichment (writes disk, in-memory map).
147
- *
148
- * On disk failure after the in-memory enqueue, the row stays in `pending` so polling can still
149
- * resolve or time out; failures are logged and never propagate (subscriber uses fire-and-forget).
150
- */
151
- async enqueue(event) {
152
- const id = randomUUID();
153
- const rec = buildPendingCloseFromEvent(event, id);
154
- this.pending.set(id, rec);
155
- try {
156
- await mkdir(this.pendingDir, { recursive: true });
157
- await this.persist(rec);
158
- }
159
- catch (err) {
160
- logger.warn("[dsl-close-resolver] enqueue disk write failed; pending close kept in memory", {
161
- err,
162
- id,
163
- });
164
- }
165
- }
166
- async hydrateFromDisk() {
167
- let names;
168
- try {
169
- names = await readdir(this.pendingDir);
170
- }
171
- catch {
172
- return;
173
- }
174
- for (const name of names) {
175
- if (!name.endsWith(".json"))
176
- continue;
177
- try {
178
- const raw = await readFile(join(this.pendingDir, name), "utf-8");
179
- const rec = JSON.parse(raw);
180
- if (rec.resolved) {
181
- await unlink(join(this.pendingDir, name)).catch(() => { });
182
- continue;
183
- }
184
- this.pending.set(rec.id, rec);
185
- }
186
- catch (err) {
187
- logger.warn("[dsl-close-resolver] skip bad pending file", { name, err });
188
- }
189
- }
190
- }
191
- async persist(rec) {
192
- const path = join(this.pendingDir, `${rec.id}.json`);
193
- await writeFile(path, JSON.stringify(rec, null, 2), "utf-8");
194
- }
195
- async removeFile(id) {
196
- await unlink(join(this.pendingDir, `${id}.json`)).catch(() => { });
197
- }
198
- async tick() {
199
- for (const id of [...this.pending.keys()]) {
200
- const rec = this.pending.get(id);
201
- if (!rec || rec.resolved)
202
- continue;
203
- try {
204
- await this.resolveOne(rec);
205
- }
206
- catch (err) {
207
- logger.warn("[dsl-close-resolver] resolveOne failed", { id: rec.id, err });
208
- await this.bumpRetryAndMaybeFallback(rec);
209
- }
210
- }
211
- }
212
- /**
213
- * Increments retry count and sends the no-PnL fallback once the enqueue age exceeds the timeout.
214
- * Used after unexpected errors so a pending row cannot wedge the resolver forever.
215
- */
216
- async bumpRetryAndMaybeFallback(rec) {
217
- rec.retryCount += 1;
218
- const elapsed = Date.now() - rec.enqueuedAt;
219
- if (elapsed >= CLOSE_RESOLVE_TIMEOUT_MS && this.pending.has(rec.id) && !rec.resolved) {
220
- this.notify(formatDslClosedFallback(rec));
221
- await this.finish(rec);
222
- }
223
- }
224
- /**
225
- * Paginates `fetchPastTrades` (sorted by closedTime DESC) until a match is found or
226
- * trades fall before the position's open time. Returns the matched trade, `undefined`
227
- * when no match was found across all pages, or `"error"` on fetch failure.
228
- *
229
- * NOTE: offset-based pagination with descending closedTime can skip or duplicate a row
230
- * when a new trade lands between page fetches (row shifts down by one). Cursor-style
231
- * pagination (closedTime < lastSeen) would avoid this but the upstream API does not
232
- * support it. At typical trade cadence and the ±120s match tolerance this is unlikely
233
- * to cause a missed notification.
234
- */
235
- async fetchAndMatch(strategy, rec) {
236
- const cutoffMs = Date.parse(rec.createdAt) - MATCH_OPEN_TIME_MS;
237
- let offset = 0;
238
- for (let page = 0; page < MAX_TRADE_PAGES; page++) {
239
- let trades;
240
- try {
241
- trades = await strategy.fetchPastTrades({
242
- limit: TRADE_PAGE_SIZE,
243
- offset,
244
- sort_by: "CLOSED_TIME",
245
- sort_direction: "DESC",
246
- });
247
- }
248
- catch (err) {
249
- logger.warn("[dsl-close-resolver] fetchPastTrades failed", { id: rec.id, page, err });
250
- return "error";
251
- }
252
- if (!trades?.length)
253
- return undefined;
254
- const hit = matchTrade(rec, trades);
255
- if (hit)
256
- return hit;
257
- // Oldest trade in this page — if it predates the position open window, stop.
258
- const oldestClosedTimeMs = Math.min(...trades.map((t) => t.closedTime)) * 1000;
259
- if (oldestClosedTimeMs < cutoffMs)
260
- return undefined;
261
- // Partial page means we've exhausted results.
262
- if (trades.length < TRADE_PAGE_SIZE)
263
- return undefined;
264
- offset += TRADE_PAGE_SIZE;
265
- }
266
- return undefined;
267
- }
268
- async resolveOne(rec) {
269
- const elapsed = Date.now() - rec.enqueuedAt;
270
- const strategy = this.getStrategy(rec.address);
271
- if (!strategy) {
272
- rec.retryCount += 1;
273
- if (elapsed >= CLOSE_RESOLVE_TIMEOUT_MS) {
274
- this.notify(formatDslClosedFallback(rec));
275
- await this.finish(rec);
276
- }
277
- return;
278
- }
279
- const hit = await this.fetchAndMatch(strategy, rec);
280
- if (hit === "error") {
281
- rec.retryCount += 1;
282
- if (elapsed >= CLOSE_RESOLVE_TIMEOUT_MS) {
283
- this.notify(formatDslClosedFallback(rec));
284
- await this.finish(rec);
285
- }
286
- return;
287
- }
288
- if (hit) {
289
- this.notify(formatDslClosedEnriched(rec, {
290
- realizedPnl: hit.realizedPnl,
291
- closePx: hit.closePx,
292
- totalFees: hit.totalFees,
293
- }));
294
- await this.finish(rec);
295
- return;
296
- }
297
- rec.retryCount += 1;
298
- if (elapsed >= CLOSE_RESOLVE_TIMEOUT_MS) {
299
- this.notify(formatDslClosedFallback(rec));
300
- await this.finish(rec);
301
- }
302
- }
303
- async finish(rec) {
304
- rec.resolved = true;
305
- this.pending.delete(rec.id);
306
- await this.removeFile(rec.id);
307
- }
308
- }
309
- //# sourceMappingURL=close-resolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"close-resolver.js","sourceRoot":"","sources":["../../../src/dsl/notifications/close-resolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,OAAO,EACL,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAElF,MAAM,MAAM,GAAG,YAAY,CAAC,kCAAkC,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAO,CAAC;AAE3C,qDAAqD;AACrD,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,mFAAmF;AACnF,MAAM,eAAe,GAAG,EAAE,CAAC;AAU3B;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CACxB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 +0,0 @@
1
- /**
2
- * Pending close notification persisted while waiting for trade-history enrichment.
3
- */
4
- export interface PendingCloseNotification {
5
- id: string;
6
- address: string;
7
- asset: string;
8
- dex: string;
9
- direction: "LONG" | "SHORT";
10
- entryPrice: number;
11
- leverage: number;
12
- margin: number;
13
- size: number;
14
- closeReason: string;
15
- /** Position open time (ISO). */
16
- createdAt: string;
17
- /** Position close time (ISO). */
18
- closedAt: string;
19
- lastPrice: number;
20
- currentROE: number;
21
- peakROE: number;
22
- currentTierIndex: number | null;
23
- enqueuedAt: number;
24
- retryCount: number;
25
- resolved: boolean;
26
- }
27
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/dsl/notifications/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;CACnB"}
@@ -1,5 +0,0 @@
1
- /**
2
- * Pending close notification persisted while waiting for trade-history enrichment.
3
- */
4
- export {};
5
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dsl/notifications/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}