backtest-kit 14.0.0 → 15.0.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.
- package/LICENSE +21 -21
- package/README.md +853 -808
- package/build/index.cjs +6691 -3418
- package/build/index.mjs +6683 -3420
- package/package.json +86 -86
- package/types.d.ts +1909 -170
package/types.d.ts
CHANGED
|
@@ -1122,6 +1122,181 @@ interface SchedulePingContract {
|
|
|
1122
1122
|
timestamp: number;
|
|
1123
1123
|
}
|
|
1124
1124
|
|
|
1125
|
+
/**
|
|
1126
|
+
* Contract for scheduled signal lifecycle events (creation and cancellation).
|
|
1127
|
+
*
|
|
1128
|
+
* Emitted by scheduleEventSubject when a scheduled signal is created (added) or cancelled
|
|
1129
|
+
* during tick()/backtest() processing. Lets consumers track the scheduled phase of a signal
|
|
1130
|
+
* without subscribing to the full signal stream.
|
|
1131
|
+
*
|
|
1132
|
+
* IMPORTANT: The scheduled -> active transition (activation) is intentionally NOT emitted here.
|
|
1133
|
+
* Activation produces an "opened" signal on the regular signal emitters; this contract only
|
|
1134
|
+
* covers a scheduled signal being put in place and being removed before it ever opened.
|
|
1135
|
+
*
|
|
1136
|
+
* Consumers:
|
|
1137
|
+
* - User callbacks via listenScheduleEvent() / listenScheduleEventOnce()
|
|
1138
|
+
*
|
|
1139
|
+
* @example
|
|
1140
|
+
* ```typescript
|
|
1141
|
+
* import { listenScheduleEvent } from "backtest-kit";
|
|
1142
|
+
*
|
|
1143
|
+
* listenScheduleEvent((event) => {
|
|
1144
|
+
* if (event.action === "scheduled") {
|
|
1145
|
+
* console.log(`Scheduled ${event.symbol} @ ${event.data.priceOpen}`);
|
|
1146
|
+
* } else {
|
|
1147
|
+
* console.log(`Cancelled ${event.symbol} (reason: ${event.reason})`);
|
|
1148
|
+
* }
|
|
1149
|
+
* });
|
|
1150
|
+
* ```
|
|
1151
|
+
*/
|
|
1152
|
+
interface ScheduleEventContract {
|
|
1153
|
+
/**
|
|
1154
|
+
* Lifecycle action for the scheduled signal.
|
|
1155
|
+
* - "scheduled": a new scheduled signal was created (waiting for priceOpen activation)
|
|
1156
|
+
* - "cancelled": the scheduled signal was removed before activation (timeout / price reject / user)
|
|
1157
|
+
*/
|
|
1158
|
+
action: "scheduled" | "cancelled";
|
|
1159
|
+
/**
|
|
1160
|
+
* Trading pair symbol (e.g., "BTCUSDT").
|
|
1161
|
+
* Identifies which market this event belongs to.
|
|
1162
|
+
*/
|
|
1163
|
+
symbol: string;
|
|
1164
|
+
/**
|
|
1165
|
+
* Strategy name that owns this scheduled signal.
|
|
1166
|
+
*/
|
|
1167
|
+
strategyName: StrategyName;
|
|
1168
|
+
/**
|
|
1169
|
+
* Exchange name where this scheduled signal lives.
|
|
1170
|
+
*/
|
|
1171
|
+
exchangeName: ExchangeName;
|
|
1172
|
+
/**
|
|
1173
|
+
* Frame name (timeframe / date range) for the run. Empty string in live mode.
|
|
1174
|
+
* Same value as the signal's `frameName` (`data.frameName`).
|
|
1175
|
+
*/
|
|
1176
|
+
frameName: FrameName;
|
|
1177
|
+
/**
|
|
1178
|
+
* Complete scheduled signal row data in public form.
|
|
1179
|
+
* Contains all signal information: id, position, priceOpen, priceTakeProfit, priceStopLoss, etc.
|
|
1180
|
+
*/
|
|
1181
|
+
data: IPublicSignalRow;
|
|
1182
|
+
/**
|
|
1183
|
+
* Cancellation reason. Present only when `action === "cancelled"`:
|
|
1184
|
+
* - "timeout": CC_SCHEDULE_AWAIT_MINUTES elapsed without reaching priceOpen
|
|
1185
|
+
* - "price_reject": price hit stop-loss before activation
|
|
1186
|
+
* - "user": cancelled via cancelScheduled()
|
|
1187
|
+
*
|
|
1188
|
+
* Always undefined when `action === "scheduled"`.
|
|
1189
|
+
*/
|
|
1190
|
+
reason?: StrategyCancelReason;
|
|
1191
|
+
/**
|
|
1192
|
+
* Current market price of the symbol at the time of the event.
|
|
1193
|
+
*/
|
|
1194
|
+
currentPrice: number;
|
|
1195
|
+
/**
|
|
1196
|
+
* Execution mode flag.
|
|
1197
|
+
* - true: Event from backtest execution (historical candle data)
|
|
1198
|
+
* - false: Event from live trading (real-time tick)
|
|
1199
|
+
*/
|
|
1200
|
+
backtest: boolean;
|
|
1201
|
+
/**
|
|
1202
|
+
* Event timestamp in milliseconds since Unix epoch.
|
|
1203
|
+
*
|
|
1204
|
+
* Timing semantics:
|
|
1205
|
+
* - Live mode: when.getTime() at the moment of the event
|
|
1206
|
+
* - Backtest mode: candle.timestamp of the candle being processed
|
|
1207
|
+
*/
|
|
1208
|
+
timestamp: number;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
/**
|
|
1212
|
+
* Contract for pending signal lifecycle events (open and close).
|
|
1213
|
+
*
|
|
1214
|
+
* Emitted by signalEventSubject when a pending position is opened (action "opened") or closed
|
|
1215
|
+
* (action "closed") during tick()/backtest() processing. Lets consumers track the active phase
|
|
1216
|
+
* of a signal without subscribing to the full signal stream.
|
|
1217
|
+
*
|
|
1218
|
+
* Covers every way a position opens (new signal, immediate entry, scheduled activation, user
|
|
1219
|
+
* activation) and every way it closes (take_profit / stop_loss / time_expired / user-close /
|
|
1220
|
+
* broker fill / order no longer pending).
|
|
1221
|
+
*
|
|
1222
|
+
* Consumers:
|
|
1223
|
+
* - User callbacks via listenSignalEvent() / listenSignalEventOnce()
|
|
1224
|
+
*
|
|
1225
|
+
* @example
|
|
1226
|
+
* ```typescript
|
|
1227
|
+
* import { listenSignalEvent } from "backtest-kit";
|
|
1228
|
+
*
|
|
1229
|
+
* listenSignalEvent((event) => {
|
|
1230
|
+
* if (event.action === "opened") {
|
|
1231
|
+
* console.log(`Opened ${event.symbol} @ ${event.data.priceOpen}`);
|
|
1232
|
+
* } else {
|
|
1233
|
+
* console.log(`Closed ${event.symbol} (reason: ${event.closeReason})`);
|
|
1234
|
+
* }
|
|
1235
|
+
* });
|
|
1236
|
+
* ```
|
|
1237
|
+
*/
|
|
1238
|
+
interface SignalEventContract {
|
|
1239
|
+
/**
|
|
1240
|
+
* Lifecycle action for the pending signal.
|
|
1241
|
+
* - "opened": a pending position was opened (new signal / immediate / scheduled or user activation)
|
|
1242
|
+
* - "closed": the pending position was closed (TP / SL / time_expired / user / broker fill / ping)
|
|
1243
|
+
*/
|
|
1244
|
+
action: "opened" | "closed";
|
|
1245
|
+
/**
|
|
1246
|
+
* Trading pair symbol (e.g., "BTCUSDT").
|
|
1247
|
+
* Identifies which market this event belongs to.
|
|
1248
|
+
*/
|
|
1249
|
+
symbol: string;
|
|
1250
|
+
/**
|
|
1251
|
+
* Strategy name that owns this pending signal.
|
|
1252
|
+
*/
|
|
1253
|
+
strategyName: StrategyName;
|
|
1254
|
+
/**
|
|
1255
|
+
* Exchange name where this pending signal lives.
|
|
1256
|
+
*/
|
|
1257
|
+
exchangeName: ExchangeName;
|
|
1258
|
+
/**
|
|
1259
|
+
* Frame name (timeframe / date range) for the run. Empty string in live mode.
|
|
1260
|
+
* Same value as the signal's `frameName` (`data.frameName`).
|
|
1261
|
+
*/
|
|
1262
|
+
frameName: FrameName;
|
|
1263
|
+
/**
|
|
1264
|
+
* Complete pending signal row data in public form.
|
|
1265
|
+
* Contains all signal information: id, position, priceOpen, priceTakeProfit, priceStopLoss,
|
|
1266
|
+
* effective entry / trailing SL/TP, PnL, etc.
|
|
1267
|
+
*/
|
|
1268
|
+
data: IPublicSignalRow;
|
|
1269
|
+
/**
|
|
1270
|
+
* Close reason. Present only when `action === "closed"`:
|
|
1271
|
+
* - "take_profit": effective take-profit level reached
|
|
1272
|
+
* - "stop_loss": effective stop-loss level reached
|
|
1273
|
+
* - "time_expired": position exceeded minuteEstimatedTime
|
|
1274
|
+
* - "closed": closed by user (closePending) or because the order is no longer open on the exchange
|
|
1275
|
+
*
|
|
1276
|
+
* Always undefined when `action === "opened"`.
|
|
1277
|
+
*/
|
|
1278
|
+
closeReason?: StrategyCloseReason;
|
|
1279
|
+
/**
|
|
1280
|
+
* Current market price of the symbol at the time of the event.
|
|
1281
|
+
* For "opened" this is the effective entry (priceOpen); for "closed" the close price.
|
|
1282
|
+
*/
|
|
1283
|
+
currentPrice: number;
|
|
1284
|
+
/**
|
|
1285
|
+
* Execution mode flag.
|
|
1286
|
+
* - true: Event from backtest execution (historical candle data)
|
|
1287
|
+
* - false: Event from live trading (real-time tick)
|
|
1288
|
+
*/
|
|
1289
|
+
backtest: boolean;
|
|
1290
|
+
/**
|
|
1291
|
+
* Event timestamp in milliseconds since Unix epoch.
|
|
1292
|
+
*
|
|
1293
|
+
* Timing semantics:
|
|
1294
|
+
* - Live mode: when.getTime() at the moment of the event
|
|
1295
|
+
* - Backtest mode: candle.timestamp of the candle being processed
|
|
1296
|
+
*/
|
|
1297
|
+
timestamp: number;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1125
1300
|
/**
|
|
1126
1301
|
* Contract for active ping events during active pending signal monitoring.
|
|
1127
1302
|
*
|
|
@@ -1362,9 +1537,20 @@ interface RiskContract {
|
|
|
1362
1537
|
}
|
|
1363
1538
|
|
|
1364
1539
|
/**
|
|
1365
|
-
* Base fields shared by all
|
|
1540
|
+
* Base fields shared by all order sync events.
|
|
1366
1541
|
*/
|
|
1367
|
-
interface
|
|
1542
|
+
interface OrderSyncBase {
|
|
1543
|
+
/**
|
|
1544
|
+
* Which order the sync gate is about:
|
|
1545
|
+
* - "active" — the position order: immediate open, activation fill of a resting
|
|
1546
|
+
* order, and every close. Reject (false/throw) skips the open/close; a rejected
|
|
1547
|
+
* fresh open rolls back the interval throttle and retries on the next tick.
|
|
1548
|
+
* - "schedule" — the resting entry order being PLACED when a scheduled signal is
|
|
1549
|
+
* created (action "signal-open" only). Reject means the exchange did not accept
|
|
1550
|
+
* the resting order: the scheduled signal is NOT registered, the risk
|
|
1551
|
+
* reservation is released and the placement retries on the next tick.
|
|
1552
|
+
*/
|
|
1553
|
+
type: "schedule" | "active";
|
|
1368
1554
|
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
1369
1555
|
symbol: string;
|
|
1370
1556
|
/** Strategy name that generated this signal */
|
|
@@ -1398,7 +1584,7 @@ interface SignalSyncBase {
|
|
|
1398
1584
|
* - External order sync services
|
|
1399
1585
|
* - Audit/logging pipelines
|
|
1400
1586
|
*/
|
|
1401
|
-
interface
|
|
1587
|
+
interface OrderOpenContract extends OrderSyncBase {
|
|
1402
1588
|
/** Discriminator for signal-open action */
|
|
1403
1589
|
action: "signal-open";
|
|
1404
1590
|
/** Market price at the moment of activation (VWAP or candle average) */
|
|
@@ -1453,7 +1639,7 @@ interface SignalOpenContract extends SignalSyncBase {
|
|
|
1453
1639
|
* - External order sync services
|
|
1454
1640
|
* - Audit/logging pipelines
|
|
1455
1641
|
*/
|
|
1456
|
-
interface
|
|
1642
|
+
interface OrderCloseContract extends OrderSyncBase {
|
|
1457
1643
|
/** Discriminator for signal-close action */
|
|
1458
1644
|
action: "signal-close";
|
|
1459
1645
|
/** Market price at the moment of close */
|
|
@@ -1496,37 +1682,48 @@ interface SignalCloseContract extends SignalSyncBase {
|
|
|
1496
1682
|
totalPartials: number;
|
|
1497
1683
|
}
|
|
1498
1684
|
/**
|
|
1499
|
-
* Discriminated union for
|
|
1685
|
+
* Discriminated union for order sync events.
|
|
1500
1686
|
*
|
|
1501
1687
|
* Emitted to allow external systems to synchronize with the framework's
|
|
1502
|
-
*
|
|
1688
|
+
* order lifecycle: open (type "active" — immediate/activation fill; type
|
|
1689
|
+
* "schedule" — placement of the resting entry order at scheduled-signal
|
|
1690
|
+
* creation) and close (position exited, always type "active").
|
|
1503
1691
|
*
|
|
1504
|
-
* Note:
|
|
1505
|
-
*
|
|
1692
|
+
* Note: cancelled scheduled signals do NOT emit OrderOpenContract — their
|
|
1693
|
+
* teardown goes through the schedule-event channel (Broker.commitScheduleCancelled).
|
|
1506
1694
|
*/
|
|
1507
|
-
type
|
|
1695
|
+
type OrderSyncContract = OrderOpenContract | OrderCloseContract;
|
|
1508
1696
|
|
|
1509
1697
|
/**
|
|
1510
|
-
* Signal
|
|
1698
|
+
* Signal order-ping sync event.
|
|
1511
1699
|
*
|
|
1512
|
-
* Emitted on every live tick while a
|
|
1513
|
-
*
|
|
1514
|
-
*
|
|
1700
|
+
* Emitted on every live tick while a signal is being monitored, BEFORE the framework
|
|
1701
|
+
* evaluates completion. It asks the external order management system whether the
|
|
1702
|
+
* corresponding order is STILL open on the exchange. Fires for BOTH monitored states,
|
|
1703
|
+
* discriminated by `type`:
|
|
1704
|
+
* - `type: "active"` — a pending signal (open position); the order backing the position.
|
|
1705
|
+
* - `type: "schedule"` — a scheduled signal; the resting entry order awaiting activation.
|
|
1515
1706
|
*
|
|
1516
1707
|
* Listener contract (mirrors syncSubject semantics):
|
|
1517
1708
|
* - Return true (or do nothing) — the order is still open on the exchange, keep monitoring.
|
|
1518
1709
|
* - Return false OR throw — the order is no longer open on the exchange (filled, cancelled,
|
|
1519
|
-
* liquidated externally).
|
|
1710
|
+
* liquidated externally). For "active" the framework closes the pending signal with
|
|
1711
|
+
* closeReason "closed"; for "schedule" it cancels the scheduled signal (reason "user").
|
|
1712
|
+
* NOTE for "schedule": if the resting order actually FILLED, confirm it via
|
|
1713
|
+
* activateScheduled/commitActivateScheduled instead of failing the ping — a failed ping
|
|
1714
|
+
* is a terminal cancel, not an activation.
|
|
1520
1715
|
*
|
|
1521
1716
|
* Backtest never emits this event — there is no live exchange to query.
|
|
1522
1717
|
*
|
|
1523
1718
|
* Consumers:
|
|
1524
|
-
* - Broker adapter via `
|
|
1525
|
-
* - Registered actions via `
|
|
1719
|
+
* - Broker adapter via `onOrderActiveCheck` / `onOrderScheduleCheck` (syncPendingSubject subscription)
|
|
1720
|
+
* - Registered actions via `orderCheck` / `onOrderCheck`
|
|
1526
1721
|
*/
|
|
1527
|
-
interface
|
|
1722
|
+
interface OrderCheckContract {
|
|
1528
1723
|
/** Discriminator for pending-ping action */
|
|
1529
1724
|
action: "signal-ping";
|
|
1725
|
+
/** Monitored state: "active" — open position order, "schedule" — resting entry order */
|
|
1726
|
+
type: "schedule" | "active";
|
|
1530
1727
|
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
1531
1728
|
symbol: string;
|
|
1532
1729
|
/** Strategy name that generated this signal */
|
|
@@ -1834,6 +2031,96 @@ interface IActionCallbacks {
|
|
|
1834
2031
|
* @param backtest - True for backtest mode, false for live trading
|
|
1835
2032
|
*/
|
|
1836
2033
|
onPingScheduled(event: SchedulePingContract, actionName: ActionName, strategyName: StrategyName, frameName: FrameName, backtest: boolean): void | Promise<void>;
|
|
2034
|
+
/**
|
|
2035
|
+
* Called on scheduled signal lifecycle events (creation / cancellation).
|
|
2036
|
+
*
|
|
2037
|
+
* Triggered by: StrategyConnectionService via scheduleEventSubject
|
|
2038
|
+
* Frequency: Once on creation (action "scheduled") and once on cancellation before activation
|
|
2039
|
+
* (action "cancelled": timeout / price_reject / user). The scheduled -> active transition is
|
|
2040
|
+
* NOT reported here — activation surfaces as an "opened" signal instead.
|
|
2041
|
+
*
|
|
2042
|
+
* Manual wiring — EVENT-BASED (driving the exchange from an action registered via `addActionSchema`)
|
|
2043
|
+
*
|
|
2044
|
+
* An action is the alternative to a Broker adapter for binding the framework to a real exchange:
|
|
2045
|
+
* both run inside the strategy tick, so the commit-functions from `src/function/strategy.ts` are
|
|
2046
|
+
* callable here and take effect on the next tick. On `event.action === "scheduled"` place the real
|
|
2047
|
+
* resting/limit order (tag it with `event.data.id`) and, if it resolves at once, call
|
|
2048
|
+
* `commitActivateScheduled(event.symbol, { id })`; on a reject call
|
|
2049
|
+
* `commitCancelScheduled(event.symbol, { id })`. On `event.action === "cancelled"` (the strategy has
|
|
2050
|
+
* already dropped the scheduled signal) cancel the matching exchange order; `event.reason` says why.
|
|
2051
|
+
* For ongoing polling of the resting order use `onPingScheduled` (every tick).
|
|
2052
|
+
*
|
|
2053
|
+
* @param event - Scheduled lifecycle data (action discriminates created vs cancelled)
|
|
2054
|
+
* @param actionName - Action identifier
|
|
2055
|
+
* @param strategyName - Strategy identifier
|
|
2056
|
+
* @param frameName - Timeframe identifier
|
|
2057
|
+
* @param backtest - True for backtest mode, false for live trading
|
|
2058
|
+
*
|
|
2059
|
+
* @example
|
|
2060
|
+
* ```typescript
|
|
2061
|
+
* import { addActionSchema, commitActivateScheduled, commitCancelScheduled } from "backtest-kit";
|
|
2062
|
+
*
|
|
2063
|
+
* addActionSchema({
|
|
2064
|
+
* actionName: "exchange-bridge",
|
|
2065
|
+
* callbacks: {
|
|
2066
|
+
* async onScheduleEvent(event) {
|
|
2067
|
+
* if (event.action === "scheduled") {
|
|
2068
|
+
* const order = await exchange.placeLimit(event.symbol, event.data.priceOpen, event.data.id);
|
|
2069
|
+
* if (order.status === "filled") await commitActivateScheduled(event.symbol, { id: order.id });
|
|
2070
|
+
* } else {
|
|
2071
|
+
* await exchange.cancelOrderById(event.data.id);
|
|
2072
|
+
* }
|
|
2073
|
+
* },
|
|
2074
|
+
* },
|
|
2075
|
+
* });
|
|
2076
|
+
* ```
|
|
2077
|
+
*/
|
|
2078
|
+
onScheduleEvent(event: ScheduleEventContract, actionName: ActionName, strategyName: StrategyName, frameName: FrameName, backtest: boolean): void | Promise<void>;
|
|
2079
|
+
/**
|
|
2080
|
+
* Called on pending signal lifecycle events (open / close).
|
|
2081
|
+
*
|
|
2082
|
+
* Triggered by: StrategyConnectionService via signalEventSubject
|
|
2083
|
+
* Frequency: Once when a pending position is opened (action "opened": new signal / immediate /
|
|
2084
|
+
* scheduled or user activation) and once when it is closed (action "closed" with closeReason
|
|
2085
|
+
* take_profit / stop_loss / time_expired / closed).
|
|
2086
|
+
*
|
|
2087
|
+
* Manual wiring — EVENT-BASED (driving the exchange from an action registered via `addActionSchema`)
|
|
2088
|
+
*
|
|
2089
|
+
* Alternative to a Broker adapter — the commit-functions from `src/function/strategy.ts` are
|
|
2090
|
+
* callable here (same tick context) and apply on the next tick. On `event.action === "opened"`
|
|
2091
|
+
* place the real entry + protective TP/SL orders; on `event.action === "closed"` (the strategy has
|
|
2092
|
+
* already removed the signal) flatten the real position and cancel leftover orders.
|
|
2093
|
+
*
|
|
2094
|
+
* Note: `onPendingEvent` fires only at open/close — it is NOT a per-tick monitor. To translate
|
|
2095
|
+
* intra-position exchange fills into `commitCreateTakeProfit` / `commitCreateStopLoss` /
|
|
2096
|
+
* `commitClosePending` on every tick, use `onPingActive` (fires each tick while the position is open).
|
|
2097
|
+
*
|
|
2098
|
+
* @param event - Pending lifecycle data (action discriminates opened vs closed)
|
|
2099
|
+
* @param actionName - Action identifier
|
|
2100
|
+
* @param strategyName - Strategy identifier
|
|
2101
|
+
* @param frameName - Timeframe identifier
|
|
2102
|
+
* @param backtest - True for backtest mode, false for live trading
|
|
2103
|
+
*
|
|
2104
|
+
* @example
|
|
2105
|
+
* ```typescript
|
|
2106
|
+
* import { addActionSchema, commitClosePending } from "backtest-kit";
|
|
2107
|
+
*
|
|
2108
|
+
* addActionSchema({
|
|
2109
|
+
* actionName: "exchange-bridge",
|
|
2110
|
+
* callbacks: {
|
|
2111
|
+
* async onPendingEvent(event) {
|
|
2112
|
+
* if (event.action === "opened") await exchange.openWithProtection(event.symbol, event.data);
|
|
2113
|
+
* else await exchange.flatten(event.symbol, event.data.id);
|
|
2114
|
+
* },
|
|
2115
|
+
* async onPingActive(event) { // per-tick fills -> close
|
|
2116
|
+
* const order = await exchange.getOrderById(event.data.id);
|
|
2117
|
+
* if (order?.status === "no_counterparty") await commitClosePending(event.symbol, { id: order.id });
|
|
2118
|
+
* },
|
|
2119
|
+
* },
|
|
2120
|
+
* });
|
|
2121
|
+
* ```
|
|
2122
|
+
*/
|
|
2123
|
+
onPendingEvent(event: SignalEventContract, actionName: ActionName, strategyName: StrategyName, frameName: FrameName, backtest: boolean): void | Promise<void>;
|
|
1837
2124
|
/**
|
|
1838
2125
|
* Called during active pending signal monitoring (every minute while position is active).
|
|
1839
2126
|
*
|
|
@@ -1881,37 +2168,54 @@ interface IActionCallbacks {
|
|
|
1881
2168
|
* They propagate up to CREATE_SYNC_FN which catches them and returns false.
|
|
1882
2169
|
* Throw to reject the operation — framework will retry on next tick.
|
|
1883
2170
|
*
|
|
2171
|
+
* MANUAL WIRING — EXCEPTION-BASED GATE: the action-side equivalent of the Broker
|
|
2172
|
+
* `onOrderOpenCommit` / `onOrderCloseCommit` gate. Throwing (or returning false) on
|
|
2173
|
+
* `event.action === "signal-open"` rolls the open back to idle (a scheduled activation is
|
|
2174
|
+
* cancelled); on `"signal-close"` it skips the close and leaves the position open — retried next
|
|
2175
|
+
* tick. Rides the same `syncSubject` emission as the Broker commit hooks, so a throw from either is
|
|
2176
|
+
* collapsed to false by `CREATE_SYNC_FN`. Backtest short-circuits the gate to true (live-only).
|
|
2177
|
+
*
|
|
1884
2178
|
* @param event - Sync event with action "signal-open" or "signal-close"
|
|
1885
2179
|
* @param actionName - Action identifier
|
|
1886
2180
|
* @param strategyName - Strategy identifier
|
|
1887
2181
|
* @param frameName - Timeframe identifier
|
|
1888
2182
|
* @param backtest - True for backtest mode, false for live trading
|
|
1889
2183
|
*/
|
|
1890
|
-
|
|
2184
|
+
onOrderSync(event: OrderSyncContract, actionName: ActionName, strategyName: StrategyName, frameName: FrameName, backtest: boolean): void | Promise<void>;
|
|
1891
2185
|
/**
|
|
1892
2186
|
* Called on every live tick while a pending signal is monitored, BEFORE TP/SL/time evaluation,
|
|
1893
2187
|
* to confirm the order is still pending (open) on the exchange.
|
|
1894
2188
|
*
|
|
2189
|
+
* Fires for both monitored states, discriminated by `event.type`: "active" — pending signal
|
|
2190
|
+
* (open position); "schedule" — scheduled signal (resting entry order awaiting activation).
|
|
2191
|
+
*
|
|
1895
2192
|
* Query the exchange by `event.signalId` and THROW ONLY when the order is NOT FOUND by that id
|
|
1896
2193
|
* (filled, cancelled, or liquidated externally) — the framework then closes the position with
|
|
1897
|
-
* closeReason "closed"
|
|
2194
|
+
* closeReason "closed" (type "active") or cancels the scheduled signal with reason "user"
|
|
2195
|
+
* (type "schedule").
|
|
1898
2196
|
*
|
|
1899
2197
|
* CRITICAL: swallow transient/network errors (timeout, 5xx, rate limit, disconnect) — return
|
|
1900
2198
|
* normally instead of throwing, otherwise a connectivity blip would wrongly close an open
|
|
1901
2199
|
* position. Throw exclusively on a confirmed "order not found by id" result.
|
|
1902
2200
|
*
|
|
1903
|
-
* NOTE: Like
|
|
2201
|
+
* NOTE: Like onOrderSync, exceptions from this method are NOT swallowed. They propagate up to
|
|
1904
2202
|
* CREATE_SYNC_PENDING_FN which catches them and returns false.
|
|
1905
2203
|
*
|
|
2204
|
+
* MANUAL WIRING — EXCEPTION-BASED GATE: the action-side equivalent of the Broker `onOrderCheck`.
|
|
2205
|
+
* A THROW on a confirmed "order not found by id" closes the position with closeReason "closed"
|
|
2206
|
+
* (retried via CREATE_SYNC_PENDING_FN). This is the throw-driven alternative to the imperative
|
|
2207
|
+
* `commitClosePending` (call it from `pingActive` instead) — pick one, not both, for the same
|
|
2208
|
+
* "order gone" condition. Backtest short-circuits the gate (live-only).
|
|
2209
|
+
*
|
|
1906
2210
|
* @deprecated This callback is not recommended for use. Exchange integration should be implemented
|
|
1907
|
-
* in Broker.useBrokerAdapter (the infrastructure domain layer) via
|
|
2211
|
+
* in Broker.useBrokerAdapter (the infrastructure domain layer) via onOrderCheck instead.
|
|
1908
2212
|
* @param event - Pending-ping event with action "signal-ping"
|
|
1909
2213
|
* @param actionName - Action identifier
|
|
1910
2214
|
* @param strategyName - Strategy identifier
|
|
1911
2215
|
* @param frameName - Timeframe identifier
|
|
1912
2216
|
* @param backtest - True for backtest mode, false for live trading
|
|
1913
2217
|
*/
|
|
1914
|
-
|
|
2218
|
+
onOrderCheck(event: OrderCheckContract, actionName: ActionName, strategyName: StrategyName, frameName: FrameName, backtest: boolean): void | Promise<void>;
|
|
1915
2219
|
}
|
|
1916
2220
|
/**
|
|
1917
2221
|
* Action schema registered via addActionSchema().
|
|
@@ -2142,6 +2446,35 @@ interface IAction {
|
|
|
2142
2446
|
* @param event - Scheduled signal monitoring data
|
|
2143
2447
|
*/
|
|
2144
2448
|
pingScheduled(event: SchedulePingContract): void | Promise<void>;
|
|
2449
|
+
/**
|
|
2450
|
+
* Handles scheduled signal lifecycle events (creation / cancellation).
|
|
2451
|
+
*
|
|
2452
|
+
* Emitted by: StrategyConnectionService via scheduleEventSubject
|
|
2453
|
+
* Source: CREATE_COMMIT_SCHEDULE_EVENT_FN callback in StrategyConnectionService
|
|
2454
|
+
* Frequency: Once when a scheduled signal is created ("scheduled") and once when it is
|
|
2455
|
+
* cancelled before activation ("cancelled": timeout / price_reject / user). The
|
|
2456
|
+
* scheduled -> active transition is NOT reported here.
|
|
2457
|
+
*
|
|
2458
|
+
* Manual wiring — EVENT-BASED: implement the user-facing callback {@link IActionCallbacks.onScheduleEvent} (via
|
|
2459
|
+
* `addActionSchema`) to drive the exchange (`commitActivateScheduled` / `commitCancelScheduled`).
|
|
2460
|
+
*
|
|
2461
|
+
* @param event - Scheduled lifecycle data (action discriminates created vs cancelled)
|
|
2462
|
+
*/
|
|
2463
|
+
scheduleEvent(event: ScheduleEventContract): void | Promise<void>;
|
|
2464
|
+
/**
|
|
2465
|
+
* Handles pending signal lifecycle events (open / close).
|
|
2466
|
+
*
|
|
2467
|
+
* Emitted by: StrategyConnectionService via signalEventSubject
|
|
2468
|
+
* Source: CREATE_COMMIT_SIGNAL_EVENT_FN callback in StrategyConnectionService
|
|
2469
|
+
* Frequency: Once when a pending position is opened (action "opened") and once when it is
|
|
2470
|
+
* closed (action "closed" with closeReason take_profit / stop_loss / time_expired / closed).
|
|
2471
|
+
*
|
|
2472
|
+
* Manual wiring — EVENT-BASED: implement the user-facing callback {@link IActionCallbacks.onPendingEvent} (via
|
|
2473
|
+
* `addActionSchema`) to drive the exchange; for per-tick fills use `onPingActive`.
|
|
2474
|
+
*
|
|
2475
|
+
* @param event - Pending lifecycle data (action discriminates opened vs closed)
|
|
2476
|
+
*/
|
|
2477
|
+
pendingEvent(event: SignalEventContract): void | Promise<void>;
|
|
2145
2478
|
/**
|
|
2146
2479
|
* Handles active ping events during active pending signal monitoring.
|
|
2147
2480
|
*
|
|
@@ -2178,12 +2511,18 @@ interface IAction {
|
|
|
2178
2511
|
*
|
|
2179
2512
|
* NOTE: Exceptions are NOT swallowed here — they propagate to CREATE_SYNC_FN.
|
|
2180
2513
|
*
|
|
2514
|
+
* MANUAL WIRING — EXCEPTION-BASED GATE: action-side equivalent of the Broker
|
|
2515
|
+
* `onOrderOpenCommit` / `onOrderCloseCommit`. Throw on "signal-open" → open rolls back to idle
|
|
2516
|
+
* (scheduled activation cancelled); throw on "signal-close" → close skipped, position stays open;
|
|
2517
|
+
* retried next tick. Same `syncSubject` emission as the Broker commit hooks (collapsed to false by
|
|
2518
|
+
* CREATE_SYNC_FN). Live-only. Implement via the {@link IActionCallbacks.onOrderSync} callback.
|
|
2519
|
+
*
|
|
2181
2520
|
* @deprecated This method is not recommended for use. Implement custom logic in signal(), signalLive(), or signalBacktest() instead.
|
|
2182
2521
|
* If you need to implement custom logic on signal open/close, please use signal(), signalBacktest(), signalLive() instead.
|
|
2183
|
-
* If Action::
|
|
2522
|
+
* If Action::orderSync throws the exchange will not execute the order!
|
|
2184
2523
|
* @param event - Sync event with action "signal-open" or "signal-close"
|
|
2185
2524
|
*/
|
|
2186
|
-
|
|
2525
|
+
orderSync(event: OrderSyncContract): void | Promise<void>;
|
|
2187
2526
|
/**
|
|
2188
2527
|
* Called on every live tick while a pending signal is monitored, BEFORE TP/SL/time evaluation,
|
|
2189
2528
|
* to confirm the order is still pending (open) on the exchange.
|
|
@@ -2198,12 +2537,19 @@ interface IAction {
|
|
|
2198
2537
|
*
|
|
2199
2538
|
* NOTE: Exceptions are NOT swallowed here — they propagate to CREATE_SYNC_PENDING_FN.
|
|
2200
2539
|
*
|
|
2540
|
+
* MANUAL WIRING — EXCEPTION-BASED GATE: action-side equivalent of the Broker `onOrderCheck`. A
|
|
2541
|
+
* throw on a confirmed "order not found by id" closes the position with closeReason "closed"
|
|
2542
|
+
* (retried via CREATE_SYNC_PENDING_FN). Throw-driven alternative to the imperative
|
|
2543
|
+
* `commitClosePending` (call it from `pingActive`) — pick one, not both. Live-only. Implement via
|
|
2544
|
+
* the {@link IActionCallbacks.onOrderCheck} callback.
|
|
2545
|
+
*
|
|
2201
2546
|
* @deprecated This method is not recommended for use. Exchange integration should be implemented
|
|
2202
|
-
* in Broker.useBrokerAdapter (the infrastructure domain layer) via
|
|
2203
|
-
* If Action::
|
|
2204
|
-
*
|
|
2547
|
+
* in Broker.useBrokerAdapter (the infrastructure domain layer) via onOrderCheck instead.
|
|
2548
|
+
* If Action::orderCheck throws the framework will close the position with closeReason "closed"
|
|
2549
|
+
* (event.type "active") or cancel the scheduled signal (event.type "schedule")!
|
|
2550
|
+
* @param event - Order-ping event with action "signal-ping" and type "schedule" | "active"
|
|
2205
2551
|
*/
|
|
2206
|
-
|
|
2552
|
+
orderCheck(event: OrderCheckContract): void | Promise<void>;
|
|
2207
2553
|
/**
|
|
2208
2554
|
* Cleans up resources and subscriptions when action handler is no longer needed.
|
|
2209
2555
|
*
|
|
@@ -2564,6 +2910,20 @@ type StrategyStatus = {
|
|
|
2564
2910
|
cancelledSignal: IScheduledSignalCancelRow | null;
|
|
2565
2911
|
/** Deferred user-initiated scheduled activate (activateScheduled), or null if none pending */
|
|
2566
2912
|
activatedSignal: IScheduledSignalActivateRow | null;
|
|
2913
|
+
/**
|
|
2914
|
+
* Deferred broker-confirmed take-profit fill (createTakeProfit), or null if none pending.
|
|
2915
|
+
* Set when the external order management system reports the position's TP order was actually
|
|
2916
|
+
* filled on the exchange (e.g. by candle high/low) — independent of the VWAP-based TP check.
|
|
2917
|
+
* Drained on the next tick/backtest to close the position with closeReason "take_profit".
|
|
2918
|
+
*/
|
|
2919
|
+
takeProfitSignal: ISignalCloseRow | null;
|
|
2920
|
+
/**
|
|
2921
|
+
* Deferred broker-confirmed stop-loss fill (createStopLoss), or null if none pending.
|
|
2922
|
+
* Set when the external order management system reports the position's SL order was actually
|
|
2923
|
+
* filled on the exchange (e.g. by candle high/low) — independent of the VWAP-based SL check.
|
|
2924
|
+
* Drained on the next tick/backtest to close the position with closeReason "stop_loss".
|
|
2925
|
+
*/
|
|
2926
|
+
stopLossSignal: ISignalCloseRow | null;
|
|
2567
2927
|
};
|
|
2568
2928
|
/**
|
|
2569
2929
|
* Commit payload for strategy commits.
|
|
@@ -3584,6 +3944,44 @@ interface IStrategy {
|
|
|
3584
3944
|
* @returns Promise that resolves when the DTO is queued
|
|
3585
3945
|
*/
|
|
3586
3946
|
createSignal: (symbol: string, currentPrice: number, dto: ISignalDto) => Promise<void>;
|
|
3947
|
+
/**
|
|
3948
|
+
* Reports that the pending position's take-profit order was actually filled on the exchange
|
|
3949
|
+
* (e.g. by candle high/low), forcing a close that does not wait for the VWAP-based TP check.
|
|
3950
|
+
*
|
|
3951
|
+
* The exchange and the strategy are parallel states: ClientStrategy evaluates TP/SL against
|
|
3952
|
+
* VWAP, but the real order may close on high/low. This method bridges that gap — the broker
|
|
3953
|
+
* confirms the fill out of the async-hooks execution context, and the close is deferred:
|
|
3954
|
+
* a snapshot of the current pending signal is stored and drained on the next tick/backtest,
|
|
3955
|
+
* which closes the position with closeReason "take_profit" at the effective take-profit level.
|
|
3956
|
+
*
|
|
3957
|
+
* No-op if no pending signal exists. Persisted (live mode only) so a crash before the next
|
|
3958
|
+
* tick does not lose the deferred close.
|
|
3959
|
+
*
|
|
3960
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
3961
|
+
* @param backtest - Whether running in backtest mode
|
|
3962
|
+
* @param payload - Optional commit id/note attached to the close
|
|
3963
|
+
* @returns Promise that resolves when the take-profit fill is queued
|
|
3964
|
+
*/
|
|
3965
|
+
createTakeProfit: (symbol: string, backtest: boolean, payload: Partial<CommitPayload>) => Promise<void>;
|
|
3966
|
+
/**
|
|
3967
|
+
* Reports that the pending position's stop-loss order was actually filled on the exchange
|
|
3968
|
+
* (e.g. by candle high/low), forcing a close that does not wait for the VWAP-based SL check.
|
|
3969
|
+
*
|
|
3970
|
+
* The exchange and the strategy are parallel states: ClientStrategy evaluates TP/SL against
|
|
3971
|
+
* VWAP, but the real order may close on high/low. This method bridges that gap — the broker
|
|
3972
|
+
* confirms the fill out of the async-hooks execution context, and the close is deferred:
|
|
3973
|
+
* a snapshot of the current pending signal is stored and drained on the next tick/backtest,
|
|
3974
|
+
* which closes the position with closeReason "stop_loss" at the effective stop-loss level.
|
|
3975
|
+
*
|
|
3976
|
+
* No-op if no pending signal exists. Persisted (live mode only) so a crash before the next
|
|
3977
|
+
* tick does not lose the deferred close.
|
|
3978
|
+
*
|
|
3979
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
3980
|
+
* @param backtest - Whether running in backtest mode
|
|
3981
|
+
* @param payload - Optional commit id/note attached to the close
|
|
3982
|
+
* @returns Promise that resolves when the stop-loss fill is queued
|
|
3983
|
+
*/
|
|
3984
|
+
createStopLoss: (symbol: string, backtest: boolean, payload: Partial<CommitPayload>) => Promise<void>;
|
|
3587
3985
|
/**
|
|
3588
3986
|
* Returns the deferred strategy-state snapshot held in memory for this iteration — exactly
|
|
3589
3987
|
* what would be written to persist (queued createSignal, commit queue, deferred user-action
|
|
@@ -5722,6 +6120,9 @@ declare function commitAverageBuy(symbol: string, cost?: number): Promise<boolea
|
|
|
5722
6120
|
*
|
|
5723
6121
|
* Automatically detects backtest/live mode from execution context.
|
|
5724
6122
|
*
|
|
6123
|
+
* @deprecated The name is misleading — the function returns the HELD share,
|
|
6124
|
+
* not the closed one. Use {@link getTotalPercentHeld} instead.
|
|
6125
|
+
*
|
|
5725
6126
|
* @param symbol - Trading pair symbol
|
|
5726
6127
|
* @returns Promise<number> - held percentage (0–100)
|
|
5727
6128
|
*
|
|
@@ -5740,6 +6141,9 @@ declare function getTotalPercentClosed(symbol: string): Promise<number>;
|
|
|
5740
6141
|
*
|
|
5741
6142
|
* Automatically detects backtest/live mode from execution context.
|
|
5742
6143
|
*
|
|
6144
|
+
* @deprecated The name is misleading — the function returns the REMAINING
|
|
6145
|
+
* cost basis, not the closed one. Use {@link getRemainingCostBasis} instead.
|
|
6146
|
+
*
|
|
5743
6147
|
* @param symbol - Trading pair symbol
|
|
5744
6148
|
* @returns Promise<number> - held cost basis in dollars
|
|
5745
6149
|
*
|
|
@@ -5752,6 +6156,44 @@ declare function getTotalPercentClosed(symbol: string): Promise<number>;
|
|
|
5752
6156
|
* ```
|
|
5753
6157
|
*/
|
|
5754
6158
|
declare function getTotalCostClosed(symbol: string): Promise<number>;
|
|
6159
|
+
/**
|
|
6160
|
+
* Returns the percentage of the position currently held (not yet closed by partials).
|
|
6161
|
+
* 100 = nothing has been closed (full position), 0 = fully closed.
|
|
6162
|
+
* Correctly accounts for DCA entries between partial closes.
|
|
6163
|
+
*
|
|
6164
|
+
* Correctly-named alias for {@link getTotalPercentClosed}.
|
|
6165
|
+
*
|
|
6166
|
+
* @param symbol - Trading pair symbol
|
|
6167
|
+
* @returns Promise<number> - held percentage (0–100)
|
|
6168
|
+
*
|
|
6169
|
+
* @example
|
|
6170
|
+
* ```typescript
|
|
6171
|
+
* import { getTotalPercentHeld } from "backtest-kit";
|
|
6172
|
+
*
|
|
6173
|
+
* const heldPct = await getTotalPercentHeld("BTCUSDT");
|
|
6174
|
+
* console.log(`Holding ${heldPct}% of position`);
|
|
6175
|
+
* ```
|
|
6176
|
+
*/
|
|
6177
|
+
declare function getTotalPercentHeld(symbol: string): Promise<number>;
|
|
6178
|
+
/**
|
|
6179
|
+
* Returns the remaining cost basis in dollars — how much of the position is
|
|
6180
|
+
* still held (not yet closed by partials). Correctly accounts for DCA entries
|
|
6181
|
+
* between partial closes.
|
|
6182
|
+
*
|
|
6183
|
+
* Correctly-named alias for {@link getTotalCostClosed}.
|
|
6184
|
+
*
|
|
6185
|
+
* @param symbol - Trading pair symbol
|
|
6186
|
+
* @returns Promise<number> - remaining cost basis in dollars
|
|
6187
|
+
*
|
|
6188
|
+
* @example
|
|
6189
|
+
* ```typescript
|
|
6190
|
+
* import { getRemainingCostBasis } from "backtest-kit";
|
|
6191
|
+
*
|
|
6192
|
+
* const remaining = await getRemainingCostBasis("BTCUSDT");
|
|
6193
|
+
* console.log(`Holding $${remaining} of position`);
|
|
6194
|
+
* ```
|
|
6195
|
+
*/
|
|
6196
|
+
declare function getRemainingCostBasis(symbol: string): Promise<number>;
|
|
5755
6197
|
/**
|
|
5756
6198
|
* Returns the currently active pending signal for the strategy.
|
|
5757
6199
|
* If no active signal exists, returns null.
|
|
@@ -6635,6 +7077,52 @@ declare function commitSignalNotify(symbol: string, payload?: Partial<SignalNoti
|
|
|
6635
7077
|
* ```
|
|
6636
7078
|
*/
|
|
6637
7079
|
declare function commitCreateSignal(symbol: string, dto: ISignalDto): Promise<void>;
|
|
7080
|
+
/**
|
|
7081
|
+
* Reports that the pending position's take-profit order was actually filled on the exchange
|
|
7082
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based TP check.
|
|
7083
|
+
*
|
|
7084
|
+
* The exchange and the strategy are parallel states: the framework evaluates TP/SL against VWAP,
|
|
7085
|
+
* but the real order may fill on high/low. The close is deferred and emitted with closeReason
|
|
7086
|
+
* "take_profit" on the next tick. No-op if no pending signal exists.
|
|
7087
|
+
*
|
|
7088
|
+
* Automatically detects backtest/live mode from execution context.
|
|
7089
|
+
*
|
|
7090
|
+
* @param symbol - Trading pair symbol
|
|
7091
|
+
* @param payload - Optional commit payload with id and note
|
|
7092
|
+
* @returns Promise that resolves when the take-profit fill is queued
|
|
7093
|
+
*
|
|
7094
|
+
* @example
|
|
7095
|
+
* ```typescript
|
|
7096
|
+
* import { commitCreateTakeProfit } from "backtest-kit";
|
|
7097
|
+
*
|
|
7098
|
+
* // Report TP fill confirmed on the exchange
|
|
7099
|
+
* await commitCreateTakeProfit("BTCUSDT", { id: "tp-fill-001" });
|
|
7100
|
+
* ```
|
|
7101
|
+
*/
|
|
7102
|
+
declare function commitCreateTakeProfit(symbol: string, payload?: Partial<CommitPayload>): Promise<void>;
|
|
7103
|
+
/**
|
|
7104
|
+
* Reports that the pending position's stop-loss order was actually filled on the exchange
|
|
7105
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based SL check.
|
|
7106
|
+
*
|
|
7107
|
+
* The exchange and the strategy are parallel states: the framework evaluates TP/SL against VWAP,
|
|
7108
|
+
* but the real order may fill on high/low. The close is deferred and emitted with closeReason
|
|
7109
|
+
* "stop_loss" on the next tick. No-op if no pending signal exists.
|
|
7110
|
+
*
|
|
7111
|
+
* Automatically detects backtest/live mode from execution context.
|
|
7112
|
+
*
|
|
7113
|
+
* @param symbol - Trading pair symbol
|
|
7114
|
+
* @param payload - Optional commit payload with id and note
|
|
7115
|
+
* @returns Promise that resolves when the stop-loss fill is queued
|
|
7116
|
+
*
|
|
7117
|
+
* @example
|
|
7118
|
+
* ```typescript
|
|
7119
|
+
* import { commitCreateStopLoss } from "backtest-kit";
|
|
7120
|
+
*
|
|
7121
|
+
* // Report SL fill confirmed on the exchange
|
|
7122
|
+
* await commitCreateStopLoss("BTCUSDT", { id: "sl-fill-001" });
|
|
7123
|
+
* ```
|
|
7124
|
+
*/
|
|
7125
|
+
declare function commitCreateStopLoss(symbol: string, payload?: Partial<CommitPayload>): Promise<void>;
|
|
6638
7126
|
/**
|
|
6639
7127
|
* Returns the in-memory deferred strategy-state snapshot for the current iteration: the queued
|
|
6640
7128
|
* createSignal, commit queue and deferred user-action flags, plus the current pending signal id.
|
|
@@ -6663,16 +7151,15 @@ declare function getStrategyStatus(symbol: string): Promise<StrategyStatus>;
|
|
|
6663
7151
|
*
|
|
6664
7152
|
* Automatically detects backtest/live mode from execution context.
|
|
6665
7153
|
*
|
|
6666
|
-
* @param symbol - Trading pair symbol
|
|
6667
|
-
* @param strategyName - Strategy name to stop
|
|
7154
|
+
* @param symbol - Trading pair symbol; the strategy is resolved from the active method context
|
|
6668
7155
|
* @returns Promise that resolves when stop flag is set
|
|
6669
7156
|
*
|
|
6670
7157
|
* @example
|
|
6671
7158
|
* ```typescript
|
|
6672
|
-
* import {
|
|
7159
|
+
* import { stopStrategy } from "backtest-kit";
|
|
6673
7160
|
*
|
|
6674
|
-
* // Stop strategy after some condition
|
|
6675
|
-
* await
|
|
7161
|
+
* // Stop strategy after some condition (inside a strategy/action callback)
|
|
7162
|
+
* await stopStrategy("BTCUSDT");
|
|
6676
7163
|
* ```
|
|
6677
7164
|
*/
|
|
6678
7165
|
declare function stopStrategy(symbol: string): Promise<void>;
|
|
@@ -9248,9 +9735,9 @@ declare function listenValidation(fn: (error: Error) => void): () => void;
|
|
|
9248
9735
|
*
|
|
9249
9736
|
* @example
|
|
9250
9737
|
* ```typescript
|
|
9251
|
-
* import {
|
|
9738
|
+
* import { listenPartialProfitAvailable } from "./function/event";
|
|
9252
9739
|
*
|
|
9253
|
-
* const unsubscribe =
|
|
9740
|
+
* const unsubscribe = listenPartialProfitAvailable((event) => {
|
|
9254
9741
|
* console.log(`Signal ${event.data.id} reached ${event.level}% profit`);
|
|
9255
9742
|
* console.log(`Symbol: ${event.symbol}, Price: ${event.currentPrice}`);
|
|
9256
9743
|
* console.log(`Mode: ${event.backtest ? "Backtest" : "Live"}`);
|
|
@@ -9304,9 +9791,9 @@ declare function listenPartialProfitAvailableOnce(filterFn: (event: PartialProfi
|
|
|
9304
9791
|
*
|
|
9305
9792
|
* @example
|
|
9306
9793
|
* ```typescript
|
|
9307
|
-
* import {
|
|
9794
|
+
* import { listenPartialLossAvailable } from "./function/event";
|
|
9308
9795
|
*
|
|
9309
|
-
* const unsubscribe =
|
|
9796
|
+
* const unsubscribe = listenPartialLossAvailable((event) => {
|
|
9310
9797
|
* console.log(`Signal ${event.data.id} reached ${event.level}% loss`);
|
|
9311
9798
|
* console.log(`Symbol: ${event.symbol}, Price: ${event.currentPrice}`);
|
|
9312
9799
|
* console.log(`Mode: ${event.backtest ? "Backtest" : "Live"}`);
|
|
@@ -9361,9 +9848,9 @@ declare function listenPartialLossAvailableOnce(filterFn: (event: PartialLossCon
|
|
|
9361
9848
|
*
|
|
9362
9849
|
* @example
|
|
9363
9850
|
* ```typescript
|
|
9364
|
-
* import {
|
|
9851
|
+
* import { listenBreakevenAvailable } from "./function/event";
|
|
9365
9852
|
*
|
|
9366
|
-
* const unsubscribe =
|
|
9853
|
+
* const unsubscribe = listenBreakevenAvailable((event) => {
|
|
9367
9854
|
* console.log(`Signal ${event.data.id} reached breakeven`);
|
|
9368
9855
|
* console.log(`Symbol: ${event.symbol}, Position: ${event.data.position}`);
|
|
9369
9856
|
* console.log(`Entry: ${event.data.priceOpen}, Current: ${event.currentPrice}`);
|
|
@@ -9524,6 +10011,111 @@ declare function listenSchedulePing(fn: (event: SchedulePingContract) => void):
|
|
|
9524
10011
|
* ```
|
|
9525
10012
|
*/
|
|
9526
10013
|
declare function listenSchedulePingOnce(filterFn: (event: SchedulePingContract) => boolean, fn: (event: SchedulePingContract) => void): () => void;
|
|
10014
|
+
/**
|
|
10015
|
+
* Subscribes to scheduled signal lifecycle events (creation and cancellation) with queued async processing.
|
|
10016
|
+
*
|
|
10017
|
+
* Emitted when a scheduled signal is created (action "scheduled") or cancelled before activation
|
|
10018
|
+
* (action "cancelled" with reason "timeout" / "price_reject" / "user"), in both live and backtest.
|
|
10019
|
+
*
|
|
10020
|
+
* IMPORTANT: The scheduled -> active transition (activation) is NOT reported here. Activation
|
|
10021
|
+
* produces an "opened" event on the regular signal emitters (listenSignal) instead.
|
|
10022
|
+
*
|
|
10023
|
+
* Events are processed sequentially in order received, even if callback is async.
|
|
10024
|
+
*
|
|
10025
|
+
* @param fn - Callback function to handle scheduled lifecycle events
|
|
10026
|
+
* @returns Unsubscribe function to stop listening
|
|
10027
|
+
*
|
|
10028
|
+
* @example
|
|
10029
|
+
* ```typescript
|
|
10030
|
+
* import { listenScheduleEvent } from "./function/event";
|
|
10031
|
+
*
|
|
10032
|
+
* const unsubscribe = listenScheduleEvent((event) => {
|
|
10033
|
+
* if (event.action === "scheduled") {
|
|
10034
|
+
* console.log(`Scheduled ${event.symbol} @ ${event.data.priceOpen}`);
|
|
10035
|
+
* } else {
|
|
10036
|
+
* console.log(`Cancelled ${event.symbol} (reason: ${event.reason})`);
|
|
10037
|
+
* }
|
|
10038
|
+
* });
|
|
10039
|
+
*
|
|
10040
|
+
* // Later: stop listening
|
|
10041
|
+
* unsubscribe();
|
|
10042
|
+
* ```
|
|
10043
|
+
*/
|
|
10044
|
+
declare function listenScheduleEvent(fn: (event: ScheduleEventContract) => void): () => void;
|
|
10045
|
+
/**
|
|
10046
|
+
* Subscribes to filtered scheduled lifecycle events with one-time execution.
|
|
10047
|
+
*
|
|
10048
|
+
* Listens for events matching the filter predicate, then executes callback once
|
|
10049
|
+
* and automatically unsubscribes. Useful for waiting for a specific scheduled creation
|
|
10050
|
+
* or cancellation.
|
|
10051
|
+
*
|
|
10052
|
+
* @param filterFn - Predicate to filter which events trigger the callback
|
|
10053
|
+
* @param fn - Callback function to handle the filtered event (called only once)
|
|
10054
|
+
* @returns Unsubscribe function to cancel the listener before it fires
|
|
10055
|
+
*
|
|
10056
|
+
* @example
|
|
10057
|
+
* ```typescript
|
|
10058
|
+
* import { listenScheduleEventOnce } from "./function/event";
|
|
10059
|
+
*
|
|
10060
|
+
* // Wait for the first cancellation on BTCUSDT
|
|
10061
|
+
* listenScheduleEventOnce(
|
|
10062
|
+
* (event) => event.symbol === "BTCUSDT" && event.action === "cancelled",
|
|
10063
|
+
* (event) => console.log("BTCUSDT scheduled cancelled:", event.reason)
|
|
10064
|
+
* );
|
|
10065
|
+
* ```
|
|
10066
|
+
*/
|
|
10067
|
+
declare function listenScheduleEventOnce(filterFn: (event: ScheduleEventContract) => boolean, fn: (event: ScheduleEventContract) => void): () => void;
|
|
10068
|
+
/**
|
|
10069
|
+
* Subscribes to pending signal lifecycle events (open and close) with queued async processing.
|
|
10070
|
+
*
|
|
10071
|
+
* Emitted when a pending position is opened (action "opened": new signal / immediate / scheduled
|
|
10072
|
+
* or user activation) or closed (action "closed" with closeReason "take_profit" / "stop_loss" /
|
|
10073
|
+
* "time_expired" / "closed"), in both live and backtest.
|
|
10074
|
+
*
|
|
10075
|
+
* Events are processed sequentially in order received, even if callback is async.
|
|
10076
|
+
*
|
|
10077
|
+
* @param fn - Callback function to handle pending lifecycle events
|
|
10078
|
+
* @returns Unsubscribe function to stop listening
|
|
10079
|
+
*
|
|
10080
|
+
* @example
|
|
10081
|
+
* ```typescript
|
|
10082
|
+
* import { listenSignalEvent } from "./function/event";
|
|
10083
|
+
*
|
|
10084
|
+
* const unsubscribe = listenSignalEvent((event) => {
|
|
10085
|
+
* if (event.action === "opened") {
|
|
10086
|
+
* console.log(`Opened ${event.symbol} @ ${event.data.priceOpen}`);
|
|
10087
|
+
* } else {
|
|
10088
|
+
* console.log(`Closed ${event.symbol} (reason: ${event.closeReason})`);
|
|
10089
|
+
* }
|
|
10090
|
+
* });
|
|
10091
|
+
*
|
|
10092
|
+
* // Later: stop listening
|
|
10093
|
+
* unsubscribe();
|
|
10094
|
+
* ```
|
|
10095
|
+
*/
|
|
10096
|
+
declare function listenSignalEvent(fn: (event: SignalEventContract) => void): () => void;
|
|
10097
|
+
/**
|
|
10098
|
+
* Subscribes to filtered pending lifecycle events with one-time execution.
|
|
10099
|
+
*
|
|
10100
|
+
* Listens for events matching the filter predicate, then executes callback once
|
|
10101
|
+
* and automatically unsubscribes. Useful for waiting for a specific open or close.
|
|
10102
|
+
*
|
|
10103
|
+
* @param filterFn - Predicate to filter which events trigger the callback
|
|
10104
|
+
* @param fn - Callback function to handle the filtered event (called only once)
|
|
10105
|
+
* @returns Unsubscribe function to cancel the listener before it fires
|
|
10106
|
+
*
|
|
10107
|
+
* @example
|
|
10108
|
+
* ```typescript
|
|
10109
|
+
* import { listenSignalEventOnce } from "./function/event";
|
|
10110
|
+
*
|
|
10111
|
+
* // Wait for the first close on BTCUSDT
|
|
10112
|
+
* listenSignalEventOnce(
|
|
10113
|
+
* (event) => event.symbol === "BTCUSDT" && event.action === "closed",
|
|
10114
|
+
* (event) => console.log("BTCUSDT closed:", event.closeReason)
|
|
10115
|
+
* );
|
|
10116
|
+
* ```
|
|
10117
|
+
*/
|
|
10118
|
+
declare function listenSignalEventOnce(filterFn: (event: SignalEventContract) => boolean, fn: (event: SignalEventContract) => void): () => void;
|
|
9527
10119
|
/**
|
|
9528
10120
|
* Subscribes to active ping events with queued async processing.
|
|
9529
10121
|
*
|
|
@@ -9675,7 +10267,7 @@ declare function listenStrategyCommitOnce(filterFn: (event: StrategyCommitContra
|
|
|
9675
10267
|
* @param fn - Callback function to handle sync events. If the function returns a promise, signal processing will wait until it resolves.
|
|
9676
10268
|
* @returns Unsubscribe function to stop listening
|
|
9677
10269
|
*/
|
|
9678
|
-
declare function listenSync(fn: (event:
|
|
10270
|
+
declare function listenSync(fn: (event: OrderSyncContract) => void, warned?: boolean): () => void;
|
|
9679
10271
|
/**
|
|
9680
10272
|
* Subscribes to filtered signal synchronization events with one-time execution.
|
|
9681
10273
|
* If throws position is not being opened/closed until the async function completes. Useful for synchronizing with external systems.
|
|
@@ -9684,7 +10276,30 @@ declare function listenSync(fn: (event: SignalSyncContract) => void, warned?: bo
|
|
|
9684
10276
|
* @param fn - Callback function to handle the filtered event (called only once). If the function returns a promise, signal processing will wait until it resolves.
|
|
9685
10277
|
* @returns Unsubscribe function to cancel the listener before it fires
|
|
9686
10278
|
*/
|
|
9687
|
-
declare function listenSyncOnce(filterFn: (event:
|
|
10279
|
+
declare function listenSyncOnce(filterFn: (event: OrderSyncContract) => boolean, fn: (event: OrderSyncContract) => void, warned?: boolean): () => void;
|
|
10280
|
+
/**
|
|
10281
|
+
* Subscribes to order-check ping events with queued async processing.
|
|
10282
|
+
* If throws, the order behind the monitored signal is treated as no longer open on the
|
|
10283
|
+
* exchange until the async function completes. Useful for synchronizing with external systems.
|
|
10284
|
+
*
|
|
10285
|
+
* Emits on every live tick while a signal is monitored, BEFORE completion evaluation,
|
|
10286
|
+
* discriminated by `event.type`: "active" — pending signal (open position), "schedule" —
|
|
10287
|
+
* scheduled signal (resting entry order). Backtest never emits this event.
|
|
10288
|
+
*
|
|
10289
|
+
* @param fn - Callback function to handle check events. If the function returns a promise, signal processing will wait until it resolves.
|
|
10290
|
+
* @returns Unsubscribe function to stop listening
|
|
10291
|
+
*/
|
|
10292
|
+
declare function listenCheck(fn: (event: OrderCheckContract) => void, warned?: boolean): () => void;
|
|
10293
|
+
/**
|
|
10294
|
+
* Subscribes to filtered order-check ping events with one-time execution.
|
|
10295
|
+
* If throws, the order behind the monitored signal is treated as no longer open on the
|
|
10296
|
+
* exchange until the async function completes. Useful for synchronizing with external systems.
|
|
10297
|
+
*
|
|
10298
|
+
* @param filterFn - Predicate to filter which events trigger the callback
|
|
10299
|
+
* @param fn - Callback function to handle the filtered event (called only once). If the function returns a promise, signal processing will wait until it resolves.
|
|
10300
|
+
* @returns Unsubscribe function to cancel the listener before it fires
|
|
10301
|
+
*/
|
|
10302
|
+
declare function listenCheckOnce(filterFn: (event: OrderCheckContract) => boolean, fn: (event: OrderCheckContract) => void, warned?: boolean): () => void;
|
|
9688
10303
|
/**
|
|
9689
10304
|
* Subscribes to highest profit events with queued async processing.
|
|
9690
10305
|
* Emits when a signal reaches a new highest profit level during its lifecycle.
|
|
@@ -10166,8 +10781,8 @@ declare function getMinutesSinceLatestSignalCreated(symbol: string): Promise<num
|
|
|
10166
10781
|
/**
|
|
10167
10782
|
* Reads the state value scoped to the current active signal.
|
|
10168
10783
|
*
|
|
10169
|
-
* Resolves the active pending signal automatically from execution context.
|
|
10170
|
-
*
|
|
10784
|
+
* Resolves the active pending or scheduled signal automatically from execution context.
|
|
10785
|
+
* Throws if neither a pending nor a scheduled signal exists.
|
|
10171
10786
|
*
|
|
10172
10787
|
* Automatically detects backtest/live mode from execution context.
|
|
10173
10788
|
*
|
|
@@ -10204,8 +10819,8 @@ declare function getSignalState<Value extends object = object>(symbol: string, d
|
|
|
10204
10819
|
/**
|
|
10205
10820
|
* Updates the state value scoped to the current active signal.
|
|
10206
10821
|
*
|
|
10207
|
-
* Resolves the active pending signal automatically from execution context.
|
|
10208
|
-
*
|
|
10822
|
+
* Resolves the active pending or scheduled signal automatically from execution context.
|
|
10823
|
+
* Throws if neither a pending nor a scheduled signal exists.
|
|
10209
10824
|
*
|
|
10210
10825
|
* Automatically detects backtest/live mode from execution context.
|
|
10211
10826
|
*
|
|
@@ -12220,7 +12835,7 @@ interface TrailingTakeCommitNotification {
|
|
|
12220
12835
|
* Signal sync open notification.
|
|
12221
12836
|
* Emitted when a scheduled (limit order) signal is activated and the position is opened.
|
|
12222
12837
|
*/
|
|
12223
|
-
interface
|
|
12838
|
+
interface OrderSyncOpenNotification {
|
|
12224
12839
|
/** Discriminator for type-safe union */
|
|
12225
12840
|
type: "signal_sync.open";
|
|
12226
12841
|
/** Unique notification identifier */
|
|
@@ -12308,7 +12923,7 @@ interface SignalSyncOpenNotification {
|
|
|
12308
12923
|
* Signal sync close notification.
|
|
12309
12924
|
* Emitted when an active pending signal is closed (TP/SL hit, time expired, or user-initiated).
|
|
12310
12925
|
*/
|
|
12311
|
-
interface
|
|
12926
|
+
interface OrderSyncCloseNotification {
|
|
12312
12927
|
/** Discriminator for type-safe union */
|
|
12313
12928
|
type: "signal_sync.close";
|
|
12314
12929
|
/** Unique notification identifier */
|
|
@@ -12878,7 +13493,7 @@ interface SignalInfoNotification {
|
|
|
12878
13493
|
* }
|
|
12879
13494
|
* ```
|
|
12880
13495
|
*/
|
|
12881
|
-
type NotificationModel = SignalOpenedNotification | SignalClosedNotification | PartialProfitAvailableNotification | PartialLossAvailableNotification | BreakevenAvailableNotification | PartialProfitCommitNotification | PartialLossCommitNotification | BreakevenCommitNotification | AverageBuyCommitNotification | ActivateScheduledCommitNotification | TrailingStopCommitNotification | TrailingTakeCommitNotification | CancelScheduledCommitNotification | ClosePendingCommitNotification |
|
|
13496
|
+
type NotificationModel = SignalOpenedNotification | SignalClosedNotification | PartialProfitAvailableNotification | PartialLossAvailableNotification | BreakevenAvailableNotification | PartialProfitCommitNotification | PartialLossCommitNotification | BreakevenCommitNotification | AverageBuyCommitNotification | ActivateScheduledCommitNotification | TrailingStopCommitNotification | TrailingTakeCommitNotification | CancelScheduledCommitNotification | ClosePendingCommitNotification | OrderSyncOpenNotification | OrderSyncCloseNotification | RiskRejectionNotification | SignalScheduledNotification | SignalCancelledNotification | InfoErrorNotification | CriticalErrorNotification | ValidationErrorNotification | SignalInfoNotification;
|
|
12882
13497
|
|
|
12883
13498
|
/**
|
|
12884
13499
|
* Unified tick event data for report generation.
|
|
@@ -14350,6 +14965,18 @@ type StrategyData = {
|
|
|
14350
14965
|
cancelledSignal: IScheduledSignalCancelRow | null;
|
|
14351
14966
|
/** Deferred user-initiated scheduled activate (activateScheduled), or null if none pending */
|
|
14352
14967
|
activatedSignal: IScheduledSignalActivateRow | null;
|
|
14968
|
+
/**
|
|
14969
|
+
* Deferred broker-confirmed take-profit fill (createTakeProfit), or null if none pending.
|
|
14970
|
+
* Set when the exchange reports the TP order was actually filled (e.g. by candle high/low),
|
|
14971
|
+
* independent of the VWAP-based TP check. Drained on the next tick to close with "take_profit".
|
|
14972
|
+
*/
|
|
14973
|
+
takeProfitSignal: ISignalCloseRow | null;
|
|
14974
|
+
/**
|
|
14975
|
+
* Deferred broker-confirmed stop-loss fill (createStopLoss), or null if none pending.
|
|
14976
|
+
* Set when the exchange reports the SL order was actually filled (e.g. by candle high/low),
|
|
14977
|
+
* independent of the VWAP-based SL check. Drained on the next tick to close with "stop_loss".
|
|
14978
|
+
*/
|
|
14979
|
+
stopLossSignal: ISignalCloseRow | null;
|
|
14353
14980
|
};
|
|
14354
14981
|
/**
|
|
14355
14982
|
* Per-context deferred strategy state persistence instance interface.
|
|
@@ -16106,6 +16733,8 @@ declare class PersistMemoryInstance implements IPersistMemoryInstance {
|
|
|
16106
16733
|
writeMemoryData(data: MemoryData, memoryId: string, _when: Date): Promise<void>;
|
|
16107
16734
|
/**
|
|
16108
16735
|
* Soft-deletes a memory entry by writing `removed: true` flag.
|
|
16736
|
+
* No-op when the entry does not exist (readValue throws on a missing
|
|
16737
|
+
* entity, so existence must be checked first to keep removal idempotent).
|
|
16109
16738
|
*
|
|
16110
16739
|
* @param memoryId - Memory entry identifier
|
|
16111
16740
|
* @returns Promise that resolves when removal is complete
|
|
@@ -16702,16 +17331,27 @@ declare class PersistSessionInstance implements IPersistSessionInstance {
|
|
|
16702
17331
|
readonly strategyName: string;
|
|
16703
17332
|
readonly exchangeName: string;
|
|
16704
17333
|
readonly frameName: string;
|
|
17334
|
+
readonly symbol: string;
|
|
17335
|
+
readonly backtest: boolean;
|
|
16705
17336
|
/** Underlying file-based storage scoped to this context */
|
|
16706
17337
|
private readonly _storage;
|
|
17338
|
+
/**
|
|
17339
|
+
* Entity key inside the per-strategy/exchange/frame storage directory.
|
|
17340
|
+
* Includes the symbol and backtest flag: without them two symbols running
|
|
17341
|
+
* the same strategy would clobber one shared record and restore each
|
|
17342
|
+
* other's session state after a restart.
|
|
17343
|
+
*/
|
|
17344
|
+
private readonly _entityId;
|
|
16707
17345
|
/**
|
|
16708
17346
|
* Creates new session persistence instance.
|
|
16709
17347
|
*
|
|
16710
17348
|
* @param strategyName - Strategy identifier
|
|
16711
17349
|
* @param exchangeName - Exchange identifier
|
|
16712
|
-
* @param frameName - Frame identifier (
|
|
17350
|
+
* @param frameName - Frame identifier (storage subdirectory)
|
|
17351
|
+
* @param symbol - Trading pair symbol (part of the entity key)
|
|
17352
|
+
* @param backtest - Whether the session belongs to a backtest run (part of the entity key)
|
|
16713
17353
|
*/
|
|
16714
|
-
constructor(strategyName: string, exchangeName: string, frameName: string);
|
|
17354
|
+
constructor(strategyName: string, exchangeName: string, frameName: string, symbol: string, backtest: boolean);
|
|
16715
17355
|
/**
|
|
16716
17356
|
* Initializes the underlying PersistBase storage.
|
|
16717
17357
|
*
|
|
@@ -16720,13 +17360,13 @@ declare class PersistSessionInstance implements IPersistSessionInstance {
|
|
|
16720
17360
|
*/
|
|
16721
17361
|
waitForInit(initial: boolean): Promise<void>;
|
|
16722
17362
|
/**
|
|
16723
|
-
* Reads the persisted session data using
|
|
17363
|
+
* Reads the persisted session data using the per-symbol entity key.
|
|
16724
17364
|
*
|
|
16725
17365
|
* @returns Promise resolving to session data or null if not found
|
|
16726
17366
|
*/
|
|
16727
17367
|
readSessionData(): Promise<SessionData | null>;
|
|
16728
17368
|
/**
|
|
16729
|
-
* Writes the session data using
|
|
17369
|
+
* Writes the session data using the per-symbol entity key.
|
|
16730
17370
|
*
|
|
16731
17371
|
* @param data - Session data to persist
|
|
16732
17372
|
* @returns Promise that resolves when write is complete
|
|
@@ -16742,7 +17382,7 @@ declare class PersistSessionInstance implements IPersistSessionInstance {
|
|
|
16742
17382
|
* Constructor type for IPersistSessionInstance.
|
|
16743
17383
|
* Used by PersistSessionUtils.usePersistSessionAdapter() to register custom adapters.
|
|
16744
17384
|
*/
|
|
16745
|
-
type TPersistSessionInstanceCtor = new (strategyName: string, exchangeName: string, frameName: string) => IPersistSessionInstance;
|
|
17385
|
+
type TPersistSessionInstanceCtor = new (strategyName: string, exchangeName: string, frameName: string, symbol: string, backtest: boolean) => IPersistSessionInstance;
|
|
16746
17386
|
/**
|
|
16747
17387
|
* Utility class for managing session persistence.
|
|
16748
17388
|
*
|
|
@@ -16763,9 +17403,14 @@ declare class PersistSessionUtils {
|
|
|
16763
17403
|
private PersistSessionInstanceCtor;
|
|
16764
17404
|
/**
|
|
16765
17405
|
* Memoized factory creating one IPersistSessionInstance per
|
|
16766
|
-
* (strategyName, exchangeName, frameName)
|
|
17406
|
+
* (strategyName, exchangeName, frameName, symbol, backtest) tuple.
|
|
16767
17407
|
*/
|
|
16768
17408
|
private getSessionStorage;
|
|
17409
|
+
/**
|
|
17410
|
+
* Builds the memoization key for the given context.
|
|
17411
|
+
* Kept in sync with the getSessionStorage key function.
|
|
17412
|
+
*/
|
|
17413
|
+
private static GET_KEY_FN;
|
|
16769
17414
|
/**
|
|
16770
17415
|
* Registers a custom IPersistSessionInstance constructor.
|
|
16771
17416
|
* Clears the memoization cache so subsequent calls use the new adapter.
|
|
@@ -16783,7 +17428,7 @@ declare class PersistSessionUtils {
|
|
|
16783
17428
|
* @param initial - Whether this is the first initialization
|
|
16784
17429
|
* @returns Promise that resolves when initialization is complete
|
|
16785
17430
|
*/
|
|
16786
|
-
waitForInit: (strategyName: string, exchangeName: string, frameName: string, initial: boolean) => Promise<void>;
|
|
17431
|
+
waitForInit: (strategyName: string, exchangeName: string, frameName: string, initial: boolean, symbol: string, backtest: boolean) => Promise<void>;
|
|
16787
17432
|
/**
|
|
16788
17433
|
* Reads persisted session data for the given context.
|
|
16789
17434
|
* Lazily initializes the instance on first access.
|
|
@@ -16793,7 +17438,7 @@ declare class PersistSessionUtils {
|
|
|
16793
17438
|
* @param frameName - Frame identifier
|
|
16794
17439
|
* @returns Promise resolving to session data or null if none persisted
|
|
16795
17440
|
*/
|
|
16796
|
-
readSessionData: (strategyName: string, exchangeName: string, frameName: string) => Promise<SessionData | null>;
|
|
17441
|
+
readSessionData: (strategyName: string, exchangeName: string, frameName: string, symbol: string, backtest: boolean) => Promise<SessionData | null>;
|
|
16797
17442
|
/**
|
|
16798
17443
|
* Writes session data for the given context.
|
|
16799
17444
|
* Lazily initializes the instance on first access.
|
|
@@ -16805,7 +17450,7 @@ declare class PersistSessionUtils {
|
|
|
16805
17450
|
* @param when - Logical timestamp this value belongs to (duplicates `data.when` for API consistency)
|
|
16806
17451
|
* @returns Promise that resolves when write is complete
|
|
16807
17452
|
*/
|
|
16808
|
-
writeSessionData: (data: SessionData, strategyName: string, exchangeName: string, frameName: string, when: Date) => Promise<void>;
|
|
17453
|
+
writeSessionData: (data: SessionData, strategyName: string, exchangeName: string, frameName: string, when: Date, symbol: string, backtest: boolean) => Promise<void>;
|
|
16809
17454
|
/**
|
|
16810
17455
|
* Switches to PersistSessionDummyInstance (all operations are no-ops).
|
|
16811
17456
|
*/
|
|
@@ -16827,7 +17472,7 @@ declare class PersistSessionUtils {
|
|
|
16827
17472
|
* @param exchangeName - Exchange identifier
|
|
16828
17473
|
* @param frameName - Frame identifier
|
|
16829
17474
|
*/
|
|
16830
|
-
dispose: (strategyName: string, exchangeName: string, frameName: string) => void;
|
|
17475
|
+
dispose: (strategyName: string, exchangeName: string, frameName: string, symbol: string, backtest: boolean) => void;
|
|
16831
17476
|
}
|
|
16832
17477
|
/**
|
|
16833
17478
|
* Global singleton instance of PersistSessionUtils.
|
|
@@ -18979,6 +19624,62 @@ declare class BacktestUtils {
|
|
|
18979
19624
|
exchangeName: ExchangeName;
|
|
18980
19625
|
frameName: FrameName;
|
|
18981
19626
|
}, dto: ISignalDto) => Promise<void>;
|
|
19627
|
+
/**
|
|
19628
|
+
* Reports that the pending position's take-profit order was actually filled on the exchange
|
|
19629
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based TP check.
|
|
19630
|
+
*
|
|
19631
|
+
* The exchange and the strategy are parallel states: the framework evaluates TP/SL against VWAP,
|
|
19632
|
+
* but the real order may fill on high/low. The close is deferred and emitted with closeReason
|
|
19633
|
+
* "take_profit" on the next backtest tick. No-op if no pending signal exists.
|
|
19634
|
+
*
|
|
19635
|
+
* @param symbol - Trading pair symbol
|
|
19636
|
+
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
19637
|
+
* @param payload - Optional commit payload with id and note
|
|
19638
|
+
* @returns Promise that resolves when the take-profit fill is queued
|
|
19639
|
+
*
|
|
19640
|
+
* @example
|
|
19641
|
+
* ```typescript
|
|
19642
|
+
* // Report TP fill confirmed on the exchange
|
|
19643
|
+
* await Backtest.commitCreateTakeProfit("BTCUSDT", {
|
|
19644
|
+
* exchangeName: "binance",
|
|
19645
|
+
* strategyName: "my-strategy",
|
|
19646
|
+
* frameName: "1m"
|
|
19647
|
+
* }, { id: "tp-fill-001" });
|
|
19648
|
+
* ```
|
|
19649
|
+
*/
|
|
19650
|
+
commitCreateTakeProfit: (symbol: string, context: {
|
|
19651
|
+
strategyName: StrategyName;
|
|
19652
|
+
exchangeName: ExchangeName;
|
|
19653
|
+
frameName: FrameName;
|
|
19654
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
19655
|
+
/**
|
|
19656
|
+
* Reports that the pending position's stop-loss order was actually filled on the exchange
|
|
19657
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based SL check.
|
|
19658
|
+
*
|
|
19659
|
+
* The exchange and the strategy are parallel states: the framework evaluates TP/SL against VWAP,
|
|
19660
|
+
* but the real order may fill on high/low. The close is deferred and emitted with closeReason
|
|
19661
|
+
* "stop_loss" on the next backtest tick. No-op if no pending signal exists.
|
|
19662
|
+
*
|
|
19663
|
+
* @param symbol - Trading pair symbol
|
|
19664
|
+
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
19665
|
+
* @param payload - Optional commit payload with id and note
|
|
19666
|
+
* @returns Promise that resolves when the stop-loss fill is queued
|
|
19667
|
+
*
|
|
19668
|
+
* @example
|
|
19669
|
+
* ```typescript
|
|
19670
|
+
* // Report SL fill confirmed on the exchange
|
|
19671
|
+
* await Backtest.commitCreateStopLoss("BTCUSDT", {
|
|
19672
|
+
* exchangeName: "binance",
|
|
19673
|
+
* strategyName: "my-strategy",
|
|
19674
|
+
* frameName: "1m"
|
|
19675
|
+
* }, { id: "sl-fill-001" });
|
|
19676
|
+
* ```
|
|
19677
|
+
*/
|
|
19678
|
+
commitCreateStopLoss: (symbol: string, context: {
|
|
19679
|
+
strategyName: StrategyName;
|
|
19680
|
+
exchangeName: ExchangeName;
|
|
19681
|
+
frameName: FrameName;
|
|
19682
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
18982
19683
|
/**
|
|
18983
19684
|
* Returns the in-memory deferred strategy-state snapshot for the current backtest iteration.
|
|
18984
19685
|
*
|
|
@@ -20489,6 +21190,40 @@ declare class LiveUtils {
|
|
|
20489
21190
|
strategyName: StrategyName;
|
|
20490
21191
|
exchangeName: ExchangeName;
|
|
20491
21192
|
}, dto: ISignalDto) => Promise<void>;
|
|
21193
|
+
/**
|
|
21194
|
+
* Reports that the pending position's take-profit order was actually filled on the exchange
|
|
21195
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based TP check.
|
|
21196
|
+
*
|
|
21197
|
+
* The exchange and the strategy are parallel states: the framework evaluates TP/SL against VWAP,
|
|
21198
|
+
* but the real order may fill on high/low. The close is deferred and emitted with closeReason
|
|
21199
|
+
* "take_profit" on the next live tick. No-op if no pending signal exists.
|
|
21200
|
+
*
|
|
21201
|
+
* @param symbol - Trading pair symbol
|
|
21202
|
+
* @param context - Execution context with strategyName and exchangeName
|
|
21203
|
+
* @param payload - Optional commit payload with id and note
|
|
21204
|
+
* @returns Promise that resolves when the take-profit fill is queued
|
|
21205
|
+
*/
|
|
21206
|
+
commitCreateTakeProfit: (symbol: string, context: {
|
|
21207
|
+
strategyName: StrategyName;
|
|
21208
|
+
exchangeName: ExchangeName;
|
|
21209
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
21210
|
+
/**
|
|
21211
|
+
* Reports that the pending position's stop-loss order was actually filled on the exchange
|
|
21212
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based SL check.
|
|
21213
|
+
*
|
|
21214
|
+
* The exchange and the strategy are parallel states: the framework evaluates TP/SL against VWAP,
|
|
21215
|
+
* but the real order may fill on high/low. The close is deferred and emitted with closeReason
|
|
21216
|
+
* "stop_loss" on the next live tick. No-op if no pending signal exists.
|
|
21217
|
+
*
|
|
21218
|
+
* @param symbol - Trading pair symbol
|
|
21219
|
+
* @param context - Execution context with strategyName and exchangeName
|
|
21220
|
+
* @param payload - Optional commit payload with id and note
|
|
21221
|
+
* @returns Promise that resolves when the stop-loss fill is queued
|
|
21222
|
+
*/
|
|
21223
|
+
commitCreateStopLoss: (symbol: string, context: {
|
|
21224
|
+
strategyName: StrategyName;
|
|
21225
|
+
exchangeName: ExchangeName;
|
|
21226
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
20492
21227
|
/**
|
|
20493
21228
|
* Returns the in-memory deferred strategy-state snapshot for the current live iteration.
|
|
20494
21229
|
*
|
|
@@ -24398,7 +25133,7 @@ declare class SyncMarkdownService {
|
|
|
24398
25133
|
private readonly loggerService;
|
|
24399
25134
|
private getStorage;
|
|
24400
25135
|
/**
|
|
24401
|
-
* Subscribes to `syncSubject` to start receiving `
|
|
25136
|
+
* Subscribes to `syncSubject` to start receiving `OrderSyncContract` events.
|
|
24402
25137
|
* Protected against multiple subscriptions via `singleshot` — subsequent calls
|
|
24403
25138
|
* return the same unsubscribe function without re-subscribing.
|
|
24404
25139
|
*
|
|
@@ -24433,7 +25168,7 @@ declare class SyncMarkdownService {
|
|
|
24433
25168
|
*/
|
|
24434
25169
|
unsubscribe: () => Promise<void>;
|
|
24435
25170
|
/**
|
|
24436
|
-
* Handles a single `
|
|
25171
|
+
* Handles a single `OrderSyncContract` event emitted by `syncSubject`.
|
|
24437
25172
|
*
|
|
24438
25173
|
* Maps the contract fields to a `SyncEvent`, enriching it with a
|
|
24439
25174
|
* `createdAt` ISO timestamp from `getContextTimestamp()` (backtest clock
|
|
@@ -24444,8 +25179,8 @@ declare class SyncMarkdownService {
|
|
|
24444
25179
|
* Routes the constructed event to the appropriate `ReportStorage` bucket
|
|
24445
25180
|
* via `getStorage(symbol, strategyName, exchangeName, frameName, backtest)`.
|
|
24446
25181
|
*
|
|
24447
|
-
* @param data - Discriminated union `
|
|
24448
|
-
* (`
|
|
25182
|
+
* @param data - Discriminated union `OrderSyncContract`
|
|
25183
|
+
* (`OrderOpenContract | OrderCloseContract`)
|
|
24449
25184
|
*/
|
|
24450
25185
|
private tick;
|
|
24451
25186
|
/**
|
|
@@ -24726,8 +25461,8 @@ type TStorageUtilsCtor = new () => IStorageUtils;
|
|
|
24726
25461
|
*
|
|
24727
25462
|
* Features:
|
|
24728
25463
|
* - Adapter pattern for swappable storage implementations
|
|
24729
|
-
* - Default adapter:
|
|
24730
|
-
* - Alternative adapters:
|
|
25464
|
+
* - Default adapter: StorageMemoryBacktestUtils (in-memory storage)
|
|
25465
|
+
* - Alternative adapters: StoragePersistBacktestUtils, StorageDummyBacktestUtils
|
|
24731
25466
|
* - Convenience methods: usePersist(), useMemory(), useDummy()
|
|
24732
25467
|
*/
|
|
24733
25468
|
declare class StorageBacktestAdapter implements IStorageUtils {
|
|
@@ -25274,7 +26009,7 @@ interface INotificationTarget {
|
|
|
25274
26009
|
* Signal synchronization events for live trading (`signal_sync.open`, `signal_sync.close`).
|
|
25275
26010
|
* Fired when a limit order is confirmed filled (`signal-open`) or when an open
|
|
25276
26011
|
* position is confirmed exited (`signal-close`) by the exchange sync layer.
|
|
25277
|
-
* Source: `syncSubject` (
|
|
26012
|
+
* Source: `syncSubject` (OrderSyncContract).
|
|
25278
26013
|
*/
|
|
25279
26014
|
signal_sync: boolean;
|
|
25280
26015
|
/**
|
|
@@ -25345,7 +26080,7 @@ interface INotificationUtils {
|
|
|
25345
26080
|
* Handles signal sync event (signal-open, signal-close).
|
|
25346
26081
|
* @param data - The signal sync contract data
|
|
25347
26082
|
*/
|
|
25348
|
-
handleSync(data:
|
|
26083
|
+
handleSync(data: OrderSyncContract): Promise<void>;
|
|
25349
26084
|
/**
|
|
25350
26085
|
* Handles risk rejection event.
|
|
25351
26086
|
* @param data - The risk contract data
|
|
@@ -25437,7 +26172,7 @@ declare class NotificationBacktestAdapter implements INotificationUtils {
|
|
|
25437
26172
|
* Proxies call to the underlying notification adapter.
|
|
25438
26173
|
* @param data - The signal sync contract data
|
|
25439
26174
|
*/
|
|
25440
|
-
handleSync: (data:
|
|
26175
|
+
handleSync: (data: OrderSyncContract) => any;
|
|
25441
26176
|
/**
|
|
25442
26177
|
* Handles risk rejection event.
|
|
25443
26178
|
* Proxies call to the underlying notification adapter.
|
|
@@ -25558,7 +26293,7 @@ declare class NotificationLiveAdapter implements INotificationUtils {
|
|
|
25558
26293
|
* Proxies call to the underlying notification adapter.
|
|
25559
26294
|
* @param data - The signal sync contract data
|
|
25560
26295
|
*/
|
|
25561
|
-
handleSync: (data:
|
|
26296
|
+
handleSync: (data: OrderSyncContract) => any;
|
|
25562
26297
|
/**
|
|
25563
26298
|
* Handles risk rejection event.
|
|
25564
26299
|
* Proxies call to the underlying notification adapter.
|
|
@@ -26450,7 +27185,8 @@ declare class ExchangeUtils {
|
|
|
26450
27185
|
/**
|
|
26451
27186
|
* Fetches raw candles with flexible date/limit parameters.
|
|
26452
27187
|
*
|
|
26453
|
-
*
|
|
27188
|
+
* Look-ahead bias protection: the reference "now" is execution context `when`
|
|
27189
|
+
* when a context is active (backtest), otherwise the current wall-clock time.
|
|
26454
27190
|
*
|
|
26455
27191
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
26456
27192
|
* @param interval - Candle interval (e.g., "1m", "1h")
|
|
@@ -28684,12 +29420,18 @@ declare class ActionBase implements IPublicAction {
|
|
|
28684
29420
|
/**
|
|
28685
29421
|
* Payload for the signal-open broker event.
|
|
28686
29422
|
*
|
|
28687
|
-
* Emitted automatically via syncSubject
|
|
28688
|
-
*
|
|
29423
|
+
* Emitted automatically via syncSubject and forwarded to the registered IBroker adapter via
|
|
29424
|
+
* `onOrderOpenCommit`. Discriminated by `type`:
|
|
29425
|
+
* - "active" — a pending signal is being opened (immediate entry or activation fill of the
|
|
29426
|
+
* resting order); throw = the exchange did not fill the entry, the framework rolls back the
|
|
29427
|
+
* open and retries on the next tick;
|
|
29428
|
+
* - "schedule" — the resting entry order is being PLACED (scheduled signal creation); throw =
|
|
29429
|
+
* the exchange did not accept the resting order, the scheduled signal is NOT registered and
|
|
29430
|
+
* the placement retries on the next tick.
|
|
28689
29431
|
*
|
|
28690
29432
|
* @example
|
|
28691
29433
|
* ```typescript
|
|
28692
|
-
* const payload:
|
|
29434
|
+
* const payload: BrokerOrderOpenPayload = {
|
|
28693
29435
|
* symbol: "BTCUSDT",
|
|
28694
29436
|
* cost: 100,
|
|
28695
29437
|
* position: "long",
|
|
@@ -28701,7 +29443,9 @@ declare class ActionBase implements IPublicAction {
|
|
|
28701
29443
|
* };
|
|
28702
29444
|
* ```
|
|
28703
29445
|
*/
|
|
28704
|
-
type
|
|
29446
|
+
type BrokerOrderOpenPayload = {
|
|
29447
|
+
/** Which order is being opened: "active" — position entry, "schedule" — resting entry order placement */
|
|
29448
|
+
type: "schedule" | "active";
|
|
28705
29449
|
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
28706
29450
|
symbol: string;
|
|
28707
29451
|
/** Unique signal identifier (UUID v4) the order belongs to */
|
|
@@ -28735,11 +29479,11 @@ type BrokerSignalOpenPayload = {
|
|
|
28735
29479
|
* Payload for the signal-close broker event.
|
|
28736
29480
|
*
|
|
28737
29481
|
* Emitted automatically via syncSubject when a pending signal is closed (SL/TP hit or manual close).
|
|
28738
|
-
* Forwarded to the registered IBroker adapter via `
|
|
29482
|
+
* Forwarded to the registered IBroker adapter via `onOrderCloseCommit`.
|
|
28739
29483
|
*
|
|
28740
29484
|
* @example
|
|
28741
29485
|
* ```typescript
|
|
28742
|
-
* const payload:
|
|
29486
|
+
* const payload: BrokerOrderClosePayload = {
|
|
28743
29487
|
* symbol: "BTCUSDT",
|
|
28744
29488
|
* cost: 100,
|
|
28745
29489
|
* position: "long",
|
|
@@ -28754,7 +29498,7 @@ type BrokerSignalOpenPayload = {
|
|
|
28754
29498
|
* };
|
|
28755
29499
|
* ```
|
|
28756
29500
|
*/
|
|
28757
|
-
type
|
|
29501
|
+
type BrokerOrderClosePayload = {
|
|
28758
29502
|
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
28759
29503
|
symbol: string;
|
|
28760
29504
|
/** Unique signal identifier (UUID v4) the order belongs to */
|
|
@@ -28791,16 +29535,25 @@ type BrokerSignalClosePayload = {
|
|
|
28791
29535
|
backtest: boolean;
|
|
28792
29536
|
};
|
|
28793
29537
|
/**
|
|
28794
|
-
* Payload for the
|
|
29538
|
+
* Payload for the order synchronization broker event.
|
|
28795
29539
|
*
|
|
28796
|
-
* Emitted automatically via syncPendingSubject on every live tick while a
|
|
28797
|
-
*
|
|
28798
|
-
*
|
|
29540
|
+
* Emitted automatically via syncPendingSubject on every live tick while a signal is monitored,
|
|
29541
|
+
* BEFORE the framework evaluates completion. Forwarded to the registered IBroker adapter,
|
|
29542
|
+
* routed by `type` to the matching callback:
|
|
29543
|
+
* - `type: "active"` — pending signal (open position), before TP/SL/time evaluation —
|
|
29544
|
+
* delivered to `onOrderActiveCheck`;
|
|
29545
|
+
* - `type: "schedule"` — scheduled signal, before timeout/price-activation evaluation
|
|
29546
|
+
* (the order in question is the resting entry order) — delivered to `onOrderScheduleCheck`.
|
|
28799
29547
|
*
|
|
28800
29548
|
* The adapter should query the exchange by `signalId` and THROW ONLY when the order is
|
|
28801
29549
|
* definitively NOT FOUND by that id (filled, cancelled, or liquidated externally). A throw
|
|
28802
29550
|
* propagates to CREATE_SYNC_PENDING_FN, which makes the framework close the pending signal with
|
|
28803
|
-
* closeReason "closed"
|
|
29551
|
+
* closeReason "closed" (type "active") or cancel the scheduled signal with reason "user"
|
|
29552
|
+
* (type "schedule"). Returning normally keeps the signal under normal monitoring.
|
|
29553
|
+
*
|
|
29554
|
+
* NOTE for type "schedule": if the resting entry order actually FILLED, confirm the fill via
|
|
29555
|
+
* `commitActivateScheduled` instead of throwing — a throw here is a terminal cancel, not an
|
|
29556
|
+
* activation.
|
|
28804
29557
|
*
|
|
28805
29558
|
* CRITICAL: transient/network errors (timeout, 5xx, rate limit, disconnect) must be SWALLOWED —
|
|
28806
29559
|
* return normally instead of throwing. A thrown network error would wrongly close an open
|
|
@@ -28808,7 +29561,7 @@ type BrokerSignalClosePayload = {
|
|
|
28808
29561
|
*
|
|
28809
29562
|
* @example
|
|
28810
29563
|
* ```typescript
|
|
28811
|
-
* const payload:
|
|
29564
|
+
* const payload: BrokerOrderCheckPayload = {
|
|
28812
29565
|
* symbol: "BTCUSDT",
|
|
28813
29566
|
* position: "long",
|
|
28814
29567
|
* currentPrice: 50500,
|
|
@@ -28820,7 +29573,9 @@ type BrokerSignalClosePayload = {
|
|
|
28820
29573
|
* };
|
|
28821
29574
|
* ```
|
|
28822
29575
|
*/
|
|
28823
|
-
type
|
|
29576
|
+
type BrokerOrderCheckPayload = {
|
|
29577
|
+
/** Monitored state: "active" — open position order, "schedule" — resting entry order */
|
|
29578
|
+
type: "schedule" | "active";
|
|
28824
29579
|
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
28825
29580
|
symbol: string;
|
|
28826
29581
|
/** Unique signal identifier (UUID v4) the order belongs to */
|
|
@@ -28854,6 +29609,316 @@ type BrokerSignalPendingPayload = {
|
|
|
28854
29609
|
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
28855
29610
|
backtest: boolean;
|
|
28856
29611
|
};
|
|
29612
|
+
/**
|
|
29613
|
+
* Payload for the active-ping broker event.
|
|
29614
|
+
*
|
|
29615
|
+
* Emitted automatically via activePingSubject on every live tick while a pending (open) signal is
|
|
29616
|
+
* monitored. Forwarded to the registered IBroker adapter via `onSignalActivePing`. Purely
|
|
29617
|
+
* informational — unlike `onOrderActiveCheck` a throw here does NOT close the position.
|
|
29618
|
+
*
|
|
29619
|
+
* @example
|
|
29620
|
+
* ```typescript
|
|
29621
|
+
* const payload: BrokerActivePingPayload = {
|
|
29622
|
+
* symbol: "BTCUSDT",
|
|
29623
|
+
* position: "long",
|
|
29624
|
+
* currentPrice: 50500,
|
|
29625
|
+
* priceOpen: 50000,
|
|
29626
|
+
* priceTakeProfit: 55000,
|
|
29627
|
+
* priceStopLoss: 48000,
|
|
29628
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29629
|
+
* backtest: false,
|
|
29630
|
+
* };
|
|
29631
|
+
* ```
|
|
29632
|
+
*/
|
|
29633
|
+
type BrokerActivePingPayload = {
|
|
29634
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29635
|
+
symbol: string;
|
|
29636
|
+
/** Unique signal identifier (UUID v4) of the monitored position */
|
|
29637
|
+
signalId: string;
|
|
29638
|
+
/** Position direction */
|
|
29639
|
+
position: "long" | "short";
|
|
29640
|
+
/** Market price at the moment of the ping */
|
|
29641
|
+
currentPrice: number;
|
|
29642
|
+
/** Effective entry price (may differ from priceOpen after DCA averaging) */
|
|
29643
|
+
priceOpen: number;
|
|
29644
|
+
/** Effective take-profit price at the moment of the ping */
|
|
29645
|
+
priceTakeProfit: number;
|
|
29646
|
+
/** Effective stop-loss price at the moment of the ping */
|
|
29647
|
+
priceStopLoss: number;
|
|
29648
|
+
/** Unrealized PnL of the open position at the moment of the ping */
|
|
29649
|
+
pnl: IStrategyPnL;
|
|
29650
|
+
/** Strategy/exchange/frame routing context */
|
|
29651
|
+
context: {
|
|
29652
|
+
strategyName: StrategyName;
|
|
29653
|
+
exchangeName: ExchangeName;
|
|
29654
|
+
frameName?: FrameName;
|
|
29655
|
+
};
|
|
29656
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29657
|
+
backtest: boolean;
|
|
29658
|
+
};
|
|
29659
|
+
/**
|
|
29660
|
+
* Payload for the schedule-ping broker event.
|
|
29661
|
+
*
|
|
29662
|
+
* Emitted automatically via schedulePingSubject on every live tick while a scheduled signal is
|
|
29663
|
+
* monitored (waiting for priceOpen activation). Forwarded to the registered IBroker adapter via
|
|
29664
|
+
* `onSignalSchedulePing`. Purely informational.
|
|
29665
|
+
*
|
|
29666
|
+
* @example
|
|
29667
|
+
* ```typescript
|
|
29668
|
+
* const payload: BrokerSchedulePingPayload = {
|
|
29669
|
+
* symbol: "BTCUSDT",
|
|
29670
|
+
* position: "long",
|
|
29671
|
+
* currentPrice: 49800,
|
|
29672
|
+
* priceOpen: 50000,
|
|
29673
|
+
* priceTakeProfit: 55000,
|
|
29674
|
+
* priceStopLoss: 48000,
|
|
29675
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29676
|
+
* backtest: false,
|
|
29677
|
+
* };
|
|
29678
|
+
* ```
|
|
29679
|
+
*/
|
|
29680
|
+
type BrokerSchedulePingPayload = {
|
|
29681
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29682
|
+
symbol: string;
|
|
29683
|
+
/** Unique signal identifier (UUID v4) of the scheduled signal */
|
|
29684
|
+
signalId: string;
|
|
29685
|
+
/** Position direction */
|
|
29686
|
+
position: "long" | "short";
|
|
29687
|
+
/** Market price at the moment of the ping */
|
|
29688
|
+
currentPrice: number;
|
|
29689
|
+
/** Pending entry price the scheduled signal is waiting for */
|
|
29690
|
+
priceOpen: number;
|
|
29691
|
+
/** Take-profit price configured for the scheduled signal */
|
|
29692
|
+
priceTakeProfit: number;
|
|
29693
|
+
/** Stop-loss price configured for the scheduled signal */
|
|
29694
|
+
priceStopLoss: number;
|
|
29695
|
+
/** Strategy/exchange/frame routing context */
|
|
29696
|
+
context: {
|
|
29697
|
+
strategyName: StrategyName;
|
|
29698
|
+
exchangeName: ExchangeName;
|
|
29699
|
+
frameName?: FrameName;
|
|
29700
|
+
};
|
|
29701
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29702
|
+
backtest: boolean;
|
|
29703
|
+
};
|
|
29704
|
+
/**
|
|
29705
|
+
* Payload for the idle-ping broker event.
|
|
29706
|
+
*
|
|
29707
|
+
* Emitted automatically via idlePingSubject on every live tick while the strategy has no pending or
|
|
29708
|
+
* scheduled signal. Forwarded to the registered IBroker adapter via `onSignalIdlePing`. Purely
|
|
29709
|
+
* informational — carries no signal because none is active.
|
|
29710
|
+
*
|
|
29711
|
+
* @example
|
|
29712
|
+
* ```typescript
|
|
29713
|
+
* const payload: BrokerIdlePingPayload = {
|
|
29714
|
+
* symbol: "BTCUSDT",
|
|
29715
|
+
* currentPrice: 50500,
|
|
29716
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29717
|
+
* backtest: false,
|
|
29718
|
+
* };
|
|
29719
|
+
* ```
|
|
29720
|
+
*/
|
|
29721
|
+
type BrokerIdlePingPayload = {
|
|
29722
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29723
|
+
symbol: string;
|
|
29724
|
+
/** Market price at the moment of the ping */
|
|
29725
|
+
currentPrice: number;
|
|
29726
|
+
/** Strategy/exchange/frame routing context */
|
|
29727
|
+
context: {
|
|
29728
|
+
strategyName: StrategyName;
|
|
29729
|
+
exchangeName: ExchangeName;
|
|
29730
|
+
frameName?: FrameName;
|
|
29731
|
+
};
|
|
29732
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29733
|
+
backtest: boolean;
|
|
29734
|
+
};
|
|
29735
|
+
/**
|
|
29736
|
+
* Payload for the scheduled-signal-open broker event.
|
|
29737
|
+
*
|
|
29738
|
+
* Emitted automatically via scheduleEventSubject (action "scheduled") when a new scheduled signal is
|
|
29739
|
+
* created and starts waiting for priceOpen activation. Forwarded to the registered IBroker adapter
|
|
29740
|
+
* via `onSignalScheduleOpen`. The scheduled -> active transition is NOT reported here — activation
|
|
29741
|
+
* arrives through `onOrderOpenCommit`.
|
|
29742
|
+
*
|
|
29743
|
+
* @example
|
|
29744
|
+
* ```typescript
|
|
29745
|
+
* const payload: BrokerScheduleOpenPayload = {
|
|
29746
|
+
* symbol: "BTCUSDT",
|
|
29747
|
+
* position: "long",
|
|
29748
|
+
* currentPrice: 49800,
|
|
29749
|
+
* priceOpen: 50000,
|
|
29750
|
+
* priceTakeProfit: 55000,
|
|
29751
|
+
* priceStopLoss: 48000,
|
|
29752
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29753
|
+
* backtest: false,
|
|
29754
|
+
* };
|
|
29755
|
+
* ```
|
|
29756
|
+
*/
|
|
29757
|
+
type BrokerScheduleOpenPayload = {
|
|
29758
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29759
|
+
symbol: string;
|
|
29760
|
+
/** Unique signal identifier (UUID v4) of the scheduled signal */
|
|
29761
|
+
signalId: string;
|
|
29762
|
+
/** Position direction */
|
|
29763
|
+
position: "long" | "short";
|
|
29764
|
+
/** Market price at the moment the scheduled signal was created */
|
|
29765
|
+
currentPrice: number;
|
|
29766
|
+
/** Pending entry price the scheduled signal waits for */
|
|
29767
|
+
priceOpen: number;
|
|
29768
|
+
/** Take-profit price configured for the scheduled signal */
|
|
29769
|
+
priceTakeProfit: number;
|
|
29770
|
+
/** Stop-loss price configured for the scheduled signal */
|
|
29771
|
+
priceStopLoss: number;
|
|
29772
|
+
/** Strategy/exchange/frame routing context */
|
|
29773
|
+
context: {
|
|
29774
|
+
strategyName: StrategyName;
|
|
29775
|
+
exchangeName: ExchangeName;
|
|
29776
|
+
frameName?: FrameName;
|
|
29777
|
+
};
|
|
29778
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29779
|
+
backtest: boolean;
|
|
29780
|
+
};
|
|
29781
|
+
/**
|
|
29782
|
+
* Payload for the scheduled-signal-cancelled broker event.
|
|
29783
|
+
*
|
|
29784
|
+
* Emitted automatically via scheduleEventSubject (action "cancelled") when a scheduled signal is
|
|
29785
|
+
* removed before it ever activated. Forwarded to the registered IBroker adapter via
|
|
29786
|
+
* `onSignalScheduleCancelled`. The `reason` distinguishes timeout / price reject / user cancel.
|
|
29787
|
+
*
|
|
29788
|
+
* @example
|
|
29789
|
+
* ```typescript
|
|
29790
|
+
* const payload: BrokerScheduleCancelledPayload = {
|
|
29791
|
+
* symbol: "BTCUSDT",
|
|
29792
|
+
* position: "long",
|
|
29793
|
+
* currentPrice: 47500,
|
|
29794
|
+
* priceOpen: 50000,
|
|
29795
|
+
* priceTakeProfit: 55000,
|
|
29796
|
+
* priceStopLoss: 48000,
|
|
29797
|
+
* reason: "price_reject",
|
|
29798
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29799
|
+
* backtest: false,
|
|
29800
|
+
* };
|
|
29801
|
+
* ```
|
|
29802
|
+
*/
|
|
29803
|
+
type BrokerScheduleCancelledPayload = {
|
|
29804
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29805
|
+
symbol: string;
|
|
29806
|
+
/** Unique signal identifier (UUID v4) of the cancelled scheduled signal */
|
|
29807
|
+
signalId: string;
|
|
29808
|
+
/** Position direction */
|
|
29809
|
+
position: "long" | "short";
|
|
29810
|
+
/** Market price at the moment of cancellation */
|
|
29811
|
+
currentPrice: number;
|
|
29812
|
+
/** Pending entry price the scheduled signal had been waiting for */
|
|
29813
|
+
priceOpen: number;
|
|
29814
|
+
/** Take-profit price that had been configured for the scheduled signal */
|
|
29815
|
+
priceTakeProfit: number;
|
|
29816
|
+
/** Stop-loss price that had been configured for the scheduled signal */
|
|
29817
|
+
priceStopLoss: number;
|
|
29818
|
+
/** Why the scheduled signal was cancelled: "timeout" / "price_reject" / "user" */
|
|
29819
|
+
reason?: StrategyCancelReason;
|
|
29820
|
+
/** Strategy/exchange/frame routing context */
|
|
29821
|
+
context: {
|
|
29822
|
+
strategyName: StrategyName;
|
|
29823
|
+
exchangeName: ExchangeName;
|
|
29824
|
+
frameName?: FrameName;
|
|
29825
|
+
};
|
|
29826
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29827
|
+
backtest: boolean;
|
|
29828
|
+
};
|
|
29829
|
+
/**
|
|
29830
|
+
* Payload for the pending-signal-open broker event.
|
|
29831
|
+
*
|
|
29832
|
+
* Emitted automatically via signalEventSubject (action "opened") when a pending position is opened
|
|
29833
|
+
* (new signal / immediate entry / scheduled or user activation). Forwarded to the registered IBroker
|
|
29834
|
+
* adapter via `onSignalPendingOpen`.
|
|
29835
|
+
*
|
|
29836
|
+
* @example
|
|
29837
|
+
* ```typescript
|
|
29838
|
+
* const payload: BrokerPendingOpenPayload = {
|
|
29839
|
+
* symbol: "BTCUSDT",
|
|
29840
|
+
* position: "long",
|
|
29841
|
+
* currentPrice: 50000,
|
|
29842
|
+
* priceOpen: 50000,
|
|
29843
|
+
* priceTakeProfit: 55000,
|
|
29844
|
+
* priceStopLoss: 48000,
|
|
29845
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29846
|
+
* backtest: false,
|
|
29847
|
+
* };
|
|
29848
|
+
* ```
|
|
29849
|
+
*/
|
|
29850
|
+
type BrokerPendingOpenPayload = {
|
|
29851
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29852
|
+
symbol: string;
|
|
29853
|
+
/** Unique signal identifier (UUID v4) of the opened position */
|
|
29854
|
+
signalId: string;
|
|
29855
|
+
/** Position direction */
|
|
29856
|
+
position: "long" | "short";
|
|
29857
|
+
/** Effective entry price at the moment the position opened */
|
|
29858
|
+
currentPrice: number;
|
|
29859
|
+
/** Effective entry price (may differ from currentPrice after DCA averaging) */
|
|
29860
|
+
priceOpen: number;
|
|
29861
|
+
/** Take-profit price configured for the position */
|
|
29862
|
+
priceTakeProfit: number;
|
|
29863
|
+
/** Stop-loss price configured for the position */
|
|
29864
|
+
priceStopLoss: number;
|
|
29865
|
+
/** Strategy/exchange/frame routing context */
|
|
29866
|
+
context: {
|
|
29867
|
+
strategyName: StrategyName;
|
|
29868
|
+
exchangeName: ExchangeName;
|
|
29869
|
+
frameName?: FrameName;
|
|
29870
|
+
};
|
|
29871
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29872
|
+
backtest: boolean;
|
|
29873
|
+
};
|
|
29874
|
+
/**
|
|
29875
|
+
* Payload for the pending-signal-close broker event.
|
|
29876
|
+
*
|
|
29877
|
+
* Emitted automatically via signalEventSubject (action "closed") when a pending position is closed.
|
|
29878
|
+
* Forwarded to the registered IBroker adapter via `onSignalPendingClose`. The `closeReason`
|
|
29879
|
+
* distinguishes take_profit / stop_loss / time_expired / user-close / broker fill / order gone.
|
|
29880
|
+
*
|
|
29881
|
+
* @example
|
|
29882
|
+
* ```typescript
|
|
29883
|
+
* const payload: BrokerPendingClosePayload = {
|
|
29884
|
+
* symbol: "BTCUSDT",
|
|
29885
|
+
* position: "long",
|
|
29886
|
+
* currentPrice: 55000,
|
|
29887
|
+
* priceOpen: 50000,
|
|
29888
|
+
* priceTakeProfit: 55000,
|
|
29889
|
+
* priceStopLoss: 48000,
|
|
29890
|
+
* closeReason: "take_profit",
|
|
29891
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29892
|
+
* backtest: false,
|
|
29893
|
+
* };
|
|
29894
|
+
* ```
|
|
29895
|
+
*/
|
|
29896
|
+
type BrokerPendingClosePayload = {
|
|
29897
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29898
|
+
symbol: string;
|
|
29899
|
+
/** Unique signal identifier (UUID v4) of the closed position */
|
|
29900
|
+
signalId: string;
|
|
29901
|
+
/** Position direction */
|
|
29902
|
+
position: "long" | "short";
|
|
29903
|
+
/** Market price at the moment of close */
|
|
29904
|
+
currentPrice: number;
|
|
29905
|
+
/** Effective entry price of the closed position */
|
|
29906
|
+
priceOpen: number;
|
|
29907
|
+
/** Effective take-profit price of the closed position */
|
|
29908
|
+
priceTakeProfit: number;
|
|
29909
|
+
/** Effective stop-loss price of the closed position */
|
|
29910
|
+
priceStopLoss: number;
|
|
29911
|
+
/** Why the position closed: "take_profit" / "stop_loss" / "time_expired" / "closed" */
|
|
29912
|
+
closeReason?: StrategyCloseReason;
|
|
29913
|
+
/** Strategy/exchange/frame routing context */
|
|
29914
|
+
context: {
|
|
29915
|
+
strategyName: StrategyName;
|
|
29916
|
+
exchangeName: ExchangeName;
|
|
29917
|
+
frameName?: FrameName;
|
|
29918
|
+
};
|
|
29919
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29920
|
+
backtest: boolean;
|
|
29921
|
+
};
|
|
28857
29922
|
/**
|
|
28858
29923
|
* Payload for a partial-profit close broker event.
|
|
28859
29924
|
*
|
|
@@ -29131,7 +30196,7 @@ type BrokerAverageBuyPayload = {
|
|
|
29131
30196
|
* async waitForInit() {
|
|
29132
30197
|
* await this.exchange.connect();
|
|
29133
30198
|
* }
|
|
29134
|
-
* async
|
|
30199
|
+
* async onOrderOpenCommit(payload) {
|
|
29135
30200
|
* await this.exchange.placeOrder({ symbol: payload.symbol, side: payload.position });
|
|
29136
30201
|
* }
|
|
29137
30202
|
* // ... other methods
|
|
@@ -29143,21 +30208,264 @@ type BrokerAverageBuyPayload = {
|
|
|
29143
30208
|
interface IBroker {
|
|
29144
30209
|
/** Called once before first use. Connect to exchange, load credentials, etc. */
|
|
29145
30210
|
waitForInit(): Promise<void>;
|
|
29146
|
-
/** Called when a new signal is closed (take-profit, stop-loss, or manual close). */
|
|
29147
|
-
onSignalCloseCommit(payload: BrokerSignalClosePayload): Promise<void>;
|
|
29148
|
-
/** Called when a new signal is opened (position entry confirmed). */
|
|
29149
|
-
onSignalOpenCommit(payload: BrokerSignalOpenPayload): Promise<void>;
|
|
29150
30211
|
/**
|
|
29151
|
-
* Called
|
|
30212
|
+
* Called when a signal is being closed (take-profit, stop-loss, or manual close). Emitted via
|
|
30213
|
+
* syncSubject BEFORE the framework mutates strategy state, so it is also the close **gate**.
|
|
30214
|
+
*
|
|
30215
|
+
* MANUAL WIRING — EXCEPTION-BASED: place the real exit order here (tag/look up by `payload.signalId`)
|
|
30216
|
+
* and record final PnL. This is the confirmed-close commit; like `onOrderSync` (signal-close) it
|
|
30217
|
+
* shares the gate semantics — a THROW means "the exchange did not close the position" and the
|
|
30218
|
+
* framework SKIPS the close, leaving the position open and retrying on the next tick. Return
|
|
30219
|
+
* normally to let the close proceed. Backtest short-circuits this (no live exchange), so the gate is
|
|
30220
|
+
* live-only.
|
|
30221
|
+
*
|
|
30222
|
+
* This differs from `onSignalPendingClose`, which is the informational lifecycle hook that fires
|
|
30223
|
+
* AFTER the close is committed (and cannot veto it).
|
|
30224
|
+
*/
|
|
30225
|
+
onOrderCloseCommit(payload: BrokerOrderClosePayload): Promise<void>;
|
|
30226
|
+
/**
|
|
30227
|
+
* Called when an order is being opened. Emitted via syncSubject BEFORE the framework mutates
|
|
30228
|
+
* strategy state, so it is also the open **gate**. Discriminated by `payload.type`:
|
|
30229
|
+
* - "active" — position entry (immediate open or activation fill of the resting order);
|
|
30230
|
+
* - "schedule" — PLACEMENT of the resting entry order at scheduled-signal creation.
|
|
30231
|
+
*
|
|
30232
|
+
* MANUAL WIRING — EXCEPTION-BASED: place the real order here (tag the exchange order with
|
|
30233
|
+
* `payload.signalId` so later `onOrderActiveCheck` / `onOrderScheduleCheck` / `onSignalActivePing` can find it). Like `onOrderSync`
|
|
30234
|
+
* (signal-open) it shares the gate semantics — a THROW means "the exchange did not accept/fill the
|
|
30235
|
+
* order" and the framework ROLLS BACK: for type "active" the pending signal returns to idle (a
|
|
30236
|
+
* scheduled activation is cancelled); for type "schedule" the scheduled signal is NOT registered
|
|
30237
|
+
* and the risk reservation is released. Both retry on the next tick. Return normally to let the
|
|
30238
|
+
* open proceed. Backtest short-circuits this, so the gate is live-only.
|
|
30239
|
+
*
|
|
30240
|
+
* This differs from `onSignalPendingOpen`, which is the informational lifecycle hook that fires
|
|
30241
|
+
* AFTER the open is committed (and cannot veto it).
|
|
30242
|
+
*/
|
|
30243
|
+
onOrderOpenCommit(payload: BrokerOrderOpenPayload): Promise<void>;
|
|
30244
|
+
/**
|
|
30245
|
+
* Called on every live tick while a pending signal (open position) is monitored,
|
|
30246
|
+
* BEFORE TP/SL/time evaluation (`payload.type` is always "active").
|
|
30247
|
+
*
|
|
29152
30248
|
* Query the exchange by `payload.signalId` and THROW ONLY when the order is NOT FOUND by that id
|
|
29153
|
-
* — the framework will then close the position with closeReason "closed". Return normally to
|
|
29154
|
-
* monitoring.
|
|
30249
|
+
* — the framework will then close the position with closeReason "closed". Return normally to
|
|
30250
|
+
* keep monitoring.
|
|
29155
30251
|
*
|
|
29156
30252
|
* CRITICAL: swallow transient/network errors (timeout, 5xx, rate limit, disconnect) — return
|
|
29157
30253
|
* normally instead of throwing, otherwise a connectivity blip would wrongly close an open
|
|
29158
30254
|
* position. Throw exclusively on a confirmed "order not found by id" result.
|
|
30255
|
+
*
|
|
30256
|
+
* Manual wiring — EXCEPTION-BASED VARIANT
|
|
30257
|
+
*
|
|
30258
|
+
* This is the throw-driven **alternative** to the imperative commit-function wiring in
|
|
30259
|
+
* `onSignalActivePing`:
|
|
30260
|
+
* - **Exception-based (here):** THROW → framework closes the position with closeReason "closed".
|
|
30261
|
+
* One binary gate, no reason distinction. Good when "order gone" is the only condition you handle.
|
|
30262
|
+
* - **Imperative (`onSignalActivePing` + `src/function/strategy.ts`):** call
|
|
30263
|
+
* `commitClosePending` / `commitCreateTakeProfit` / `commitCreateStopLoss` to close with the
|
|
30264
|
+
* correct reason and handle TP vs SL vs no-counterparty separately.
|
|
30265
|
+
*
|
|
30266
|
+
* Pick ONE per condition — do not both throw here AND `commitClosePending` in the active-ping for
|
|
30267
|
+
* the same "order gone" event.
|
|
30268
|
+
*
|
|
30269
|
+
* @example
|
|
30270
|
+
* ```typescript
|
|
30271
|
+
* async onOrderActiveCheck(payload: BrokerOrderCheckPayload) {
|
|
30272
|
+
* let order: Order | null;
|
|
30273
|
+
* try {
|
|
30274
|
+
* order = await this.exchange.getOrderById(payload.signalId);
|
|
30275
|
+
* } catch (networkError) {
|
|
30276
|
+
* return; // transient — keep the position open, retry next tick
|
|
30277
|
+
* }
|
|
30278
|
+
* if (!order) {
|
|
30279
|
+
* throw new Error(`Order ${payload.signalId} not found`); // confirmed gone -> close "closed"
|
|
30280
|
+
* }
|
|
30281
|
+
* }
|
|
30282
|
+
* ```
|
|
30283
|
+
*/
|
|
30284
|
+
onOrderActiveCheck(payload: BrokerOrderCheckPayload): Promise<void>;
|
|
30285
|
+
/**
|
|
30286
|
+
* Called on every live tick while a scheduled signal (resting entry order) is monitored,
|
|
30287
|
+
* BEFORE timeout/price-activation evaluation (`payload.type` is always "schedule").
|
|
30288
|
+
*
|
|
30289
|
+
* Query the exchange by `payload.signalId` and THROW ONLY when the resting order is NOT FOUND
|
|
30290
|
+
* by that id — the framework will then cancel the scheduled signal with reason "user". Return
|
|
30291
|
+
* normally to keep monitoring. A FILLED resting order must be confirmed via
|
|
30292
|
+
* `commitActivateScheduled`, not by throwing here (a throw is a terminal cancel, not an
|
|
30293
|
+
* activation).
|
|
30294
|
+
*
|
|
30295
|
+
* CRITICAL: swallow transient/network errors (timeout, 5xx, rate limit, disconnect) — return
|
|
30296
|
+
* normally instead of throwing, otherwise a connectivity blip would wrongly cancel the resting
|
|
30297
|
+
* order. Throw exclusively on a confirmed "order not found by id" result.
|
|
30298
|
+
*
|
|
30299
|
+
* Manual wiring — EXCEPTION-BASED VARIANT: the throw-driven alternative to the imperative
|
|
30300
|
+
* commit-function wiring in `onSignalSchedulePing` (`commitActivateScheduled` /
|
|
30301
|
+
* `commitCancelScheduled`). Pick ONE per condition.
|
|
30302
|
+
*
|
|
30303
|
+
* @example
|
|
30304
|
+
* ```typescript
|
|
30305
|
+
* async onOrderScheduleCheck(payload: BrokerOrderCheckPayload) {
|
|
30306
|
+
* let order: Order | null;
|
|
30307
|
+
* try {
|
|
30308
|
+
* order = await this.exchange.getOrderById(payload.signalId);
|
|
30309
|
+
* } catch (networkError) {
|
|
30310
|
+
* return; // transient — keep the resting order monitored, retry next tick
|
|
30311
|
+
* }
|
|
30312
|
+
* if (!order) {
|
|
30313
|
+
* throw new Error(`Order ${payload.signalId} not found`); // confirmed gone -> cancel "user"
|
|
30314
|
+
* }
|
|
30315
|
+
* }
|
|
30316
|
+
* ```
|
|
30317
|
+
*/
|
|
30318
|
+
onOrderScheduleCheck(payload: BrokerOrderCheckPayload): Promise<void>;
|
|
30319
|
+
/**
|
|
30320
|
+
* Called on every live tick while a pending (open) signal is monitored.
|
|
30321
|
+
* Purely informational mirror of the active-ping lifecycle — a throw here does NOT close the
|
|
30322
|
+
* position (unlike `onOrderActiveCheck`).
|
|
30323
|
+
*
|
|
30324
|
+
* Manual wiring — EVENT-BASED (driving an open position from real exchange state)
|
|
30325
|
+
*
|
|
30326
|
+
* Primary per-tick **event-based** hook for an open position (a throw does NOT close it — react to
|
|
30327
|
+
* the event and decide imperatively). This is where you reconcile the framework's VWAP view with
|
|
30328
|
+
* real fills: catch a **SL that gapped through** the level, or a **TP that filled before VWAP**
|
|
30329
|
+
* reached it. Poll your real order and translate its state into strategy state via the
|
|
30330
|
+
* commit-functions from `src/function/strategy.ts` (callable here because the ping is emitted inside
|
|
30331
|
+
* the strategy tick; effects are deferred to the next tick):
|
|
30332
|
+
* - `commitCreateTakeProfit(symbol, { id })` — real TP order filled (possibly before VWAP reached
|
|
30333
|
+
* the level) → force close, reason "take_profit".
|
|
30334
|
+
* - `commitCreateStopLoss(symbol, { id })` — real SL order filled (e.g. price gapped through SL) →
|
|
30335
|
+
* force close, reason "stop_loss".
|
|
30336
|
+
* - `commitClosePending(symbol, { id })` — no counterparty (no buyer/seller, liquidity gap) → close
|
|
30337
|
+
* now with reason "closed", instead of throwing.
|
|
30338
|
+
*
|
|
30339
|
+
* @example
|
|
30340
|
+
* ```typescript
|
|
30341
|
+
* import { commitCreateTakeProfit, commitCreateStopLoss, commitClosePending } from "backtest-kit";
|
|
30342
|
+
*
|
|
30343
|
+
* async onSignalActivePing(payload: BrokerActivePingPayload) {
|
|
30344
|
+
* const order = await this.exchange.getOrderById(payload.signalId);
|
|
30345
|
+
* if (order?.status === "filled" && order.kind === "take_profit") {
|
|
30346
|
+
* await commitCreateTakeProfit(payload.symbol, { id: order.id });
|
|
30347
|
+
* } else if (order?.status === "filled" && order.kind === "stop_loss") {
|
|
30348
|
+
* await commitCreateStopLoss(payload.symbol, { id: order.id });
|
|
30349
|
+
* } else if (order?.status === "no_counterparty") {
|
|
30350
|
+
* await commitClosePending(payload.symbol, { id: order.id });
|
|
30351
|
+
* }
|
|
30352
|
+
* }
|
|
30353
|
+
* ```
|
|
30354
|
+
*/
|
|
30355
|
+
onSignalActivePing(payload: BrokerActivePingPayload): Promise<void>;
|
|
30356
|
+
/**
|
|
30357
|
+
* Called on every live tick while a scheduled signal is monitored (waiting for priceOpen
|
|
30358
|
+
* activation). Purely informational.
|
|
30359
|
+
*
|
|
30360
|
+
* Manual wiring — EVENT-BASED (driving the scheduled phase from real exchange state)
|
|
30361
|
+
*
|
|
30362
|
+
* Per-tick **event-based** hook (a throw does NOT veto anything — react and decide imperatively).
|
|
30363
|
+
* Poll your real resting/limit order and translate it via the commit-functions from
|
|
30364
|
+
* `src/function/strategy.ts` (deferred to the next tick):
|
|
30365
|
+
* - `commitActivateScheduled(symbol, { id })` — resting order filled/resolved → activate now,
|
|
30366
|
+
* without waiting for VWAP to reach priceOpen (surfaces as `onOrderOpenCommit` next tick).
|
|
30367
|
+
* - `commitCancelScheduled(symbol, { id })` — resting order cancelled/rejected externally → drop it.
|
|
30368
|
+
*
|
|
30369
|
+
* @example
|
|
30370
|
+
* ```typescript
|
|
30371
|
+
* import { commitActivateScheduled, commitCancelScheduled } from "backtest-kit";
|
|
30372
|
+
*
|
|
30373
|
+
* async onSignalSchedulePing(payload: BrokerSchedulePingPayload) {
|
|
30374
|
+
* const order = await this.exchange.getOrderById(payload.signalId);
|
|
30375
|
+
* if (order?.status === "filled" || order?.status === "resolved") {
|
|
30376
|
+
* await commitActivateScheduled(payload.symbol, { id: order.id });
|
|
30377
|
+
* } else if (order?.status === "cancelled" || order?.status === "rejected") {
|
|
30378
|
+
* await commitCancelScheduled(payload.symbol, { id: order.id });
|
|
30379
|
+
* }
|
|
30380
|
+
* }
|
|
30381
|
+
* ```
|
|
30382
|
+
*/
|
|
30383
|
+
onSignalSchedulePing(payload: BrokerSchedulePingPayload): Promise<void>;
|
|
30384
|
+
/**
|
|
30385
|
+
* Called on every live tick while the strategy is idle (no pending or scheduled signal).
|
|
30386
|
+
* Purely informational.
|
|
30387
|
+
*
|
|
30388
|
+
* MANUAL WIRING — EVENT-BASED: no signal is active, so there is nothing to commit; use it for idle
|
|
30389
|
+
* heartbeats / housekeeping. A throw does not affect strategy state.
|
|
30390
|
+
*/
|
|
30391
|
+
onSignalIdlePing(payload: BrokerIdlePingPayload): Promise<void>;
|
|
30392
|
+
/**
|
|
30393
|
+
* Called when a new scheduled signal is created and starts waiting for priceOpen activation.
|
|
30394
|
+
* The scheduled -> active transition is reported via `onOrderOpenCommit`, not here.
|
|
30395
|
+
*
|
|
30396
|
+
* Manual wiring — EVENT-BASED (placing the resting order)
|
|
30397
|
+
*
|
|
30398
|
+
* Fires ONCE at creation — place the real resting/limit order (tag it with `payload.signalId` so
|
|
30399
|
+
* `onSignalSchedulePing` can poll it later). If it resolves immediately, promote it with
|
|
30400
|
+
* `commitActivateScheduled(symbol, { id })`; if rejected, drop it with
|
|
30401
|
+
* `commitCancelScheduled(symbol, { id })`. Use `onSignalSchedulePing` for ongoing polling.
|
|
30402
|
+
*
|
|
30403
|
+
* @example
|
|
30404
|
+
* ```typescript
|
|
30405
|
+
* import { commitActivateScheduled, commitCancelScheduled } from "backtest-kit";
|
|
30406
|
+
*
|
|
30407
|
+
* async onSignalScheduleOpen(payload: BrokerScheduleOpenPayload) {
|
|
30408
|
+
* const order = await this.exchange.placeLimitOrder({
|
|
30409
|
+
* id: payload.signalId,
|
|
30410
|
+
* symbol: payload.symbol,
|
|
30411
|
+
* side: payload.position,
|
|
30412
|
+
* price: payload.priceOpen,
|
|
30413
|
+
* });
|
|
30414
|
+
* if (order.status === "filled") await commitActivateScheduled(payload.symbol, { id: order.id });
|
|
30415
|
+
* else if (order.status === "rejected") await commitCancelScheduled(payload.symbol, { id: order.id });
|
|
30416
|
+
* }
|
|
30417
|
+
* ```
|
|
30418
|
+
*/
|
|
30419
|
+
onSignalScheduleOpen(payload: BrokerScheduleOpenPayload): Promise<void>;
|
|
30420
|
+
/**
|
|
30421
|
+
* Called when a scheduled signal is cancelled before it ever activated
|
|
30422
|
+
* (reason: timeout / price_reject / user).
|
|
30423
|
+
*
|
|
30424
|
+
* Manual wiring — EVENT-BASED (tearing down the resting order)
|
|
30425
|
+
*
|
|
30426
|
+
* Outbound side — the framework has already dropped the scheduled signal, so there is nothing to
|
|
30427
|
+
* `commitCancelScheduled` here; instead cancel the real resting order you placed in
|
|
30428
|
+
* `onSignalScheduleOpen` (look it up by `payload.signalId`). `payload.reason` tells you why.
|
|
30429
|
+
*
|
|
30430
|
+
* @example
|
|
30431
|
+
* ```typescript
|
|
30432
|
+
* async onSignalScheduleCancelled(payload: BrokerScheduleCancelledPayload) {
|
|
30433
|
+
* await this.exchange.cancelOrderById(payload.signalId);
|
|
30434
|
+
* }
|
|
30435
|
+
* ```
|
|
30436
|
+
*/
|
|
30437
|
+
onSignalScheduleCancelled(payload: BrokerScheduleCancelledPayload): Promise<void>;
|
|
30438
|
+
/**
|
|
30439
|
+
* Called when a pending position is opened (new signal / immediate / scheduled or user
|
|
30440
|
+
* activation). Purely informational lifecycle hook for the active phase of a signal.
|
|
30441
|
+
*
|
|
30442
|
+
* Manual wiring — EVENT-BASED (placing entry + protective orders)
|
|
30443
|
+
*
|
|
30444
|
+
* Fires ONCE at open — place the real entry confirmation and protective TP/SL orders (tag them with
|
|
30445
|
+
* `payload.signalId`). Drive the rest per-tick from `onSignalActivePing`. This hook does not gate
|
|
30446
|
+
* the position; for a true entry gate use `onOrderSync` (signal-open).
|
|
30447
|
+
*/
|
|
30448
|
+
onSignalPendingOpen(payload: BrokerPendingOpenPayload): Promise<void>;
|
|
30449
|
+
/**
|
|
30450
|
+
* Called when a pending position is closed
|
|
30451
|
+
* (reason: take_profit / stop_loss / time_expired / closed).
|
|
30452
|
+
*
|
|
30453
|
+
* Manual wiring — EVENT-BASED (tearing down the position)
|
|
30454
|
+
*
|
|
30455
|
+
* Outbound side — the framework has already removed the pending signal, so there is nothing to
|
|
30456
|
+
* `commitClosePending` here; instead flatten the real position and cancel leftover TP/SL orders by
|
|
30457
|
+
* `payload.signalId`, and record final PnL. `payload.closeReason` says which path closed it. If you
|
|
30458
|
+
* need to FORCE the close yourself (e.g. no counterparty), do it earlier in `onSignalActivePing`.
|
|
30459
|
+
*
|
|
30460
|
+
* @example
|
|
30461
|
+
* ```typescript
|
|
30462
|
+
* async onSignalPendingClose(payload: BrokerPendingClosePayload) {
|
|
30463
|
+
* await this.exchange.flatten(payload.symbol);
|
|
30464
|
+
* await this.exchange.cancelProtectiveOrders(payload.signalId);
|
|
30465
|
+
* }
|
|
30466
|
+
* ```
|
|
29159
30467
|
*/
|
|
29160
|
-
|
|
30468
|
+
onSignalPendingClose(payload: BrokerPendingClosePayload): Promise<void>;
|
|
29161
30469
|
/** Called when a partial profit close is committed. */
|
|
29162
30470
|
onPartialProfitCommit(payload: BrokerPartialProfitPayload): Promise<void>;
|
|
29163
30471
|
/** Called when a partial loss close is committed. */
|
|
@@ -29180,7 +30488,7 @@ interface IBroker {
|
|
|
29180
30488
|
* @example
|
|
29181
30489
|
* ```typescript
|
|
29182
30490
|
* class MyBroker implements Partial<IBroker> {
|
|
29183
|
-
* async
|
|
30491
|
+
* async onOrderOpenCommit(payload: BrokerOrderOpenPayload) { ... }
|
|
29184
30492
|
* }
|
|
29185
30493
|
*
|
|
29186
30494
|
* Broker.useBrokerAdapter(MyBroker); // MyBroker satisfies TBrokerCtor
|
|
@@ -29240,7 +30548,7 @@ declare class BrokerAdapter {
|
|
|
29240
30548
|
*
|
|
29241
30549
|
* @example
|
|
29242
30550
|
* ```typescript
|
|
29243
|
-
* await Broker.
|
|
30551
|
+
* await Broker.commitOrderOpen({
|
|
29244
30552
|
* symbol: "BTCUSDT",
|
|
29245
30553
|
* cost: 100,
|
|
29246
30554
|
* position: "long",
|
|
@@ -29252,7 +30560,7 @@ declare class BrokerAdapter {
|
|
|
29252
30560
|
* });
|
|
29253
30561
|
* ```
|
|
29254
30562
|
*/
|
|
29255
|
-
|
|
30563
|
+
commitOrderOpen: (payload: BrokerOrderOpenPayload) => Promise<void>;
|
|
29256
30564
|
/**
|
|
29257
30565
|
* Forwards a signal-close event to the registered broker adapter.
|
|
29258
30566
|
*
|
|
@@ -29263,7 +30571,7 @@ declare class BrokerAdapter {
|
|
|
29263
30571
|
*
|
|
29264
30572
|
* @example
|
|
29265
30573
|
* ```typescript
|
|
29266
|
-
* await Broker.
|
|
30574
|
+
* await Broker.commitOrderClose({
|
|
29267
30575
|
* symbol: "BTCUSDT",
|
|
29268
30576
|
* cost: 100,
|
|
29269
30577
|
* position: "long",
|
|
@@ -29278,18 +30586,95 @@ declare class BrokerAdapter {
|
|
|
29278
30586
|
* });
|
|
29279
30587
|
* ```
|
|
29280
30588
|
*/
|
|
29281
|
-
|
|
30589
|
+
commitOrderClose: (payload: BrokerOrderClosePayload) => Promise<void>;
|
|
29282
30590
|
/**
|
|
29283
|
-
* Forwards
|
|
30591
|
+
* Forwards an order ping to the registered broker adapter.
|
|
29284
30592
|
*
|
|
29285
30593
|
* Called automatically via syncPendingSubject when `enable()` is active, on every live tick
|
|
29286
|
-
* while a pending signal
|
|
29287
|
-
*
|
|
29288
|
-
*
|
|
30594
|
+
* while a pending signal (payload.type "active") or a scheduled signal (payload.type
|
|
30595
|
+
* "schedule") is monitored — routed to `onOrderActiveCheck` / `onOrderScheduleCheck`
|
|
30596
|
+
* respectively. Skipped silently in backtest mode or when no adapter is registered.
|
|
30597
|
+
* Exceptions are NOT swallowed: a throw from the adapter propagates up to
|
|
30598
|
+
* syncPendingSubject.next() → CREATE_SYNC_PENDING_FN, which closes the position with "closed"
|
|
30599
|
+
* (type "active") or cancels the scheduled signal with reason "user" (type "schedule").
|
|
30600
|
+
*
|
|
30601
|
+
* @param payload - Order ping details: type, symbol, position, prices, pnl, context, backtest flag
|
|
30602
|
+
*/
|
|
30603
|
+
commitOrderCheck: (payload: BrokerOrderCheckPayload) => Promise<void>;
|
|
30604
|
+
/**
|
|
30605
|
+
* Forwards an active-ping to the registered broker adapter.
|
|
30606
|
+
*
|
|
30607
|
+
* Called automatically via activePingSubject when `enable()` is active, on every live tick while a
|
|
30608
|
+
* pending signal is monitored. Skipped silently in backtest mode or when no adapter is registered.
|
|
30609
|
+
* Purely informational — a throw does NOT close the position.
|
|
30610
|
+
*
|
|
30611
|
+
* @param payload - Active ping details: symbol, signalId, position, prices, pnl, context, backtest
|
|
30612
|
+
*/
|
|
30613
|
+
commitActivePing: (payload: BrokerActivePingPayload) => Promise<void>;
|
|
30614
|
+
/**
|
|
30615
|
+
* Forwards a schedule-ping to the registered broker adapter.
|
|
30616
|
+
*
|
|
30617
|
+
* Called automatically via schedulePingSubject when `enable()` is active, on every live tick while
|
|
30618
|
+
* a scheduled signal is monitored. Skipped silently in backtest mode or when no adapter is
|
|
30619
|
+
* registered. Purely informational.
|
|
30620
|
+
*
|
|
30621
|
+
* @param payload - Schedule ping details: symbol, signalId, position, prices, context, backtest
|
|
30622
|
+
*/
|
|
30623
|
+
commitSchedulePing: (payload: BrokerSchedulePingPayload) => Promise<void>;
|
|
30624
|
+
/**
|
|
30625
|
+
* Forwards an idle-ping to the registered broker adapter.
|
|
30626
|
+
*
|
|
30627
|
+
* Called automatically via idlePingSubject when `enable()` is active, on every live tick while the
|
|
30628
|
+
* strategy has no pending or scheduled signal. Skipped silently in backtest mode or when no adapter
|
|
30629
|
+
* is registered. Purely informational.
|
|
30630
|
+
*
|
|
30631
|
+
* @param payload - Idle ping details: symbol, currentPrice, context, backtest
|
|
30632
|
+
*/
|
|
30633
|
+
commitIdlePing: (payload: BrokerIdlePingPayload) => Promise<void>;
|
|
30634
|
+
/**
|
|
30635
|
+
* Forwards a scheduled-signal-open to the registered broker adapter.
|
|
30636
|
+
*
|
|
30637
|
+
* Called automatically via scheduleEventSubject (action "scheduled") when a scheduled signal is
|
|
30638
|
+
* created. Skipped silently in backtest mode or when no adapter is registered.
|
|
30639
|
+
*
|
|
30640
|
+
* @param payload - Scheduled open details: symbol, signalId, position, prices, context, backtest
|
|
30641
|
+
*/
|
|
30642
|
+
commitScheduleOpen: (payload: BrokerScheduleOpenPayload) => Promise<void>;
|
|
30643
|
+
/**
|
|
30644
|
+
* Forwards a scheduled-signal-cancelled to the registered broker adapter.
|
|
29289
30645
|
*
|
|
29290
|
-
*
|
|
30646
|
+
* Called automatically via scheduleEventSubject (action "cancelled") when a scheduled signal is
|
|
30647
|
+
* removed before activation. Skipped silently in backtest mode or when no adapter is registered.
|
|
30648
|
+
*
|
|
30649
|
+
* IMPORTANT (adapter responsibility): the cancel may race the real fill. The framework decides
|
|
30650
|
+
* to drop the scheduled signal from ITS view (risk reject at activation, sync reject, stop,
|
|
30651
|
+
* timeout), but the resting limit order on the exchange may have ALREADY filled by the time this
|
|
30652
|
+
* arrives. The adapter MUST check the actual order status before cancelling: if the order is
|
|
30653
|
+
* filled, cancelling is a no-op on the exchange and the adapter owns the resulting position
|
|
30654
|
+
* (close it or reconcile via onOrderActiveCheck / onSignalActivePing). The framework cannot model
|
|
30655
|
+
* this case — from its side the signal is terminally cancelled.
|
|
30656
|
+
*
|
|
30657
|
+
* @param payload - Scheduled cancel details: symbol, signalId, position, prices, reason, context, backtest
|
|
30658
|
+
*/
|
|
30659
|
+
commitScheduleCancelled: (payload: BrokerScheduleCancelledPayload) => Promise<void>;
|
|
30660
|
+
/**
|
|
30661
|
+
* Forwards a pending-signal-open to the registered broker adapter.
|
|
30662
|
+
*
|
|
30663
|
+
* Called automatically via signalEventSubject (action "opened") when a pending position is opened.
|
|
30664
|
+
* Skipped silently in backtest mode or when no adapter is registered.
|
|
30665
|
+
*
|
|
30666
|
+
* @param payload - Pending open details: symbol, signalId, position, prices, context, backtest
|
|
30667
|
+
*/
|
|
30668
|
+
commitPendingOpen: (payload: BrokerPendingOpenPayload) => Promise<void>;
|
|
30669
|
+
/**
|
|
30670
|
+
* Forwards a pending-signal-close to the registered broker adapter.
|
|
30671
|
+
*
|
|
30672
|
+
* Called automatically via signalEventSubject (action "closed") when a pending position is closed.
|
|
30673
|
+
* Skipped silently in backtest mode or when no adapter is registered.
|
|
30674
|
+
*
|
|
30675
|
+
* @param payload - Pending close details: symbol, signalId, position, prices, closeReason, context, backtest
|
|
29291
30676
|
*/
|
|
29292
|
-
|
|
30677
|
+
commitPendingClose: (payload: BrokerPendingClosePayload) => Promise<void>;
|
|
29293
30678
|
/**
|
|
29294
30679
|
* Intercepts a partial-profit close before DI-core mutation.
|
|
29295
30680
|
*
|
|
@@ -29528,8 +30913,8 @@ declare class BrokerAdapter {
|
|
|
29528
30913
|
* 4. No explicit dispose — clean up in `waitForInit` teardown or externally
|
|
29529
30914
|
*
|
|
29530
30915
|
* Event flow (called only in live mode, skipped in backtest):
|
|
29531
|
-
* - `
|
|
29532
|
-
* - `
|
|
30916
|
+
* - `onOrderOpenCommit` — new position opened
|
|
30917
|
+
* - `onOrderCloseCommit` — position closed (SL/TP hit or manual close)
|
|
29533
30918
|
* - `onPartialProfitCommit` — partial close at profit executed
|
|
29534
30919
|
* - `onPartialLossCommit` — partial close at loss executed
|
|
29535
30920
|
* - `onTrailingStopCommit` — trailing stop-loss updated
|
|
@@ -29551,8 +30936,8 @@ declare class BrokerAdapter {
|
|
|
29551
30936
|
* await this.client.connect();
|
|
29552
30937
|
* }
|
|
29553
30938
|
*
|
|
29554
|
-
* async
|
|
29555
|
-
* super.
|
|
30939
|
+
* async onOrderOpenCommit(payload: BrokerOrderOpenPayload) {
|
|
30940
|
+
* super.onOrderOpenCommit(payload); // Call parent for logging
|
|
29556
30941
|
* await this.client!.placeOrder({
|
|
29557
30942
|
* symbol: payload.symbol,
|
|
29558
30943
|
* side: payload.position === "long" ? "BUY" : "SELL",
|
|
@@ -29560,8 +30945,8 @@ declare class BrokerAdapter {
|
|
|
29560
30945
|
* });
|
|
29561
30946
|
* }
|
|
29562
30947
|
*
|
|
29563
|
-
* async
|
|
29564
|
-
* super.
|
|
30948
|
+
* async onOrderCloseCommit(payload: BrokerOrderClosePayload) {
|
|
30949
|
+
* super.onOrderCloseCommit(payload); // Call parent for logging
|
|
29565
30950
|
* await this.client!.closePosition(payload.symbol);
|
|
29566
30951
|
* }
|
|
29567
30952
|
* }
|
|
@@ -29575,11 +30960,11 @@ declare class BrokerAdapter {
|
|
|
29575
30960
|
* ```typescript
|
|
29576
30961
|
* // Minimal implementation — only handle opens and closes
|
|
29577
30962
|
* class NotifyBroker extends BrokerBase {
|
|
29578
|
-
* async
|
|
30963
|
+
* async onOrderOpenCommit(payload: BrokerOrderOpenPayload) {
|
|
29579
30964
|
* await sendTelegram(`Opened ${payload.position} on ${payload.symbol}`);
|
|
29580
30965
|
* }
|
|
29581
30966
|
*
|
|
29582
|
-
* async
|
|
30967
|
+
* async onOrderCloseCommit(payload: BrokerOrderClosePayload) {
|
|
29583
30968
|
* const pnl = payload.pnl.profit - payload.pnl.loss;
|
|
29584
30969
|
* await sendTelegram(`Closed ${payload.symbol}: PnL $${pnl.toFixed(2)}`);
|
|
29585
30970
|
* }
|
|
@@ -29606,30 +30991,39 @@ declare class BrokerBase implements IBroker {
|
|
|
29606
30991
|
*/
|
|
29607
30992
|
waitForInit(): Promise<void>;
|
|
29608
30993
|
/**
|
|
29609
|
-
* Called when a
|
|
30994
|
+
* Called when a position is being opened (signal activated).
|
|
29610
30995
|
*
|
|
29611
30996
|
* Triggered automatically via syncSubject when a scheduled signal's priceOpen is hit.
|
|
29612
30997
|
* Use to place the actual entry order on the exchange.
|
|
29613
30998
|
*
|
|
29614
30999
|
* Default implementation: Logs signal-open event.
|
|
29615
31000
|
*
|
|
31001
|
+
* Manual wiring — EXCEPTION-BASED GATE: emitted BEFORE the framework mutates state, so a THROW here
|
|
31002
|
+
* (e.g. limit order rejected) rolls back the open — the pending signal returns to idle and retries
|
|
31003
|
+
* next tick; return normally to let it open. Live-only (backtest short-circuits). See
|
|
31004
|
+
* {@link IBroker.onOrderOpenCommit} for the full semantics.
|
|
31005
|
+
*
|
|
29616
31006
|
* @param payload - Signal open details: symbol, cost, position, priceOpen, priceTakeProfit, priceStopLoss, context, backtest
|
|
29617
31007
|
*
|
|
29618
31008
|
* @example
|
|
29619
31009
|
* ```typescript
|
|
29620
|
-
* async
|
|
29621
|
-
* super.
|
|
29622
|
-
* await this.exchange.placeMarketOrder({
|
|
31010
|
+
* async onOrderOpenCommit(payload: BrokerOrderOpenPayload) {
|
|
31011
|
+
* super.onOrderOpenCommit(payload); // Keep parent logging
|
|
31012
|
+
* const order = await this.exchange.placeMarketOrder({
|
|
29623
31013
|
* symbol: payload.symbol,
|
|
29624
31014
|
* side: payload.position === "long" ? "BUY" : "SELL",
|
|
29625
31015
|
* quantity: payload.cost / payload.priceOpen,
|
|
29626
31016
|
* });
|
|
31017
|
+
* if (!order.filled) {
|
|
31018
|
+
* throw new Error(`Entry not filled for ${payload.symbol}`); // -> roll back the open, retry next tick
|
|
31019
|
+
* }
|
|
29627
31020
|
* }
|
|
29628
31021
|
* ```
|
|
29629
31022
|
*/
|
|
29630
|
-
|
|
31023
|
+
onOrderOpenCommit(payload: BrokerOrderOpenPayload): Promise<void>;
|
|
29631
31024
|
/**
|
|
29632
|
-
* Called on every live tick while a pending signal is monitored, BEFORE
|
|
31025
|
+
* Called on every live tick while a pending signal (open position) is monitored, BEFORE
|
|
31026
|
+
* TP/SL/time evaluation.
|
|
29633
31027
|
*
|
|
29634
31028
|
* Override to query the exchange for the order by `payload.signalId` and THROW ONLY when it is
|
|
29635
31029
|
* definitively NOT FOUND by that id (filled, cancelled, or liquidated externally) — the framework
|
|
@@ -29640,47 +31034,143 @@ declare class BrokerBase implements IBroker {
|
|
|
29640
31034
|
* normally instead of throwing. A thrown network error would wrongly close an open position; only
|
|
29641
31035
|
* a confirmed "order not found by id" response is a valid reason to throw.
|
|
29642
31036
|
*
|
|
31037
|
+
* Manual wiring — EXCEPTION-BASED VARIANT: the throw-driven alternative to the imperative
|
|
31038
|
+
* commit-function wiring in `onSignalActivePing`. See {@link IBroker.onOrderActiveCheck} for the
|
|
31039
|
+
* full comparison and example.
|
|
31040
|
+
*
|
|
29643
31041
|
* @param payload - Pending ping details: symbol, signalId, position, prices, pnl, context, backtest
|
|
31042
|
+
*/
|
|
31043
|
+
onOrderActiveCheck(payload: BrokerOrderCheckPayload): Promise<void>;
|
|
31044
|
+
/**
|
|
31045
|
+
* Called on every live tick while a scheduled signal (resting entry order) is monitored, BEFORE
|
|
31046
|
+
* timeout/price-activation evaluation.
|
|
29644
31047
|
*
|
|
29645
|
-
*
|
|
29646
|
-
*
|
|
29647
|
-
*
|
|
29648
|
-
*
|
|
29649
|
-
*
|
|
29650
|
-
*
|
|
29651
|
-
*
|
|
29652
|
-
*
|
|
29653
|
-
*
|
|
29654
|
-
*
|
|
29655
|
-
*
|
|
29656
|
-
*
|
|
29657
|
-
*
|
|
29658
|
-
*
|
|
29659
|
-
|
|
29660
|
-
|
|
29661
|
-
|
|
31048
|
+
* Override to query the exchange for the resting order by `payload.signalId` and THROW ONLY when
|
|
31049
|
+
* it is definitively NOT FOUND by that id — the framework then cancels the scheduled signal with
|
|
31050
|
+
* reason "user". The default implementation logs and returns normally. A FILLED resting order
|
|
31051
|
+
* must be confirmed via `commitActivateScheduled`, not by throwing here.
|
|
31052
|
+
*
|
|
31053
|
+
* CRITICAL: swallow transient/network errors (timeout, 5xx, rate limit, disconnect) — return
|
|
31054
|
+
* normally instead of throwing; only a confirmed "order not found by id" response is a valid
|
|
31055
|
+
* reason to throw.
|
|
31056
|
+
*
|
|
31057
|
+
* Manual wiring — EXCEPTION-BASED VARIANT: the throw-driven alternative to the imperative
|
|
31058
|
+
* commit-function wiring in `onSignalSchedulePing`. See {@link IBroker.onOrderScheduleCheck} for
|
|
31059
|
+
* the full comparison and example.
|
|
31060
|
+
*
|
|
31061
|
+
* @param payload - Pending ping details: symbol, signalId, position, prices, pnl, context, backtest
|
|
31062
|
+
*/
|
|
31063
|
+
onOrderScheduleCheck(payload: BrokerOrderCheckPayload): Promise<void>;
|
|
31064
|
+
/**
|
|
31065
|
+
* Called on every live tick while a pending (open) signal is monitored.
|
|
31066
|
+
*
|
|
31067
|
+
* Purely informational mirror of the active-ping lifecycle — unlike `onOrderActiveCheck`, a throw here
|
|
31068
|
+
* does NOT close the position. Override to mirror live monitoring state into your own systems.
|
|
31069
|
+
* The default implementation logs.
|
|
31070
|
+
*
|
|
31071
|
+
* Manual wiring — EVENT-BASED: this is the primary per-tick hook to drive an open position from real exchange
|
|
31072
|
+
* state (`commitCreateTakeProfit` / `commitCreateStopLoss` / `commitClosePending`). See the
|
|
31073
|
+
* {@link IBroker.onSignalActivePing} contract docs for the full guidance and example.
|
|
31074
|
+
*
|
|
31075
|
+
* @param payload - Active ping details: symbol, signalId, position, prices, pnl, context, backtest
|
|
31076
|
+
*/
|
|
31077
|
+
onSignalActivePing(payload: BrokerActivePingPayload): Promise<void>;
|
|
31078
|
+
/**
|
|
31079
|
+
* Called on every live tick while a scheduled signal is monitored (waiting for priceOpen).
|
|
31080
|
+
*
|
|
31081
|
+
* Purely informational. Override to mirror scheduled-monitoring state. The default logs.
|
|
31082
|
+
*
|
|
31083
|
+
* Manual wiring — EVENT-BASED: per-tick hook to drive a scheduled (resting) order from real exchange state
|
|
31084
|
+
* (`commitActivateScheduled` / `commitCancelScheduled`). See {@link IBroker.onSignalSchedulePing}
|
|
31085
|
+
* for full guidance and example.
|
|
31086
|
+
*
|
|
31087
|
+
* @param payload - Schedule ping details: symbol, signalId, position, prices, context, backtest
|
|
31088
|
+
*/
|
|
31089
|
+
onSignalSchedulePing(payload: BrokerSchedulePingPayload): Promise<void>;
|
|
31090
|
+
/**
|
|
31091
|
+
* Called on every live tick while the strategy is idle (no pending or scheduled signal).
|
|
31092
|
+
*
|
|
31093
|
+
* Purely informational. Override to track idle heartbeats. The default logs.
|
|
31094
|
+
*
|
|
31095
|
+
* @param payload - Idle ping details: symbol, currentPrice, context, backtest
|
|
31096
|
+
*/
|
|
31097
|
+
onSignalIdlePing(payload: BrokerIdlePingPayload): Promise<void>;
|
|
31098
|
+
/**
|
|
31099
|
+
* Called when a new scheduled signal is created and starts waiting for priceOpen activation.
|
|
31100
|
+
*
|
|
31101
|
+
* The scheduled -> active transition is reported via `onOrderOpenCommit`, not here. Override to
|
|
31102
|
+
* place a resting/limit order on the exchange. The default logs.
|
|
31103
|
+
*
|
|
31104
|
+
* Manual wiring — EVENT-BASED: fires ONCE at creation — place the real resting order (tag it with
|
|
31105
|
+
* `payload.signalId`) and optionally `commitActivateScheduled` / `commitCancelScheduled`. See
|
|
31106
|
+
* {@link IBroker.onSignalScheduleOpen} for full guidance and example.
|
|
31107
|
+
*
|
|
31108
|
+
* @param payload - Scheduled open details: symbol, signalId, position, prices, context, backtest
|
|
31109
|
+
*/
|
|
31110
|
+
onSignalScheduleOpen(payload: BrokerScheduleOpenPayload): Promise<void>;
|
|
31111
|
+
/**
|
|
31112
|
+
* Called when a scheduled signal is cancelled before activation (timeout / price_reject / user).
|
|
31113
|
+
*
|
|
31114
|
+
* Override to cancel the resting/limit order on the exchange. The default logs.
|
|
31115
|
+
*
|
|
31116
|
+
* Manual wiring — EVENT-BASED (outbound): the strategy already dropped the scheduled signal — cancel the matching
|
|
31117
|
+
* exchange order by `payload.signalId`. See {@link IBroker.onSignalScheduleCancelled}.
|
|
31118
|
+
*
|
|
31119
|
+
* @param payload - Scheduled cancel details: symbol, signalId, position, prices, reason, context, backtest
|
|
31120
|
+
*/
|
|
31121
|
+
onSignalScheduleCancelled(payload: BrokerScheduleCancelledPayload): Promise<void>;
|
|
31122
|
+
/**
|
|
31123
|
+
* Called when a pending position is opened (new signal / immediate / scheduled or user activation).
|
|
31124
|
+
*
|
|
31125
|
+
* Informational lifecycle hook. Override to mirror the open into your own systems. The default logs.
|
|
31126
|
+
*
|
|
31127
|
+
* Manual wiring — EVENT-BASED: fires ONCE at open — place entry + protective TP/SL orders (tag with
|
|
31128
|
+
* `payload.signalId`), then drive per-tick from `onSignalActivePing`. See
|
|
31129
|
+
* {@link IBroker.onSignalPendingOpen}.
|
|
31130
|
+
*
|
|
31131
|
+
* @param payload - Pending open details: symbol, signalId, position, prices, context, backtest
|
|
31132
|
+
*/
|
|
31133
|
+
onSignalPendingOpen(payload: BrokerPendingOpenPayload): Promise<void>;
|
|
31134
|
+
/**
|
|
31135
|
+
* Called when a pending position is closed (take_profit / stop_loss / time_expired / closed).
|
|
31136
|
+
*
|
|
31137
|
+
* Informational lifecycle hook. Override to mirror the close into your own systems. The default logs.
|
|
31138
|
+
*
|
|
31139
|
+
* Manual wiring — EVENT-BASED (outbound): the strategy already removed the pending signal — flatten the real
|
|
31140
|
+
* position and cancel leftover TP/SL orders by `payload.signalId`. See
|
|
31141
|
+
* {@link IBroker.onSignalPendingClose}.
|
|
31142
|
+
*
|
|
31143
|
+
* @param payload - Pending close details: symbol, signalId, position, prices, closeReason, context, backtest
|
|
29662
31144
|
*/
|
|
29663
|
-
|
|
31145
|
+
onSignalPendingClose(payload: BrokerPendingClosePayload): Promise<void>;
|
|
29664
31146
|
/**
|
|
29665
|
-
* Called when a position is
|
|
31147
|
+
* Called when a position is being closed (SL/TP hit or manual close).
|
|
29666
31148
|
*
|
|
29667
31149
|
* Triggered automatically via syncSubject when a pending signal is closed.
|
|
29668
31150
|
* Use to place the exit order and record final PnL.
|
|
29669
31151
|
*
|
|
29670
31152
|
* Default implementation: Logs signal-close event.
|
|
29671
31153
|
*
|
|
31154
|
+
* Manual wiring — EXCEPTION-BASED GATE: emitted BEFORE the framework mutates state, so a THROW here
|
|
31155
|
+
* (e.g. exit order failed) SKIPS the close — the position stays open and the close retries next
|
|
31156
|
+
* tick; return normally to let it close. Live-only (backtest short-circuits). See
|
|
31157
|
+
* {@link IBroker.onOrderCloseCommit} for the full semantics.
|
|
31158
|
+
*
|
|
29672
31159
|
* @param payload - Signal close details: symbol, cost, position, currentPrice, pnl, totalEntries, totalPartials, context, backtest
|
|
29673
31160
|
*
|
|
29674
31161
|
* @example
|
|
29675
31162
|
* ```typescript
|
|
29676
|
-
* async
|
|
29677
|
-
* super.
|
|
29678
|
-
* await this.exchange.closePosition(payload.symbol);
|
|
31163
|
+
* async onOrderCloseCommit(payload: BrokerOrderClosePayload) {
|
|
31164
|
+
* super.onOrderCloseCommit(payload); // Keep parent logging
|
|
31165
|
+
* const ok = await this.exchange.closePosition(payload.symbol);
|
|
31166
|
+
* if (!ok) {
|
|
31167
|
+
* throw new Error(`Exit not filled for ${payload.symbol}`); // -> keep position open, retry next tick
|
|
31168
|
+
* }
|
|
29679
31169
|
* await this.db.recordTrade({ symbol: payload.symbol, pnl: payload.pnl });
|
|
29680
31170
|
* }
|
|
29681
31171
|
* ```
|
|
29682
31172
|
*/
|
|
29683
|
-
|
|
31173
|
+
onOrderCloseCommit(payload: BrokerOrderClosePayload): Promise<void>;
|
|
29684
31174
|
/**
|
|
29685
31175
|
* Called when a partial close at profit is executed.
|
|
29686
31176
|
*
|
|
@@ -29873,7 +31363,7 @@ interface WalkerStopContract {
|
|
|
29873
31363
|
* This ensures that the framework's internal state remains consistent with the exchange's state.
|
|
29874
31364
|
* Consumers should implement retry logic in their listeners to handle transient synchronization failures.
|
|
29875
31365
|
*/
|
|
29876
|
-
declare const syncSubject: Subject<
|
|
31366
|
+
declare const syncSubject: Subject<OrderSyncContract>;
|
|
29877
31367
|
/**
|
|
29878
31368
|
* Pending-order synchronization emitter.
|
|
29879
31369
|
* Emitted on every live tick while a pending signal is monitored, BEFORE TP/SL/time evaluation.
|
|
@@ -29882,7 +31372,7 @@ declare const syncSubject: Subject<SignalSyncContract>;
|
|
|
29882
31372
|
* If a listener returns false OR throws, the order is treated as no longer open on the exchange
|
|
29883
31373
|
* and the framework closes the pending signal with closeReason "closed". Never emitted in backtest.
|
|
29884
31374
|
*/
|
|
29885
|
-
declare const syncPendingSubject: Subject<
|
|
31375
|
+
declare const syncPendingSubject: Subject<OrderCheckContract>;
|
|
29886
31376
|
/**
|
|
29887
31377
|
* Global signal emitter for all trading events (live + backtest).
|
|
29888
31378
|
* Emits all signal events regardless of execution mode.
|
|
@@ -29993,6 +31483,22 @@ declare const riskSubject: Subject<RiskContract>;
|
|
|
29993
31483
|
* Allows users to track scheduled signal lifecycle and implement custom cancellation logic.
|
|
29994
31484
|
*/
|
|
29995
31485
|
declare const schedulePingSubject: Subject<SchedulePingContract>;
|
|
31486
|
+
/**
|
|
31487
|
+
* Scheduled signal lifecycle emitter (creation and cancellation).
|
|
31488
|
+
* Emits when a scheduled signal is created (action "scheduled") or cancelled before
|
|
31489
|
+
* activation (action "cancelled": timeout / price_reject / user) during tick()/backtest().
|
|
31490
|
+
*
|
|
31491
|
+
* The scheduled -> active transition (activation) is intentionally NOT emitted here — that
|
|
31492
|
+
* produces an "opened" signal on the regular signal emitters instead.
|
|
31493
|
+
*/
|
|
31494
|
+
declare const scheduleEventSubject: Subject<ScheduleEventContract>;
|
|
31495
|
+
/**
|
|
31496
|
+
* Pending signal lifecycle emitter (open and close).
|
|
31497
|
+
* Emits when a pending position is opened (action "opened": new signal / immediate / scheduled
|
|
31498
|
+
* or user activation) or closed (action "closed" with closeReason take_profit / stop_loss /
|
|
31499
|
+
* time_expired / closed) during tick()/backtest().
|
|
31500
|
+
*/
|
|
31501
|
+
declare const signalEventSubject: Subject<SignalEventContract>;
|
|
29996
31502
|
/**
|
|
29997
31503
|
* Active ping emitter for active pending signal monitoring events.
|
|
29998
31504
|
* Emits every minute when an active pending signal is being monitored.
|
|
@@ -30081,10 +31587,12 @@ declare const emitters_performanceEmitter: typeof performanceEmitter;
|
|
|
30081
31587
|
declare const emitters_progressBacktestEmitter: typeof progressBacktestEmitter;
|
|
30082
31588
|
declare const emitters_progressWalkerEmitter: typeof progressWalkerEmitter;
|
|
30083
31589
|
declare const emitters_riskSubject: typeof riskSubject;
|
|
31590
|
+
declare const emitters_scheduleEventSubject: typeof scheduleEventSubject;
|
|
30084
31591
|
declare const emitters_schedulePingSubject: typeof schedulePingSubject;
|
|
30085
31592
|
declare const emitters_shutdownEmitter: typeof shutdownEmitter;
|
|
30086
31593
|
declare const emitters_signalBacktestEmitter: typeof signalBacktestEmitter;
|
|
30087
31594
|
declare const emitters_signalEmitter: typeof signalEmitter;
|
|
31595
|
+
declare const emitters_signalEventSubject: typeof signalEventSubject;
|
|
30088
31596
|
declare const emitters_signalLiveEmitter: typeof signalLiveEmitter;
|
|
30089
31597
|
declare const emitters_signalNotifySubject: typeof signalNotifySubject;
|
|
30090
31598
|
declare const emitters_strategyCommitSubject: typeof strategyCommitSubject;
|
|
@@ -30095,7 +31603,7 @@ declare const emitters_walkerCompleteSubject: typeof walkerCompleteSubject;
|
|
|
30095
31603
|
declare const emitters_walkerEmitter: typeof walkerEmitter;
|
|
30096
31604
|
declare const emitters_walkerStopSubject: typeof walkerStopSubject;
|
|
30097
31605
|
declare namespace emitters {
|
|
30098
|
-
export { emitters_activePingSubject as activePingSubject, emitters_afterEndSubject as afterEndSubject, emitters_backtestScheduleOpenSubject as backtestScheduleOpenSubject, emitters_beforeStartSubject as beforeStartSubject, emitters_breakevenSubject as breakevenSubject, emitters_doneBacktestSubject as doneBacktestSubject, emitters_doneLiveSubject as doneLiveSubject, emitters_doneWalkerSubject as doneWalkerSubject, emitters_entrySubject as entrySubject, emitters_errorEmitter as errorEmitter, emitters_exitEmitter as exitEmitter, emitters_highestProfitSubject as highestProfitSubject, emitters_idlePingSubject as idlePingSubject, emitters_maxDrawdownSubject as maxDrawdownSubject, emitters_partialLossSubject as partialLossSubject, emitters_partialProfitSubject as partialProfitSubject, emitters_performanceEmitter as performanceEmitter, emitters_progressBacktestEmitter as progressBacktestEmitter, emitters_progressWalkerEmitter as progressWalkerEmitter, emitters_riskSubject as riskSubject, emitters_schedulePingSubject as schedulePingSubject, emitters_shutdownEmitter as shutdownEmitter, emitters_signalBacktestEmitter as signalBacktestEmitter, emitters_signalEmitter as signalEmitter, emitters_signalLiveEmitter as signalLiveEmitter, emitters_signalNotifySubject as signalNotifySubject, emitters_strategyCommitSubject as strategyCommitSubject, emitters_syncPendingSubject as syncPendingSubject, emitters_syncSubject as syncSubject, emitters_validationSubject as validationSubject, emitters_walkerCompleteSubject as walkerCompleteSubject, emitters_walkerEmitter as walkerEmitter, emitters_walkerStopSubject as walkerStopSubject };
|
|
31606
|
+
export { emitters_activePingSubject as activePingSubject, emitters_afterEndSubject as afterEndSubject, emitters_backtestScheduleOpenSubject as backtestScheduleOpenSubject, emitters_beforeStartSubject as beforeStartSubject, emitters_breakevenSubject as breakevenSubject, emitters_doneBacktestSubject as doneBacktestSubject, emitters_doneLiveSubject as doneLiveSubject, emitters_doneWalkerSubject as doneWalkerSubject, emitters_entrySubject as entrySubject, emitters_errorEmitter as errorEmitter, emitters_exitEmitter as exitEmitter, emitters_highestProfitSubject as highestProfitSubject, emitters_idlePingSubject as idlePingSubject, emitters_maxDrawdownSubject as maxDrawdownSubject, emitters_partialLossSubject as partialLossSubject, emitters_partialProfitSubject as partialProfitSubject, emitters_performanceEmitter as performanceEmitter, emitters_progressBacktestEmitter as progressBacktestEmitter, emitters_progressWalkerEmitter as progressWalkerEmitter, emitters_riskSubject as riskSubject, emitters_scheduleEventSubject as scheduleEventSubject, emitters_schedulePingSubject as schedulePingSubject, emitters_shutdownEmitter as shutdownEmitter, emitters_signalBacktestEmitter as signalBacktestEmitter, emitters_signalEmitter as signalEmitter, emitters_signalEventSubject as signalEventSubject, emitters_signalLiveEmitter as signalLiveEmitter, emitters_signalNotifySubject as signalNotifySubject, emitters_strategyCommitSubject as strategyCommitSubject, emitters_syncPendingSubject as syncPendingSubject, emitters_syncSubject as syncSubject, emitters_validationSubject as validationSubject, emitters_walkerCompleteSubject as walkerCompleteSubject, emitters_walkerEmitter as walkerEmitter, emitters_walkerStopSubject as walkerStopSubject };
|
|
30099
31607
|
}
|
|
30100
31608
|
|
|
30101
31609
|
/**
|
|
@@ -30139,10 +31647,13 @@ declare const waitForCandle: (interval: CandleInterval) => Promise<number>;
|
|
|
30139
31647
|
* @param {string | number} price - The price to round, can be a string or number
|
|
30140
31648
|
* @param {number} tickSize - The tick size that determines the precision (e.g., 0.01 for 2 decimal places)
|
|
30141
31649
|
* @returns {string} The price rounded to the precision specified by the tick size
|
|
31650
|
+
* @throws {Error} If tickSize is not a positive finite number
|
|
30142
31651
|
*
|
|
30143
31652
|
* @example
|
|
30144
31653
|
* roundTicks(123.456789, 0.01) // returns "123.46"
|
|
30145
31654
|
* roundTicks("100.12345", 0.001) // returns "100.123"
|
|
31655
|
+
* roundTicks(123.456789, 1) // returns "123"
|
|
31656
|
+
* roundTicks(123.456789, 1e-9) // returns "123.456789000"
|
|
30146
31657
|
*/
|
|
30147
31658
|
declare const roundTicks: (price: string | number, tickSize: number) => string;
|
|
30148
31659
|
|
|
@@ -30300,69 +31811,113 @@ declare const set: (object: any, path: any, value: any) => boolean;
|
|
|
30300
31811
|
|
|
30301
31812
|
/**
|
|
30302
31813
|
* Calculate the percentage difference between two numbers.
|
|
31814
|
+
*
|
|
31815
|
+
* The result is how many percent the larger value exceeds the smaller one:
|
|
31816
|
+
* percentDiff(100, 150) === 50, percentDiff(150, 100) === 50.
|
|
31817
|
+
*
|
|
31818
|
+
* Edge cases are reported honestly instead of a sentinel value:
|
|
31819
|
+
* - Both values equal (including 0, 0) — returns 0.
|
|
31820
|
+
* - One value is 0 and the other is not — returns Infinity
|
|
31821
|
+
* (the difference is unbounded; no finite percent can express it).
|
|
31822
|
+
*
|
|
30303
31823
|
* @param {number} a - The first number.
|
|
30304
31824
|
* @param {number} b - The second number.
|
|
30305
31825
|
* @returns {number} The percentage difference between the two numbers.
|
|
30306
31826
|
*/
|
|
30307
|
-
declare const percentDiff: (a
|
|
31827
|
+
declare const percentDiff: (a: number, b: number) => number;
|
|
30308
31828
|
|
|
30309
31829
|
/**
|
|
30310
31830
|
* Calculate the percentage change from yesterday's value to today's value.
|
|
30311
|
-
*
|
|
31831
|
+
*
|
|
31832
|
+
* Formula: ((todayValue - yesterdayValue) / yesterdayValue) * 100
|
|
31833
|
+
*
|
|
31834
|
+
* Positive result — value grew, negative — value dropped.
|
|
31835
|
+
*
|
|
31836
|
+
* @param {number} yesterdayValue - The value from yesterday (base of comparison).
|
|
30312
31837
|
* @param {number} todayValue - The value from today.
|
|
30313
|
-
* @returns {number} The percentage change from yesterday to today.
|
|
31838
|
+
* @returns {number} The percentage change from yesterday to today (e.g. 5 for +5%).
|
|
31839
|
+
*
|
|
31840
|
+
* @example
|
|
31841
|
+
* percentValue(100, 105); // 5
|
|
31842
|
+
* percentValue(100, 95); // -5
|
|
30314
31843
|
*/
|
|
30315
31844
|
declare const percentValue: (yesterdayValue: number, todayValue: number) => number;
|
|
30316
31845
|
|
|
30317
31846
|
/**
|
|
30318
|
-
* Convert an absolute dollar amount to a percentage of
|
|
31847
|
+
* Convert an absolute dollar amount to a percentage of a cost basis.
|
|
30319
31848
|
* Use the result as the `percent` argument to `commitPartialProfit` / `commitPartialLoss`.
|
|
30320
31849
|
*
|
|
31850
|
+
* IMPORTANT: `percentToClose` in partial closes is applied to the REMAINING
|
|
31851
|
+
* cost basis (what is still held after prior partials), not to the total
|
|
31852
|
+
* invested amount. To close an exact dollar amount, pass the remaining cost
|
|
31853
|
+
* basis from `getTotalCostClosed` as `costBasis` — not `getPositionInvestedCost`.
|
|
31854
|
+
*
|
|
30321
31855
|
* @param dollarAmount - Dollar value to close (e.g. 150)
|
|
30322
|
-
* @param
|
|
30323
|
-
* @returns Percentage of the position to close (0–100)
|
|
31856
|
+
* @param costBasis - Remaining cost basis from `getTotalCostClosed` (e.g. 300)
|
|
31857
|
+
* @returns Percentage of the remaining position to close (0–100)
|
|
30324
31858
|
*
|
|
30325
31859
|
* @example
|
|
30326
|
-
* const
|
|
31860
|
+
* const remaining = await getTotalCostClosed("BTCUSDT"); // e.g. 300
|
|
31861
|
+
* const percent = investedCostToPercent(150, remaining); // 50
|
|
30327
31862
|
* await commitPartialProfit("BTCUSDT", percent);
|
|
30328
31863
|
*/
|
|
30329
|
-
declare const investedCostToPercent: (dollarAmount: number,
|
|
31864
|
+
declare const investedCostToPercent: (dollarAmount: number, costBasis: number) => number;
|
|
30330
31865
|
|
|
30331
31866
|
/**
|
|
30332
31867
|
* Convert an absolute stop-loss price to a percentShift for `commitTrailingStop`.
|
|
30333
31868
|
*
|
|
30334
31869
|
* percentShift = newSlDistancePercent - originalSlDistancePercent
|
|
30335
|
-
*
|
|
31870
|
+
*
|
|
31871
|
+
* The new distance is SIGNED by position direction (mirrors how ClientStrategy
|
|
31872
|
+
* applies the shift): a stop-loss moved past the entry into the profit zone
|
|
31873
|
+
* produces a negative distance, so any target price is expressible —
|
|
31874
|
+
* `slPercentShiftToPrice(slPriceToPercentShift(x, ...), ...) === x` holds for
|
|
31875
|
+
* targets on both sides of the entry.
|
|
31876
|
+
*
|
|
31877
|
+
* LONG: newSlDistancePercent = (effectivePriceOpen - newStopLossPrice) / effectivePriceOpen * 100
|
|
31878
|
+
* SHORT: newSlDistancePercent = (newStopLossPrice - effectivePriceOpen) / effectivePriceOpen * 100
|
|
30336
31879
|
*
|
|
30337
31880
|
* @param newStopLossPrice - Desired absolute stop-loss price
|
|
30338
31881
|
* @param originalStopLossPrice - Original stop-loss price from the pending signal
|
|
30339
31882
|
* @param effectivePriceOpen - Effective entry price (from `getPositionEffectivePrice`)
|
|
31883
|
+
* @param position - Position direction: "long" or "short"
|
|
30340
31884
|
* @returns percentShift to pass to `commitTrailingStop`
|
|
30341
31885
|
*
|
|
30342
31886
|
* @example
|
|
30343
31887
|
* // LONG: entry=100, originalSL=90, desired newSL=95
|
|
30344
|
-
* const shift = slPriceToPercentShift(95, 90, 100); // -5
|
|
31888
|
+
* const shift = slPriceToPercentShift(95, 90, 100, "long"); // -5
|
|
31889
|
+
* // LONG: entry=100, originalSL=90, desired newSL=105 (profit zone)
|
|
31890
|
+
* const shiftProfit = slPriceToPercentShift(105, 90, 100, "long"); // -15
|
|
30345
31891
|
* await commitTrailingStop("BTCUSDT", shift, currentPrice);
|
|
30346
31892
|
*/
|
|
30347
|
-
declare const slPriceToPercentShift: (newStopLossPrice: number, originalStopLossPrice: number, effectivePriceOpen: number) => number;
|
|
31893
|
+
declare const slPriceToPercentShift: (newStopLossPrice: number, originalStopLossPrice: number, effectivePriceOpen: number, position: "long" | "short") => number;
|
|
30348
31894
|
|
|
30349
31895
|
/**
|
|
30350
31896
|
* Convert an absolute take-profit price to a percentShift for `commitTrailingTake`.
|
|
30351
31897
|
*
|
|
30352
31898
|
* percentShift = newTpDistancePercent - originalTpDistancePercent
|
|
30353
|
-
*
|
|
31899
|
+
*
|
|
31900
|
+
* The new distance is SIGNED by position direction (mirrors how ClientStrategy
|
|
31901
|
+
* applies the shift): a take-profit moved past the entry produces a negative
|
|
31902
|
+
* distance, so any target price is expressible —
|
|
31903
|
+
* `tpPercentShiftToPrice(tpPriceToPercentShift(x, ...), ...) === x` holds for
|
|
31904
|
+
* targets on both sides of the entry.
|
|
31905
|
+
*
|
|
31906
|
+
* LONG: newTpDistancePercent = (newTakeProfitPrice - effectivePriceOpen) / effectivePriceOpen * 100
|
|
31907
|
+
* SHORT: newTpDistancePercent = (effectivePriceOpen - newTakeProfitPrice) / effectivePriceOpen * 100
|
|
30354
31908
|
*
|
|
30355
31909
|
* @param newTakeProfitPrice - Desired absolute take-profit price
|
|
30356
31910
|
* @param originalTakeProfitPrice - Original take-profit price from the pending signal
|
|
30357
31911
|
* @param effectivePriceOpen - Effective entry price (from `getPositionEffectivePrice`)
|
|
31912
|
+
* @param position - Position direction: "long" or "short"
|
|
30358
31913
|
* @returns percentShift to pass to `commitTrailingTake`
|
|
30359
31914
|
*
|
|
30360
31915
|
* @example
|
|
30361
31916
|
* // LONG: entry=100, originalTP=110, desired newTP=107
|
|
30362
|
-
* const shift = tpPriceToPercentShift(107, 110, 100); // -3
|
|
31917
|
+
* const shift = tpPriceToPercentShift(107, 110, 100, "long"); // -3
|
|
30363
31918
|
* await commitTrailingTake("BTCUSDT", shift, currentPrice);
|
|
30364
31919
|
*/
|
|
30365
|
-
declare const tpPriceToPercentShift: (newTakeProfitPrice: number, originalTakeProfitPrice: number, effectivePriceOpen: number) => number;
|
|
31920
|
+
declare const tpPriceToPercentShift: (newTakeProfitPrice: number, originalTakeProfitPrice: number, effectivePriceOpen: number, position: "long" | "short") => number;
|
|
30366
31921
|
|
|
30367
31922
|
/**
|
|
30368
31923
|
* Convert a percentShift for `commitTrailingStop` back to an absolute stop-loss price.
|
|
@@ -31228,6 +32783,38 @@ declare class ActionCoreService implements TAction$1 {
|
|
|
31228
32783
|
exchangeName: ExchangeName;
|
|
31229
32784
|
frameName: FrameName;
|
|
31230
32785
|
}) => Promise<void>;
|
|
32786
|
+
/**
|
|
32787
|
+
* Routes a scheduled signal lifecycle event (creation / cancellation) to all registered actions.
|
|
32788
|
+
*
|
|
32789
|
+
* Retrieves action list from strategy schema (IStrategySchema.actions) and invokes the
|
|
32790
|
+
* scheduleEvent handler on each ClientAction instance sequentially. Called once on creation
|
|
32791
|
+
* (action "scheduled") and once on cancellation before activation (action "cancelled").
|
|
32792
|
+
*
|
|
32793
|
+
* @param backtest - Whether running in backtest mode (true) or live mode (false)
|
|
32794
|
+
* @param event - Scheduled lifecycle event data (action discriminates created vs cancelled)
|
|
32795
|
+
* @param context - Strategy execution context with strategyName, exchangeName, frameName
|
|
32796
|
+
*/
|
|
32797
|
+
scheduleEvent: (backtest: boolean, event: ScheduleEventContract, context: {
|
|
32798
|
+
strategyName: StrategyName;
|
|
32799
|
+
exchangeName: ExchangeName;
|
|
32800
|
+
frameName: FrameName;
|
|
32801
|
+
}) => Promise<void>;
|
|
32802
|
+
/**
|
|
32803
|
+
* Routes a pending signal lifecycle event (open / close) to all registered actions.
|
|
32804
|
+
*
|
|
32805
|
+
* Retrieves action list from strategy schema (IStrategySchema.actions) and invokes the
|
|
32806
|
+
* pendingEvent handler on each ClientAction instance sequentially. Called once on open
|
|
32807
|
+
* (action "opened") and once on close (action "closed").
|
|
32808
|
+
*
|
|
32809
|
+
* @param backtest - Whether running in backtest mode (true) or live mode (false)
|
|
32810
|
+
* @param event - Pending lifecycle event data (action discriminates opened vs closed)
|
|
32811
|
+
* @param context - Strategy execution context with strategyName, exchangeName, frameName
|
|
32812
|
+
*/
|
|
32813
|
+
pendingEvent: (backtest: boolean, event: SignalEventContract, context: {
|
|
32814
|
+
strategyName: StrategyName;
|
|
32815
|
+
exchangeName: ExchangeName;
|
|
32816
|
+
frameName: FrameName;
|
|
32817
|
+
}) => Promise<void>;
|
|
31231
32818
|
/**
|
|
31232
32819
|
* Routes active ping event to all registered actions for the strategy.
|
|
31233
32820
|
*
|
|
@@ -31285,7 +32872,7 @@ declare class ActionCoreService implements TAction$1 {
|
|
|
31285
32872
|
* @param event - Sync event with action "signal-open" or "signal-close"
|
|
31286
32873
|
* @param context - Strategy execution context
|
|
31287
32874
|
*/
|
|
31288
|
-
|
|
32875
|
+
orderSync: (backtest: boolean, event: OrderSyncContract, context: {
|
|
31289
32876
|
strategyName: StrategyName;
|
|
31290
32877
|
exchangeName: ExchangeName;
|
|
31291
32878
|
frameName: FrameName;
|
|
@@ -31298,7 +32885,7 @@ declare class ActionCoreService implements TAction$1 {
|
|
|
31298
32885
|
* @param event - Pending-ping event with action "signal-ping"
|
|
31299
32886
|
* @param context - Strategy execution context
|
|
31300
32887
|
*/
|
|
31301
|
-
|
|
32888
|
+
orderCheck: (backtest: boolean, event: OrderCheckContract, context: {
|
|
31302
32889
|
strategyName: StrategyName;
|
|
31303
32890
|
exchangeName: ExchangeName;
|
|
31304
32891
|
frameName: FrameName;
|
|
@@ -32707,6 +34294,42 @@ declare class StrategyConnectionService implements TStrategy$1 {
|
|
|
32707
34294
|
exchangeName: ExchangeName;
|
|
32708
34295
|
frameName: FrameName;
|
|
32709
34296
|
}) => Promise<void>;
|
|
34297
|
+
/**
|
|
34298
|
+
* Reports that the pending position's take-profit order was actually filled on the exchange
|
|
34299
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based TP check.
|
|
34300
|
+
*
|
|
34301
|
+
* Delegates to ClientStrategy.createTakeProfit(). The close is deferred and emitted with
|
|
34302
|
+
* closeReason "take_profit" on the next tick()/backtest(). Works out of the execution context.
|
|
34303
|
+
*
|
|
34304
|
+
* @param backtest - Whether running in backtest mode
|
|
34305
|
+
* @param symbol - Trading pair symbol
|
|
34306
|
+
* @param context - Context with strategyName, exchangeName, frameName
|
|
34307
|
+
* @param payload - Optional commit payload with id and note
|
|
34308
|
+
* @returns Promise that resolves when the take-profit fill is queued
|
|
34309
|
+
*/
|
|
34310
|
+
createTakeProfit: (backtest: boolean, symbol: string, context: {
|
|
34311
|
+
strategyName: StrategyName;
|
|
34312
|
+
exchangeName: ExchangeName;
|
|
34313
|
+
frameName: FrameName;
|
|
34314
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
34315
|
+
/**
|
|
34316
|
+
* Reports that the pending position's stop-loss order was actually filled on the exchange
|
|
34317
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based SL check.
|
|
34318
|
+
*
|
|
34319
|
+
* Delegates to ClientStrategy.createStopLoss(). The close is deferred and emitted with
|
|
34320
|
+
* closeReason "stop_loss" on the next tick()/backtest(). Works out of the execution context.
|
|
34321
|
+
*
|
|
34322
|
+
* @param backtest - Whether running in backtest mode
|
|
34323
|
+
* @param symbol - Trading pair symbol
|
|
34324
|
+
* @param context - Context with strategyName, exchangeName, frameName
|
|
34325
|
+
* @param payload - Optional commit payload with id and note
|
|
34326
|
+
* @returns Promise that resolves when the stop-loss fill is queued
|
|
34327
|
+
*/
|
|
34328
|
+
createStopLoss: (backtest: boolean, symbol: string, context: {
|
|
34329
|
+
strategyName: StrategyName;
|
|
34330
|
+
exchangeName: ExchangeName;
|
|
34331
|
+
frameName: FrameName;
|
|
34332
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
32710
34333
|
/**
|
|
32711
34334
|
* Returns the in-memory deferred strategy-state snapshot for this iteration.
|
|
32712
34335
|
*
|
|
@@ -33086,6 +34709,19 @@ declare class FrameConnectionService implements IFrame {
|
|
|
33086
34709
|
* @returns Configured ClientFrame instance
|
|
33087
34710
|
*/
|
|
33088
34711
|
getFrame: ((frameName: FrameName) => ClientFrame) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientFrame>;
|
|
34712
|
+
/**
|
|
34713
|
+
* Disposes cached ClientFrame instance(s) so the next getTimeframe call
|
|
34714
|
+
* regenerates timeframes. Without this, ClientFrame's singleshot would keep
|
|
34715
|
+
* the endDate-to-now clamp frozen at the moment of the first run: a
|
|
34716
|
+
* long-running process re-running the same frame would silently backtest
|
|
34717
|
+
* against stale timeframes and never see newly available candles.
|
|
34718
|
+
*
|
|
34719
|
+
* When called without arguments, clears all memoized frames.
|
|
34720
|
+
* Called by Backtest/Walker at strategy start.
|
|
34721
|
+
*
|
|
34722
|
+
* @param frameName - Frame to clear; omit to clear all frames
|
|
34723
|
+
*/
|
|
34724
|
+
clear: (frameName?: FrameName) => void;
|
|
33089
34725
|
/**
|
|
33090
34726
|
* Retrieves backtest timeframe boundaries for symbol.
|
|
33091
34727
|
*
|
|
@@ -33328,6 +34964,27 @@ declare class ActionProxy implements IPublicAction {
|
|
|
33328
34964
|
* @returns Promise resolving to user's pingScheduled() result or null on error
|
|
33329
34965
|
*/
|
|
33330
34966
|
pingScheduled(event: SchedulePingContract): Promise<any>;
|
|
34967
|
+
/**
|
|
34968
|
+
* Handles scheduled signal lifecycle events with error capture.
|
|
34969
|
+
*
|
|
34970
|
+
* Wraps the user's scheduleEvent() method to catch and log any errors. Called once when a
|
|
34971
|
+
* scheduled signal is created (action "scheduled") and once when it is cancelled before
|
|
34972
|
+
* activation (action "cancelled").
|
|
34973
|
+
*
|
|
34974
|
+
* @param event - Scheduled lifecycle data (action discriminates created vs cancelled)
|
|
34975
|
+
* @returns Promise resolving to user's scheduleEvent() result or null on error
|
|
34976
|
+
*/
|
|
34977
|
+
scheduleEvent(event: ScheduleEventContract): Promise<any>;
|
|
34978
|
+
/**
|
|
34979
|
+
* Handles pending signal lifecycle events with error capture.
|
|
34980
|
+
*
|
|
34981
|
+
* Wraps the user's pendingEvent() method to catch and log any errors. Called once when a
|
|
34982
|
+
* pending position is opened (action "opened") and once when it is closed (action "closed").
|
|
34983
|
+
*
|
|
34984
|
+
* @param event - Pending lifecycle data (action discriminates opened vs closed)
|
|
34985
|
+
* @returns Promise resolving to user's pendingEvent() result or null on error
|
|
34986
|
+
*/
|
|
34987
|
+
pendingEvent(event: SignalEventContract): Promise<any>;
|
|
33331
34988
|
/**
|
|
33332
34989
|
* Handles active ping events with error capture.
|
|
33333
34990
|
*
|
|
@@ -33364,14 +35021,16 @@ declare class ActionProxy implements IPublicAction {
|
|
|
33364
35021
|
*
|
|
33365
35022
|
* @param event - Sync event with action "signal-open" or "signal-close"
|
|
33366
35023
|
*/
|
|
33367
|
-
|
|
35024
|
+
orderSync(event: OrderSyncContract): Promise<void>;
|
|
33368
35025
|
/**
|
|
33369
|
-
* Gate for the
|
|
35026
|
+
* Gate for the order ping (order still open on exchange?). Fires for both
|
|
35027
|
+
* monitored states: event.type "active" (open position order) and "schedule"
|
|
35028
|
+
* (resting entry order of a scheduled signal).
|
|
33370
35029
|
* NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_PENDING_FN.
|
|
33371
35030
|
*
|
|
33372
|
-
* @param event -
|
|
35031
|
+
* @param event - Order-ping event with action "signal-ping" and type "schedule" | "active"
|
|
33373
35032
|
*/
|
|
33374
|
-
|
|
35033
|
+
orderCheck(event: OrderCheckContract): Promise<void>;
|
|
33375
35034
|
/**
|
|
33376
35035
|
* Cleans up resources with error capture.
|
|
33377
35036
|
*
|
|
@@ -33506,6 +35165,22 @@ declare class ClientAction implements IAction {
|
|
|
33506
35165
|
* Handles scheduled ping events during scheduled signal monitoring.
|
|
33507
35166
|
*/
|
|
33508
35167
|
pingScheduled(event: SchedulePingContract): Promise<void>;
|
|
35168
|
+
/**
|
|
35169
|
+
* Handles scheduled signal lifecycle events (creation / cancellation).
|
|
35170
|
+
*
|
|
35171
|
+
* Manual wiring — EVENT-BASED: users implement {@link IActionCallbacks.onScheduleEvent} (via `addActionSchema`)
|
|
35172
|
+
* to drive the exchange (`commitActivateScheduled` / `commitCancelScheduled`); see that contract
|
|
35173
|
+
* for the full guidance and example. This internal dispatch forwards to the handler/callback.
|
|
35174
|
+
*/
|
|
35175
|
+
scheduleEvent(event: ScheduleEventContract): Promise<void>;
|
|
35176
|
+
/**
|
|
35177
|
+
* Handles pending signal lifecycle events (open / close).
|
|
35178
|
+
*
|
|
35179
|
+
* Manual wiring — EVENT-BASED: users implement {@link IActionCallbacks.onPendingEvent} (via `addActionSchema`) to
|
|
35180
|
+
* drive the exchange; for per-tick fills use `onPingActive`. See that contract for the full
|
|
35181
|
+
* guidance and example. This internal dispatch forwards to the handler/callback.
|
|
35182
|
+
*/
|
|
35183
|
+
pendingEvent(event: SignalEventContract): Promise<void>;
|
|
33509
35184
|
/**
|
|
33510
35185
|
* Handles active ping events during active pending signal monitoring.
|
|
33511
35186
|
*/
|
|
@@ -33522,12 +35197,12 @@ declare class ClientAction implements IAction {
|
|
|
33522
35197
|
* Gate for position open/close via limit order.
|
|
33523
35198
|
* NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_FN.
|
|
33524
35199
|
*/
|
|
33525
|
-
|
|
35200
|
+
orderSync(event: OrderSyncContract): Promise<void>;
|
|
33526
35201
|
/**
|
|
33527
35202
|
* Gate for the pending-order ping (order still open on exchange?).
|
|
33528
35203
|
* NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_PENDING_FN.
|
|
33529
35204
|
*/
|
|
33530
|
-
|
|
35205
|
+
orderCheck(event: OrderCheckContract): Promise<void>;
|
|
33531
35206
|
/**
|
|
33532
35207
|
* Cleans up resources and subscriptions when action handler is no longer needed.
|
|
33533
35208
|
* Uses singleshot pattern to ensure cleanup happens exactly once.
|
|
@@ -33693,6 +35368,32 @@ declare class ActionConnectionService implements TAction {
|
|
|
33693
35368
|
exchangeName: ExchangeName;
|
|
33694
35369
|
frameName: FrameName;
|
|
33695
35370
|
}) => Promise<void>;
|
|
35371
|
+
/**
|
|
35372
|
+
* Routes a scheduled signal lifecycle event (creation / cancellation) to the ClientAction instance.
|
|
35373
|
+
*
|
|
35374
|
+
* @param event - Scheduled lifecycle event data (action discriminates created vs cancelled)
|
|
35375
|
+
* @param backtest - Whether running in backtest mode
|
|
35376
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
35377
|
+
*/
|
|
35378
|
+
scheduleEvent: (event: ScheduleEventContract, backtest: boolean, context: {
|
|
35379
|
+
actionName: ActionName;
|
|
35380
|
+
strategyName: StrategyName;
|
|
35381
|
+
exchangeName: ExchangeName;
|
|
35382
|
+
frameName: FrameName;
|
|
35383
|
+
}) => Promise<void>;
|
|
35384
|
+
/**
|
|
35385
|
+
* Routes a pending signal lifecycle event (open / close) to the ClientAction instance.
|
|
35386
|
+
*
|
|
35387
|
+
* @param event - Pending lifecycle event data (action discriminates opened vs closed)
|
|
35388
|
+
* @param backtest - Whether running in backtest mode
|
|
35389
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
35390
|
+
*/
|
|
35391
|
+
pendingEvent: (event: SignalEventContract, backtest: boolean, context: {
|
|
35392
|
+
actionName: ActionName;
|
|
35393
|
+
strategyName: StrategyName;
|
|
35394
|
+
exchangeName: ExchangeName;
|
|
35395
|
+
frameName: FrameName;
|
|
35396
|
+
}) => Promise<void>;
|
|
33696
35397
|
/**
|
|
33697
35398
|
* Routes active ping event to appropriate ClientAction instance.
|
|
33698
35399
|
*
|
|
@@ -33733,7 +35434,7 @@ declare class ActionConnectionService implements TAction {
|
|
|
33733
35434
|
frameName: FrameName;
|
|
33734
35435
|
}) => Promise<void>;
|
|
33735
35436
|
/**
|
|
33736
|
-
* Routes
|
|
35437
|
+
* Routes orderSync event to appropriate ClientAction instance.
|
|
33737
35438
|
* NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_FN.
|
|
33738
35439
|
*
|
|
33739
35440
|
* @param event - Sync event with action "signal-open" or "signal-close"
|
|
@@ -33741,21 +35442,21 @@ declare class ActionConnectionService implements TAction {
|
|
|
33741
35442
|
* @param context - Execution context
|
|
33742
35443
|
* @returns true to allow, false to reject
|
|
33743
35444
|
*/
|
|
33744
|
-
|
|
35445
|
+
orderSync: (event: OrderSyncContract, backtest: boolean, context: {
|
|
33745
35446
|
actionName: ActionName;
|
|
33746
35447
|
strategyName: StrategyName;
|
|
33747
35448
|
exchangeName: ExchangeName;
|
|
33748
35449
|
frameName: FrameName;
|
|
33749
35450
|
}) => Promise<void>;
|
|
33750
35451
|
/**
|
|
33751
|
-
* Routes
|
|
35452
|
+
* Routes orderCheck event to appropriate ClientAction instance.
|
|
33752
35453
|
* NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_PENDING_FN.
|
|
33753
35454
|
*
|
|
33754
35455
|
* @param event - Pending-ping event with action "signal-ping"
|
|
33755
35456
|
* @param backtest - Whether running in backtest mode
|
|
33756
35457
|
* @param context - Execution context
|
|
33757
35458
|
*/
|
|
33758
|
-
|
|
35459
|
+
orderCheck: (event: OrderCheckContract, backtest: boolean, context: {
|
|
33759
35460
|
actionName: ActionName;
|
|
33760
35461
|
strategyName: StrategyName;
|
|
33761
35462
|
exchangeName: ExchangeName;
|
|
@@ -34344,6 +36045,44 @@ declare class StrategyCoreService implements TStrategy {
|
|
|
34344
36045
|
exchangeName: ExchangeName;
|
|
34345
36046
|
frameName: FrameName;
|
|
34346
36047
|
}) => Promise<void>;
|
|
36048
|
+
/**
|
|
36049
|
+
* Reports that the pending position's take-profit order was actually filled on the exchange
|
|
36050
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based TP check.
|
|
36051
|
+
*
|
|
36052
|
+
* Validates the context, then delegates to StrategyConnectionService.createTakeProfit().
|
|
36053
|
+
* The close is deferred and emitted with closeReason "take_profit" on the next tick/backtest.
|
|
36054
|
+
* Does not require execution context.
|
|
36055
|
+
*
|
|
36056
|
+
* @param backtest - Whether running in backtest mode
|
|
36057
|
+
* @param symbol - Trading pair symbol
|
|
36058
|
+
* @param context - Context with strategyName, exchangeName, frameName
|
|
36059
|
+
* @param payload - Optional commit payload with id and note
|
|
36060
|
+
* @returns Promise that resolves when the take-profit fill is queued
|
|
36061
|
+
*/
|
|
36062
|
+
createTakeProfit: (backtest: boolean, symbol: string, context: {
|
|
36063
|
+
strategyName: StrategyName;
|
|
36064
|
+
exchangeName: ExchangeName;
|
|
36065
|
+
frameName: FrameName;
|
|
36066
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
36067
|
+
/**
|
|
36068
|
+
* Reports that the pending position's stop-loss order was actually filled on the exchange
|
|
36069
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based SL check.
|
|
36070
|
+
*
|
|
36071
|
+
* Validates the context, then delegates to StrategyConnectionService.createStopLoss().
|
|
36072
|
+
* The close is deferred and emitted with closeReason "stop_loss" on the next tick/backtest.
|
|
36073
|
+
* Does not require execution context.
|
|
36074
|
+
*
|
|
36075
|
+
* @param backtest - Whether running in backtest mode
|
|
36076
|
+
* @param symbol - Trading pair symbol
|
|
36077
|
+
* @param context - Context with strategyName, exchangeName, frameName
|
|
36078
|
+
* @param payload - Optional commit payload with id and note
|
|
36079
|
+
* @returns Promise that resolves when the stop-loss fill is queued
|
|
36080
|
+
*/
|
|
36081
|
+
createStopLoss: (backtest: boolean, symbol: string, context: {
|
|
36082
|
+
strategyName: StrategyName;
|
|
36083
|
+
exchangeName: ExchangeName;
|
|
36084
|
+
frameName: FrameName;
|
|
36085
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
34347
36086
|
/**
|
|
34348
36087
|
* Returns the in-memory deferred strategy-state snapshot for this iteration.
|
|
34349
36088
|
*
|
|
@@ -38100,4 +39839,4 @@ declare const getTotalClosed: (signal: Signal) => {
|
|
|
38100
39839
|
*/
|
|
38101
39840
|
declare const getPriceScale: (value: number) => number;
|
|
38102
39841
|
|
|
38103
|
-
export { ActionBase, type ActivateScheduledCommit, type ActivateScheduledCommitNotification, type ActivePingContract, type AfterEndContract, type AverageBuyCommit, type AverageBuyCommitNotification, Backtest, type BacktestStatisticsModel, type BeforeStartContract, Breakeven, type BreakevenAvailableNotification, type BreakevenCommit, type BreakevenCommitNotification, type BreakevenContract, type BreakevenData, type BreakevenEvent, type BreakevenStatisticsModel, Broker, type BrokerAverageBuyPayload, BrokerBase, type BrokerBreakevenPayload, type BrokerPartialLossPayload, type BrokerPartialProfitPayload, type BrokerSignalClosePayload, type BrokerSignalOpenPayload, type BrokerSignalPendingPayload, type BrokerTrailingStopPayload, type BrokerTrailingTakePayload, Cache, type CancelScheduledCommit, type CancelScheduledCommitNotification, type CandleData, type CandleInterval, type ClosePendingCommit, type ClosePendingCommitNotification, type ColumnConfig, type ColumnModel, type CommitPayload, Constant, type CriticalErrorNotification, Cron, type CronCallback, type CronEntry, type CronHandle, type DoneContract, Dump, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, HighestProfit, type HighestProfitContract, type HighestProfitEvent, type HighestProfitStatisticsModel, type IActionSchema, type IActivateScheduledCommitRow, type IAggregatedTradeData, type IBidData, type IBreakevenCommitRow, type IBroker, type ICandleData, type ICommitRow, type IDumpContext, type IDumpInstance, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type ILog, type ILogEntry, type ILogger, type IMarkdownDumpOptions, type IMemoryInstance, type INotificationUtils, type IOrderBookData, type IPartialLossCommitRow, type IPartialProfitCommitRow, type IPersistBase, type IPersistBreakevenInstance, type IPersistCandleInstance, type IPersistIntervalInstance, type IPersistLogInstance, type IPersistMeasureInstance, type IPersistMemoryInstance, type IPersistNotificationInstance, type IPersistPartialInstance, type IPersistRecentInstance, type IPersistRiskInstance, type IPersistScheduleInstance, type IPersistSessionInstance, type IPersistSignalInstance, type IPersistStateInstance, type IPersistStorageInstance, type IPersistStrategyInstance, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicAction, type IPublicCandleData, type IPublicSignalRow, type IRecentUtils, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskSignalRow, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IRuntimeInfo, type IRuntimeRange, type IScheduledSignalCancelRow, type IScheduledSignalRow, type ISessionInstance, type ISignalDto, type ISignalIntervalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingParams, type ISizingParamsATR, type ISizingParamsFixedPercentage, type ISizingParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStateInstance, type IStorageSignalRow, type IStorageUtils, type IStrategyPnL, type IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IStrategyTickResultWaiting, type ITrailingStopCommitRow, type ITrailingTakeCommitRow, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type IdlePingContract, type InfoErrorNotification, Interval, type IntervalData, Live, type LiveStatisticsModel, Log, type LogData, Lookup, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, MarkdownWriter, MaxDrawdown, type MaxDrawdownContract, type MaxDrawdownEvent, type MaxDrawdownStatisticsModel, type MeasureData, Memory, MemoryBacktest, MemoryBacktestAdapter, type MemoryData, MemoryLive, MemoryLiveAdapter, type MessageModel, type MessageRole, type MessageToolCall, MethodContextService, type MetricStats, Notification, NotificationBacktest, type NotificationData, NotificationLive, type NotificationModel, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossAvailableNotification, type PartialLossCommit, type PartialLossCommitNotification, type PartialLossContract, type PartialProfitAvailableNotification, type PartialProfitCommit, type PartialProfitCommitNotification, type PartialProfitContract, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistBreakevenAdapter, PersistBreakevenInstance, PersistCandleAdapter, PersistCandleInstance, PersistIntervalAdapter, PersistIntervalInstance, PersistLogAdapter, PersistLogInstance, PersistMeasureAdapter, PersistMeasureInstance, PersistMemoryAdapter, PersistMemoryInstance, PersistNotificationAdapter, PersistNotificationInstance, PersistPartialAdapter, PersistPartialInstance, PersistRecentAdapter, PersistRecentInstance, PersistRiskAdapter, PersistRiskInstance, PersistScheduleAdapter, PersistScheduleInstance, PersistSessionAdapter, PersistSessionInstance, PersistSignalAdapter, PersistSignalInstance, PersistStateAdapter, PersistStateInstance, PersistStorageAdapter, PersistStorageInstance, PersistStrategyAdapter, PersistStrategyInstance, Position, PositionSize, type ProgressBacktestContract, type ProgressWalkerContract, Recent, RecentBacktest, type RecentData, RecentLive, Reflect, Report, ReportBase, type ReportName, ReportWriter, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, type RuntimeData, Schedule, type ScheduleData, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, Session, SessionBacktest, type SessionData, SessionLive, type SignalCancelledNotification, type SignalCloseContract, type SignalClosedNotification, type SignalData, type SignalInfoContract, type SignalInfoNotification, type SignalInterval, type SignalOpenContract, type SignalOpenedNotification, type SignalPingContract, type SignalScheduledNotification, type SignalSyncCloseNotification, type SignalSyncContract, type SignalSyncOpenNotification, State, StateBacktest, StateBacktestAdapter, type StateData, StateLive, StateLiveAdapter, Storage, StorageBacktest, type StorageData, StorageLive, Strategy, type StrategyActionType, type StrategyCancelReason, type StrategyCloseReason, type StrategyCommitContract, type StrategyData, type StrategyEvent, type StrategyStatisticsModel, type StrategyStatus, Sync, type SyncEvent, type SyncStatisticsModel, System, type TBrokerCtor, type TDumpInstanceCtor, type TLogCtor, type TMarkdownBase, type TMemoryInstanceCtor, type TNotificationUtilsCtor, type TPersistBase, type TPersistBaseCtor, type TPersistBreakevenInstanceCtor, type TPersistCandleInstanceCtor, type TPersistIntervalInstanceCtor, type TPersistLogInstanceCtor, type TPersistMeasureInstanceCtor, type TPersistMemoryInstanceCtor, type TPersistNotificationInstanceCtor, type TPersistPartialInstanceCtor, type TPersistRecentInstanceCtor, type TPersistRiskInstanceCtor, type TPersistScheduleInstanceCtor, type TPersistSessionInstanceCtor, type TPersistSignalInstanceCtor, type TPersistStateInstanceCtor, type TPersistStorageInstanceCtor, type TPersistStrategyInstanceCtor, type TRecentUtilsCtor, type TReportBase, type TSessionInstanceCtor, type TStateInstanceCtor, type TStorageUtilsCtor, type TickEvent, type TrailingStopCommit, type TrailingStopCommitNotification, type TrailingTakeCommit, type TrailingTakeCommitNotification, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addActionSchema, addExchangeSchema, addFrameSchema, addRiskSchema, addSizingSchema, addStrategySchema, addWalkerSchema, alignToInterval, beginContext, beginTime, cacheCandles, checkCandles, commitActivateScheduled, commitAverageBuy, commitBreakeven, commitCancelScheduled, commitClosePending, commitCreateSignal, commitPartialLoss, commitPartialLossCost, commitPartialProfit, commitPartialProfitCost, commitSignalNotify, commitTrailingStop, commitTrailingStopCost, commitTrailingTake, commitTrailingTakeCost, createSignalState, dumpAgentAnswer, dumpError, dumpJson, dumpRecord, dumpTable, dumpText, emitters, formatPrice, formatQuantity, get, getActionSchema, getAggregatedTrades, getAveragePrice, getBacktestTimeframe, getBreakeven, getCandles, getClosePrice, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getEffectivePriceOpen, getExchangeSchema, getFrameSchema, getLatestSignal, getMaxDrawdownDistancePnlCost, getMaxDrawdownDistancePnlPercentage, getMinutesSinceLatestSignalCreated, getMode, getNextCandles, getOrderBook, getPendingSignal, getPositionActiveMinutes, getPositionCountdownMinutes, getPositionDrawdownMinutes, getPositionEffectivePrice, getPositionEntries, getPositionEntryOverlap, getPositionEstimateMinutes, getPositionHighestMaxDrawdownPnlCost, getPositionHighestMaxDrawdownPnlPercentage, getPositionHighestPnlCost, getPositionHighestPnlPercentage, getPositionHighestProfitBreakeven, getPositionHighestProfitDistancePnlCost, getPositionHighestProfitDistancePnlPercentage, getPositionHighestProfitMinutes, getPositionHighestProfitPrice, getPositionHighestProfitTimestamp, getPositionInvestedCost, getPositionInvestedCount, getPositionLevels, getPositionMaxDrawdownMinutes, getPositionMaxDrawdownPnlCost, getPositionMaxDrawdownPnlPercentage, getPositionMaxDrawdownPrice, getPositionMaxDrawdownTimestamp, getPositionPartialOverlap, getPositionPartials, getPositionPnlCost, getPositionPnlPercent, getPositionWaitingMinutes, getPriceScale, getRawCandles, getRiskSchema, getRuntimeInfo, getScheduledSignal, getSessionData, getSignalState, getSizingSchema, getStrategySchema, getStrategyStatus, getSymbol, getTimestamp, getTotalClosed, getTotalCostClosed, getTotalPercentClosed, getWalkerSchema, hasNoPendingSignal, hasNoScheduledSignal, hasTradeContext, intervalStepMs, investedCostToPercent, backtest as lib, listExchangeSchema, listFrameSchema, listMemory, listRiskSchema, listSizingSchema, listStrategySchema, listWalkerSchema, listenActivePing, listenActivePingOnce, listenAfterEnd, listenAfterEndOnce, listenBacktestProgress, listenBeforeStart, listenBeforeStartOnce, listenBreakevenAvailable, listenBreakevenAvailableOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenHighestProfit, listenHighestProfitOnce, listenIdlePing, listenIdlePingOnce, listenMaxDrawdown, listenMaxDrawdownOnce, listenPartialLossAvailable, listenPartialLossAvailableOnce, listenPartialProfitAvailable, listenPartialProfitAvailableOnce, listenPerformance, listenRisk, listenRiskOnce, listenSchedulePing, listenSchedulePingOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalNotify, listenSignalNotifyOnce, listenSignalOnce, listenStrategyCommit, listenStrategyCommitOnce, listenSync, listenSyncOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, percentDiff, percentToCloseCost, percentValue, readMemory, removeMemory, roundTicks, runInMockContext, searchMemory, set, setColumns, setConfig, setLogger, setSessionData, setSignalState, shutdown, slPercentShiftToPrice, slPriceToPercentShift, stopStrategy, toPlainString, toProfitLossDto, tpPercentShiftToPrice, tpPriceToPercentShift, validate, validateCandles, validateCommonSignal, validatePendingSignal, validateScheduledSignal, validateSignal, waitForCandle, waitForReady, warmCandles, writeMemory };
|
|
39842
|
+
export { ActionBase, type ActivateScheduledCommit, type ActivateScheduledCommitNotification, type ActivePingContract, type AfterEndContract, type AverageBuyCommit, type AverageBuyCommitNotification, Backtest, type BacktestStatisticsModel, type BeforeStartContract, Breakeven, type BreakevenAvailableNotification, type BreakevenCommit, type BreakevenCommitNotification, type BreakevenContract, type BreakevenData, type BreakevenEvent, type BreakevenStatisticsModel, Broker, type BrokerActivePingPayload, type BrokerAverageBuyPayload, BrokerBase, type BrokerBreakevenPayload, type BrokerIdlePingPayload, type BrokerOrderCheckPayload, type BrokerOrderClosePayload, type BrokerOrderOpenPayload, type BrokerPartialLossPayload, type BrokerPartialProfitPayload, type BrokerPendingClosePayload, type BrokerPendingOpenPayload, type BrokerScheduleCancelledPayload, type BrokerScheduleOpenPayload, type BrokerSchedulePingPayload, type BrokerTrailingStopPayload, type BrokerTrailingTakePayload, Cache, type CancelScheduledCommit, type CancelScheduledCommitNotification, type CandleData, type CandleInterval, type ClosePendingCommit, type ClosePendingCommitNotification, type ColumnConfig, type ColumnModel, type CommitPayload, Constant, type CriticalErrorNotification, Cron, type CronCallback, type CronEntry, type CronHandle, type DoneContract, Dump, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, HighestProfit, type HighestProfitContract, type HighestProfitEvent, type HighestProfitStatisticsModel, type IActionSchema, type IActivateScheduledCommitRow, type IAggregatedTradeData, type IBidData, type IBreakevenCommitRow, type IBroker, type ICandleData, type ICommitRow, type IDumpContext, type IDumpInstance, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type ILog, type ILogEntry, type ILogger, type IMarkdownDumpOptions, type IMemoryInstance, type INotificationUtils, type IOrderBookData, type IPartialLossCommitRow, type IPartialProfitCommitRow, type IPersistBase, type IPersistBreakevenInstance, type IPersistCandleInstance, type IPersistIntervalInstance, type IPersistLogInstance, type IPersistMeasureInstance, type IPersistMemoryInstance, type IPersistNotificationInstance, type IPersistPartialInstance, type IPersistRecentInstance, type IPersistRiskInstance, type IPersistScheduleInstance, type IPersistSessionInstance, type IPersistSignalInstance, type IPersistStateInstance, type IPersistStorageInstance, type IPersistStrategyInstance, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicAction, type IPublicCandleData, type IPublicSignalRow, type IRecentUtils, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskSignalRow, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IRuntimeInfo, type IRuntimeRange, type IScheduledSignalCancelRow, type IScheduledSignalRow, type ISessionInstance, type ISignalDto, type ISignalIntervalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingParams, type ISizingParamsATR, type ISizingParamsFixedPercentage, type ISizingParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStateInstance, type IStorageSignalRow, type IStorageUtils, type IStrategyPnL, type IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IStrategyTickResultWaiting, type ITrailingStopCommitRow, type ITrailingTakeCommitRow, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type IdlePingContract, type InfoErrorNotification, Interval, type IntervalData, Live, type LiveStatisticsModel, Log, type LogData, Lookup, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, MarkdownWriter, MaxDrawdown, type MaxDrawdownContract, type MaxDrawdownEvent, type MaxDrawdownStatisticsModel, type MeasureData, Memory, MemoryBacktest, MemoryBacktestAdapter, type MemoryData, MemoryLive, MemoryLiveAdapter, type MessageModel, type MessageRole, type MessageToolCall, MethodContextService, type MetricStats, Notification, NotificationBacktest, type NotificationData, NotificationLive, type NotificationModel, type OrderCheckContract, type OrderCloseContract, type OrderOpenContract, type OrderSyncCloseNotification, type OrderSyncContract, type OrderSyncOpenNotification, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossAvailableNotification, type PartialLossCommit, type PartialLossCommitNotification, type PartialLossContract, type PartialProfitAvailableNotification, type PartialProfitCommit, type PartialProfitCommitNotification, type PartialProfitContract, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistBreakevenAdapter, PersistBreakevenInstance, PersistCandleAdapter, PersistCandleInstance, PersistIntervalAdapter, PersistIntervalInstance, PersistLogAdapter, PersistLogInstance, PersistMeasureAdapter, PersistMeasureInstance, PersistMemoryAdapter, PersistMemoryInstance, PersistNotificationAdapter, PersistNotificationInstance, PersistPartialAdapter, PersistPartialInstance, PersistRecentAdapter, PersistRecentInstance, PersistRiskAdapter, PersistRiskInstance, PersistScheduleAdapter, PersistScheduleInstance, PersistSessionAdapter, PersistSessionInstance, PersistSignalAdapter, PersistSignalInstance, PersistStateAdapter, PersistStateInstance, PersistStorageAdapter, PersistStorageInstance, PersistStrategyAdapter, PersistStrategyInstance, Position, PositionSize, type ProgressBacktestContract, type ProgressWalkerContract, Recent, RecentBacktest, type RecentData, RecentLive, Reflect, Report, ReportBase, type ReportName, ReportWriter, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, type RuntimeData, Schedule, type ScheduleData, type ScheduleEventContract, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, Session, SessionBacktest, type SessionData, SessionLive, type SignalCancelledNotification, type SignalClosedNotification, type SignalData, type SignalEventContract, type SignalInfoContract, type SignalInfoNotification, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, State, StateBacktest, StateBacktestAdapter, type StateData, StateLive, StateLiveAdapter, Storage, StorageBacktest, type StorageData, StorageLive, Strategy, type StrategyActionType, type StrategyCancelReason, type StrategyCloseReason, type StrategyCommitContract, type StrategyData, type StrategyEvent, type StrategyStatisticsModel, type StrategyStatus, Sync, type SyncEvent, type SyncStatisticsModel, System, type TBrokerCtor, type TDumpInstanceCtor, type TLogCtor, type TMarkdownBase, type TMemoryInstanceCtor, type TNotificationUtilsCtor, type TPersistBase, type TPersistBaseCtor, type TPersistBreakevenInstanceCtor, type TPersistCandleInstanceCtor, type TPersistIntervalInstanceCtor, type TPersistLogInstanceCtor, type TPersistMeasureInstanceCtor, type TPersistMemoryInstanceCtor, type TPersistNotificationInstanceCtor, type TPersistPartialInstanceCtor, type TPersistRecentInstanceCtor, type TPersistRiskInstanceCtor, type TPersistScheduleInstanceCtor, type TPersistSessionInstanceCtor, type TPersistSignalInstanceCtor, type TPersistStateInstanceCtor, type TPersistStorageInstanceCtor, type TPersistStrategyInstanceCtor, type TRecentUtilsCtor, type TReportBase, type TSessionInstanceCtor, type TStateInstanceCtor, type TStorageUtilsCtor, type TickEvent, type TrailingStopCommit, type TrailingStopCommitNotification, type TrailingTakeCommit, type TrailingTakeCommitNotification, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addActionSchema, addExchangeSchema, addFrameSchema, addRiskSchema, addSizingSchema, addStrategySchema, addWalkerSchema, alignToInterval, beginContext, beginTime, cacheCandles, checkCandles, commitActivateScheduled, commitAverageBuy, commitBreakeven, commitCancelScheduled, commitClosePending, commitCreateSignal, commitCreateStopLoss, commitCreateTakeProfit, commitPartialLoss, commitPartialLossCost, commitPartialProfit, commitPartialProfitCost, commitSignalNotify, commitTrailingStop, commitTrailingStopCost, commitTrailingTake, commitTrailingTakeCost, createSignalState, dumpAgentAnswer, dumpError, dumpJson, dumpRecord, dumpTable, dumpText, emitters, formatPrice, formatQuantity, get, getActionSchema, getAggregatedTrades, getAveragePrice, getBacktestTimeframe, getBreakeven, getCandles, getClosePrice, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getEffectivePriceOpen, getExchangeSchema, getFrameSchema, getLatestSignal, getMaxDrawdownDistancePnlCost, getMaxDrawdownDistancePnlPercentage, getMinutesSinceLatestSignalCreated, getMode, getNextCandles, getOrderBook, getPendingSignal, getPositionActiveMinutes, getPositionCountdownMinutes, getPositionDrawdownMinutes, getPositionEffectivePrice, getPositionEntries, getPositionEntryOverlap, getPositionEstimateMinutes, getPositionHighestMaxDrawdownPnlCost, getPositionHighestMaxDrawdownPnlPercentage, getPositionHighestPnlCost, getPositionHighestPnlPercentage, getPositionHighestProfitBreakeven, getPositionHighestProfitDistancePnlCost, getPositionHighestProfitDistancePnlPercentage, getPositionHighestProfitMinutes, getPositionHighestProfitPrice, getPositionHighestProfitTimestamp, getPositionInvestedCost, getPositionInvestedCount, getPositionLevels, getPositionMaxDrawdownMinutes, getPositionMaxDrawdownPnlCost, getPositionMaxDrawdownPnlPercentage, getPositionMaxDrawdownPrice, getPositionMaxDrawdownTimestamp, getPositionPartialOverlap, getPositionPartials, getPositionPnlCost, getPositionPnlPercent, getPositionWaitingMinutes, getPriceScale, getRawCandles, getRemainingCostBasis, getRiskSchema, getRuntimeInfo, getScheduledSignal, getSessionData, getSignalState, getSizingSchema, getStrategySchema, getStrategyStatus, getSymbol, getTimestamp, getTotalClosed, getTotalCostClosed, getTotalPercentClosed, getTotalPercentHeld, getWalkerSchema, hasNoPendingSignal, hasNoScheduledSignal, hasTradeContext, intervalStepMs, investedCostToPercent, backtest as lib, listExchangeSchema, listFrameSchema, listMemory, listRiskSchema, listSizingSchema, listStrategySchema, listWalkerSchema, listenActivePing, listenActivePingOnce, listenAfterEnd, listenAfterEndOnce, listenBacktestProgress, listenBeforeStart, listenBeforeStartOnce, listenBreakevenAvailable, listenBreakevenAvailableOnce, listenCheck, listenCheckOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenHighestProfit, listenHighestProfitOnce, listenIdlePing, listenIdlePingOnce, listenMaxDrawdown, listenMaxDrawdownOnce, listenPartialLossAvailable, listenPartialLossAvailableOnce, listenPartialProfitAvailable, listenPartialProfitAvailableOnce, listenPerformance, listenRisk, listenRiskOnce, listenScheduleEvent, listenScheduleEventOnce, listenSchedulePing, listenSchedulePingOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalEvent, listenSignalEventOnce, listenSignalLive, listenSignalLiveOnce, listenSignalNotify, listenSignalNotifyOnce, listenSignalOnce, listenStrategyCommit, listenStrategyCommitOnce, listenSync, listenSyncOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, percentDiff, percentToCloseCost, percentValue, readMemory, removeMemory, roundTicks, runInMockContext, searchMemory, set, setColumns, setConfig, setLogger, setSessionData, setSignalState, shutdown, slPercentShiftToPrice, slPriceToPercentShift, stopStrategy, toPlainString, toProfitLossDto, tpPercentShiftToPrice, tpPriceToPercentShift, validate, validateCandles, validateCommonSignal, validatePendingSignal, validateScheduledSignal, validateSignal, waitForCandle, waitForReady, warmCandles, writeMemory };
|