backtest-kit 13.6.0 → 14.1.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/README.md +524 -1723
- package/build/index.cjs +1640 -54
- package/build/index.mjs +1635 -55
- package/package.json +3 -3
- package/types.d.ts +1516 -40
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
|
*
|
|
@@ -1521,8 +1696,8 @@ type SignalSyncContract = SignalOpenContract | SignalCloseContract;
|
|
|
1521
1696
|
* Backtest never emits this event — there is no live exchange to query.
|
|
1522
1697
|
*
|
|
1523
1698
|
* Consumers:
|
|
1524
|
-
* - Broker adapter via `
|
|
1525
|
-
* - Registered actions via `
|
|
1699
|
+
* - Broker adapter via `onOrderCheck` (syncPendingSubject subscription)
|
|
1700
|
+
* - Registered actions via `orderCheck` / `onOrderCheck`
|
|
1526
1701
|
*/
|
|
1527
1702
|
interface SignalPingContract {
|
|
1528
1703
|
/** Discriminator for pending-ping action */
|
|
@@ -1834,6 +2009,96 @@ interface IActionCallbacks {
|
|
|
1834
2009
|
* @param backtest - True for backtest mode, false for live trading
|
|
1835
2010
|
*/
|
|
1836
2011
|
onPingScheduled(event: SchedulePingContract, actionName: ActionName, strategyName: StrategyName, frameName: FrameName, backtest: boolean): void | Promise<void>;
|
|
2012
|
+
/**
|
|
2013
|
+
* Called on scheduled signal lifecycle events (creation / cancellation).
|
|
2014
|
+
*
|
|
2015
|
+
* Triggered by: StrategyConnectionService via scheduleEventSubject
|
|
2016
|
+
* Frequency: Once on creation (action "scheduled") and once on cancellation before activation
|
|
2017
|
+
* (action "cancelled": timeout / price_reject / user). The scheduled -> active transition is
|
|
2018
|
+
* NOT reported here — activation surfaces as an "opened" signal instead.
|
|
2019
|
+
*
|
|
2020
|
+
* Manual wiring — EVENT-BASED (driving the exchange from an action registered via `addActionSchema`)
|
|
2021
|
+
*
|
|
2022
|
+
* An action is the alternative to a Broker adapter for binding the framework to a real exchange:
|
|
2023
|
+
* both run inside the strategy tick, so the commit-functions from `src/function/strategy.ts` are
|
|
2024
|
+
* callable here and take effect on the next tick. On `event.action === "scheduled"` place the real
|
|
2025
|
+
* resting/limit order (tag it with `event.data.id`) and, if it resolves at once, call
|
|
2026
|
+
* `commitActivateScheduled(event.symbol, { id })`; on a reject call
|
|
2027
|
+
* `commitCancelScheduled(event.symbol, { id })`. On `event.action === "cancelled"` (the strategy has
|
|
2028
|
+
* already dropped the scheduled signal) cancel the matching exchange order; `event.reason` says why.
|
|
2029
|
+
* For ongoing polling of the resting order use `onPingScheduled` (every tick).
|
|
2030
|
+
*
|
|
2031
|
+
* @param event - Scheduled lifecycle data (action discriminates created vs cancelled)
|
|
2032
|
+
* @param actionName - Action identifier
|
|
2033
|
+
* @param strategyName - Strategy identifier
|
|
2034
|
+
* @param frameName - Timeframe identifier
|
|
2035
|
+
* @param backtest - True for backtest mode, false for live trading
|
|
2036
|
+
*
|
|
2037
|
+
* @example
|
|
2038
|
+
* ```typescript
|
|
2039
|
+
* import { addActionSchema, commitActivateScheduled, commitCancelScheduled } from "backtest-kit";
|
|
2040
|
+
*
|
|
2041
|
+
* addActionSchema({
|
|
2042
|
+
* actionName: "exchange-bridge",
|
|
2043
|
+
* callbacks: {
|
|
2044
|
+
* async onScheduleEvent(event) {
|
|
2045
|
+
* if (event.action === "scheduled") {
|
|
2046
|
+
* const order = await exchange.placeLimit(event.symbol, event.data.priceOpen, event.data.id);
|
|
2047
|
+
* if (order.status === "filled") await commitActivateScheduled(event.symbol, { id: order.id });
|
|
2048
|
+
* } else {
|
|
2049
|
+
* await exchange.cancelOrderById(event.data.id);
|
|
2050
|
+
* }
|
|
2051
|
+
* },
|
|
2052
|
+
* },
|
|
2053
|
+
* });
|
|
2054
|
+
* ```
|
|
2055
|
+
*/
|
|
2056
|
+
onScheduleEvent(event: ScheduleEventContract, actionName: ActionName, strategyName: StrategyName, frameName: FrameName, backtest: boolean): void | Promise<void>;
|
|
2057
|
+
/**
|
|
2058
|
+
* Called on pending signal lifecycle events (open / close).
|
|
2059
|
+
*
|
|
2060
|
+
* Triggered by: StrategyConnectionService via signalEventSubject
|
|
2061
|
+
* Frequency: Once when a pending position is opened (action "opened": new signal / immediate /
|
|
2062
|
+
* scheduled or user activation) and once when it is closed (action "closed" with closeReason
|
|
2063
|
+
* take_profit / stop_loss / time_expired / closed).
|
|
2064
|
+
*
|
|
2065
|
+
* Manual wiring — EVENT-BASED (driving the exchange from an action registered via `addActionSchema`)
|
|
2066
|
+
*
|
|
2067
|
+
* Alternative to a Broker adapter — the commit-functions from `src/function/strategy.ts` are
|
|
2068
|
+
* callable here (same tick context) and apply on the next tick. On `event.action === "opened"`
|
|
2069
|
+
* place the real entry + protective TP/SL orders; on `event.action === "closed"` (the strategy has
|
|
2070
|
+
* already removed the signal) flatten the real position and cancel leftover orders.
|
|
2071
|
+
*
|
|
2072
|
+
* Note: `onPendingEvent` fires only at open/close — it is NOT a per-tick monitor. To translate
|
|
2073
|
+
* intra-position exchange fills into `commitCreateTakeProfit` / `commitCreateStopLoss` /
|
|
2074
|
+
* `commitClosePending` on every tick, use `onPingActive` (fires each tick while the position is open).
|
|
2075
|
+
*
|
|
2076
|
+
* @param event - Pending lifecycle data (action discriminates opened vs closed)
|
|
2077
|
+
* @param actionName - Action identifier
|
|
2078
|
+
* @param strategyName - Strategy identifier
|
|
2079
|
+
* @param frameName - Timeframe identifier
|
|
2080
|
+
* @param backtest - True for backtest mode, false for live trading
|
|
2081
|
+
*
|
|
2082
|
+
* @example
|
|
2083
|
+
* ```typescript
|
|
2084
|
+
* import { addActionSchema, commitClosePending } from "backtest-kit";
|
|
2085
|
+
*
|
|
2086
|
+
* addActionSchema({
|
|
2087
|
+
* actionName: "exchange-bridge",
|
|
2088
|
+
* callbacks: {
|
|
2089
|
+
* async onPendingEvent(event) {
|
|
2090
|
+
* if (event.action === "opened") await exchange.openWithProtection(event.symbol, event.data);
|
|
2091
|
+
* else await exchange.flatten(event.symbol, event.data.id);
|
|
2092
|
+
* },
|
|
2093
|
+
* async onPingActive(event) { // per-tick fills -> close
|
|
2094
|
+
* const order = await exchange.getOrderById(event.data.id);
|
|
2095
|
+
* if (order?.status === "no_counterparty") await commitClosePending(event.symbol, { id: order.id });
|
|
2096
|
+
* },
|
|
2097
|
+
* },
|
|
2098
|
+
* });
|
|
2099
|
+
* ```
|
|
2100
|
+
*/
|
|
2101
|
+
onPendingEvent(event: SignalEventContract, actionName: ActionName, strategyName: StrategyName, frameName: FrameName, backtest: boolean): void | Promise<void>;
|
|
1837
2102
|
/**
|
|
1838
2103
|
* Called during active pending signal monitoring (every minute while position is active).
|
|
1839
2104
|
*
|
|
@@ -1881,6 +2146,13 @@ interface IActionCallbacks {
|
|
|
1881
2146
|
* They propagate up to CREATE_SYNC_FN which catches them and returns false.
|
|
1882
2147
|
* Throw to reject the operation — framework will retry on next tick.
|
|
1883
2148
|
*
|
|
2149
|
+
* MANUAL WIRING — EXCEPTION-BASED GATE: the action-side equivalent of the Broker
|
|
2150
|
+
* `onSignalOpenCommit` / `onSignalCloseCommit` gate. Throwing (or returning false) on
|
|
2151
|
+
* `event.action === "signal-open"` rolls the open back to idle (a scheduled activation is
|
|
2152
|
+
* cancelled); on `"signal-close"` it skips the close and leaves the position open — retried next
|
|
2153
|
+
* tick. Rides the same `syncSubject` emission as the Broker commit hooks, so a throw from either is
|
|
2154
|
+
* collapsed to false by `CREATE_SYNC_FN`. Backtest short-circuits the gate to true (live-only).
|
|
2155
|
+
*
|
|
1884
2156
|
* @param event - Sync event with action "signal-open" or "signal-close"
|
|
1885
2157
|
* @param actionName - Action identifier
|
|
1886
2158
|
* @param strategyName - Strategy identifier
|
|
@@ -1903,15 +2175,21 @@ interface IActionCallbacks {
|
|
|
1903
2175
|
* NOTE: Like onSignalSync, exceptions from this method are NOT swallowed. They propagate up to
|
|
1904
2176
|
* CREATE_SYNC_PENDING_FN which catches them and returns false.
|
|
1905
2177
|
*
|
|
2178
|
+
* MANUAL WIRING — EXCEPTION-BASED GATE: the action-side equivalent of the Broker `onOrderCheck`.
|
|
2179
|
+
* A THROW on a confirmed "order not found by id" closes the position with closeReason "closed"
|
|
2180
|
+
* (retried via CREATE_SYNC_PENDING_FN). This is the throw-driven alternative to the imperative
|
|
2181
|
+
* `commitClosePending` (call it from `pingActive` instead) — pick one, not both, for the same
|
|
2182
|
+
* "order gone" condition. Backtest short-circuits the gate (live-only).
|
|
2183
|
+
*
|
|
1906
2184
|
* @deprecated This callback is not recommended for use. Exchange integration should be implemented
|
|
1907
|
-
* in Broker.useBrokerAdapter (the infrastructure domain layer) via
|
|
2185
|
+
* in Broker.useBrokerAdapter (the infrastructure domain layer) via onOrderCheck instead.
|
|
1908
2186
|
* @param event - Pending-ping event with action "signal-ping"
|
|
1909
2187
|
* @param actionName - Action identifier
|
|
1910
2188
|
* @param strategyName - Strategy identifier
|
|
1911
2189
|
* @param frameName - Timeframe identifier
|
|
1912
2190
|
* @param backtest - True for backtest mode, false for live trading
|
|
1913
2191
|
*/
|
|
1914
|
-
|
|
2192
|
+
onOrderCheck(event: SignalPingContract, actionName: ActionName, strategyName: StrategyName, frameName: FrameName, backtest: boolean): void | Promise<void>;
|
|
1915
2193
|
}
|
|
1916
2194
|
/**
|
|
1917
2195
|
* Action schema registered via addActionSchema().
|
|
@@ -2142,6 +2420,35 @@ interface IAction {
|
|
|
2142
2420
|
* @param event - Scheduled signal monitoring data
|
|
2143
2421
|
*/
|
|
2144
2422
|
pingScheduled(event: SchedulePingContract): void | Promise<void>;
|
|
2423
|
+
/**
|
|
2424
|
+
* Handles scheduled signal lifecycle events (creation / cancellation).
|
|
2425
|
+
*
|
|
2426
|
+
* Emitted by: StrategyConnectionService via scheduleEventSubject
|
|
2427
|
+
* Source: CREATE_COMMIT_SCHEDULE_EVENT_FN callback in StrategyConnectionService
|
|
2428
|
+
* Frequency: Once when a scheduled signal is created ("scheduled") and once when it is
|
|
2429
|
+
* cancelled before activation ("cancelled": timeout / price_reject / user). The
|
|
2430
|
+
* scheduled -> active transition is NOT reported here.
|
|
2431
|
+
*
|
|
2432
|
+
* Manual wiring — EVENT-BASED: implement the user-facing callback {@link IActionCallbacks.onScheduleEvent} (via
|
|
2433
|
+
* `addActionSchema`) to drive the exchange (`commitActivateScheduled` / `commitCancelScheduled`).
|
|
2434
|
+
*
|
|
2435
|
+
* @param event - Scheduled lifecycle data (action discriminates created vs cancelled)
|
|
2436
|
+
*/
|
|
2437
|
+
scheduleEvent(event: ScheduleEventContract): void | Promise<void>;
|
|
2438
|
+
/**
|
|
2439
|
+
* Handles pending signal lifecycle events (open / close).
|
|
2440
|
+
*
|
|
2441
|
+
* Emitted by: StrategyConnectionService via signalEventSubject
|
|
2442
|
+
* Source: CREATE_COMMIT_SIGNAL_EVENT_FN callback in StrategyConnectionService
|
|
2443
|
+
* Frequency: Once when a pending position is opened (action "opened") and once when it is
|
|
2444
|
+
* closed (action "closed" with closeReason take_profit / stop_loss / time_expired / closed).
|
|
2445
|
+
*
|
|
2446
|
+
* Manual wiring — EVENT-BASED: implement the user-facing callback {@link IActionCallbacks.onPendingEvent} (via
|
|
2447
|
+
* `addActionSchema`) to drive the exchange; for per-tick fills use `onPingActive`.
|
|
2448
|
+
*
|
|
2449
|
+
* @param event - Pending lifecycle data (action discriminates opened vs closed)
|
|
2450
|
+
*/
|
|
2451
|
+
pendingEvent(event: SignalEventContract): void | Promise<void>;
|
|
2145
2452
|
/**
|
|
2146
2453
|
* Handles active ping events during active pending signal monitoring.
|
|
2147
2454
|
*
|
|
@@ -2178,6 +2485,12 @@ interface IAction {
|
|
|
2178
2485
|
*
|
|
2179
2486
|
* NOTE: Exceptions are NOT swallowed here — they propagate to CREATE_SYNC_FN.
|
|
2180
2487
|
*
|
|
2488
|
+
* MANUAL WIRING — EXCEPTION-BASED GATE: action-side equivalent of the Broker
|
|
2489
|
+
* `onSignalOpenCommit` / `onSignalCloseCommit`. Throw on "signal-open" → open rolls back to idle
|
|
2490
|
+
* (scheduled activation cancelled); throw on "signal-close" → close skipped, position stays open;
|
|
2491
|
+
* retried next tick. Same `syncSubject` emission as the Broker commit hooks (collapsed to false by
|
|
2492
|
+
* CREATE_SYNC_FN). Live-only. Implement via the {@link IActionCallbacks.onSignalSync} callback.
|
|
2493
|
+
*
|
|
2181
2494
|
* @deprecated This method is not recommended for use. Implement custom logic in signal(), signalLive(), or signalBacktest() instead.
|
|
2182
2495
|
* If you need to implement custom logic on signal open/close, please use signal(), signalBacktest(), signalLive() instead.
|
|
2183
2496
|
* If Action::signalSync throws the exchange will not execute the order!
|
|
@@ -2198,12 +2511,18 @@ interface IAction {
|
|
|
2198
2511
|
*
|
|
2199
2512
|
* NOTE: Exceptions are NOT swallowed here — they propagate to CREATE_SYNC_PENDING_FN.
|
|
2200
2513
|
*
|
|
2514
|
+
* MANUAL WIRING — EXCEPTION-BASED GATE: action-side equivalent of the Broker `onOrderCheck`. A
|
|
2515
|
+
* throw on a confirmed "order not found by id" closes the position with closeReason "closed"
|
|
2516
|
+
* (retried via CREATE_SYNC_PENDING_FN). Throw-driven alternative to the imperative
|
|
2517
|
+
* `commitClosePending` (call it from `pingActive`) — pick one, not both. Live-only. Implement via
|
|
2518
|
+
* the {@link IActionCallbacks.onOrderCheck} callback.
|
|
2519
|
+
*
|
|
2201
2520
|
* @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::
|
|
2521
|
+
* in Broker.useBrokerAdapter (the infrastructure domain layer) via onOrderCheck instead.
|
|
2522
|
+
* If Action::orderCheck throws the framework will close the position with closeReason "closed"!
|
|
2204
2523
|
* @param event - Pending-ping event with action "signal-ping"
|
|
2205
2524
|
*/
|
|
2206
|
-
|
|
2525
|
+
orderCheck(event: SignalPingContract): void | Promise<void>;
|
|
2207
2526
|
/**
|
|
2208
2527
|
* Cleans up resources and subscriptions when action handler is no longer needed.
|
|
2209
2528
|
*
|
|
@@ -2564,6 +2883,20 @@ type StrategyStatus = {
|
|
|
2564
2883
|
cancelledSignal: IScheduledSignalCancelRow | null;
|
|
2565
2884
|
/** Deferred user-initiated scheduled activate (activateScheduled), or null if none pending */
|
|
2566
2885
|
activatedSignal: IScheduledSignalActivateRow | null;
|
|
2886
|
+
/**
|
|
2887
|
+
* Deferred broker-confirmed take-profit fill (createTakeProfit), or null if none pending.
|
|
2888
|
+
* Set when the external order management system reports the position's TP order was actually
|
|
2889
|
+
* filled on the exchange (e.g. by candle high/low) — independent of the VWAP-based TP check.
|
|
2890
|
+
* Drained on the next tick/backtest to close the position with closeReason "take_profit".
|
|
2891
|
+
*/
|
|
2892
|
+
takeProfitSignal: ISignalCloseRow | null;
|
|
2893
|
+
/**
|
|
2894
|
+
* Deferred broker-confirmed stop-loss fill (createStopLoss), or null if none pending.
|
|
2895
|
+
* Set when the external order management system reports the position's SL order was actually
|
|
2896
|
+
* filled on the exchange (e.g. by candle high/low) — independent of the VWAP-based SL check.
|
|
2897
|
+
* Drained on the next tick/backtest to close the position with closeReason "stop_loss".
|
|
2898
|
+
*/
|
|
2899
|
+
stopLossSignal: ISignalCloseRow | null;
|
|
2567
2900
|
};
|
|
2568
2901
|
/**
|
|
2569
2902
|
* Commit payload for strategy commits.
|
|
@@ -3584,6 +3917,44 @@ interface IStrategy {
|
|
|
3584
3917
|
* @returns Promise that resolves when the DTO is queued
|
|
3585
3918
|
*/
|
|
3586
3919
|
createSignal: (symbol: string, currentPrice: number, dto: ISignalDto) => Promise<void>;
|
|
3920
|
+
/**
|
|
3921
|
+
* Reports that the pending position's take-profit order was actually filled on the exchange
|
|
3922
|
+
* (e.g. by candle high/low), forcing a close that does not wait for the VWAP-based TP check.
|
|
3923
|
+
*
|
|
3924
|
+
* The exchange and the strategy are parallel states: ClientStrategy evaluates TP/SL against
|
|
3925
|
+
* VWAP, but the real order may close on high/low. This method bridges that gap — the broker
|
|
3926
|
+
* confirms the fill out of the async-hooks execution context, and the close is deferred:
|
|
3927
|
+
* a snapshot of the current pending signal is stored and drained on the next tick/backtest,
|
|
3928
|
+
* which closes the position with closeReason "take_profit" at the effective take-profit level.
|
|
3929
|
+
*
|
|
3930
|
+
* No-op if no pending signal exists. Persisted (live mode only) so a crash before the next
|
|
3931
|
+
* tick does not lose the deferred close.
|
|
3932
|
+
*
|
|
3933
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
3934
|
+
* @param backtest - Whether running in backtest mode
|
|
3935
|
+
* @param payload - Optional commit id/note attached to the close
|
|
3936
|
+
* @returns Promise that resolves when the take-profit fill is queued
|
|
3937
|
+
*/
|
|
3938
|
+
createTakeProfit: (symbol: string, backtest: boolean, payload: Partial<CommitPayload>) => Promise<void>;
|
|
3939
|
+
/**
|
|
3940
|
+
* Reports that the pending position's stop-loss order was actually filled on the exchange
|
|
3941
|
+
* (e.g. by candle high/low), forcing a close that does not wait for the VWAP-based SL check.
|
|
3942
|
+
*
|
|
3943
|
+
* The exchange and the strategy are parallel states: ClientStrategy evaluates TP/SL against
|
|
3944
|
+
* VWAP, but the real order may close on high/low. This method bridges that gap — the broker
|
|
3945
|
+
* confirms the fill out of the async-hooks execution context, and the close is deferred:
|
|
3946
|
+
* a snapshot of the current pending signal is stored and drained on the next tick/backtest,
|
|
3947
|
+
* which closes the position with closeReason "stop_loss" at the effective stop-loss level.
|
|
3948
|
+
*
|
|
3949
|
+
* No-op if no pending signal exists. Persisted (live mode only) so a crash before the next
|
|
3950
|
+
* tick does not lose the deferred close.
|
|
3951
|
+
*
|
|
3952
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
3953
|
+
* @param backtest - Whether running in backtest mode
|
|
3954
|
+
* @param payload - Optional commit id/note attached to the close
|
|
3955
|
+
* @returns Promise that resolves when the stop-loss fill is queued
|
|
3956
|
+
*/
|
|
3957
|
+
createStopLoss: (symbol: string, backtest: boolean, payload: Partial<CommitPayload>) => Promise<void>;
|
|
3587
3958
|
/**
|
|
3588
3959
|
* Returns the deferred strategy-state snapshot held in memory for this iteration — exactly
|
|
3589
3960
|
* what would be written to persist (queued createSignal, commit queue, deferred user-action
|
|
@@ -6635,6 +7006,52 @@ declare function commitSignalNotify(symbol: string, payload?: Partial<SignalNoti
|
|
|
6635
7006
|
* ```
|
|
6636
7007
|
*/
|
|
6637
7008
|
declare function commitCreateSignal(symbol: string, dto: ISignalDto): Promise<void>;
|
|
7009
|
+
/**
|
|
7010
|
+
* Reports that the pending position's take-profit order was actually filled on the exchange
|
|
7011
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based TP check.
|
|
7012
|
+
*
|
|
7013
|
+
* The exchange and the strategy are parallel states: the framework evaluates TP/SL against VWAP,
|
|
7014
|
+
* but the real order may fill on high/low. The close is deferred and emitted with closeReason
|
|
7015
|
+
* "take_profit" on the next tick. No-op if no pending signal exists.
|
|
7016
|
+
*
|
|
7017
|
+
* Automatically detects backtest/live mode from execution context.
|
|
7018
|
+
*
|
|
7019
|
+
* @param symbol - Trading pair symbol
|
|
7020
|
+
* @param payload - Optional commit payload with id and note
|
|
7021
|
+
* @returns Promise that resolves when the take-profit fill is queued
|
|
7022
|
+
*
|
|
7023
|
+
* @example
|
|
7024
|
+
* ```typescript
|
|
7025
|
+
* import { commitCreateTakeProfit } from "backtest-kit";
|
|
7026
|
+
*
|
|
7027
|
+
* // Report TP fill confirmed on the exchange
|
|
7028
|
+
* await commitCreateTakeProfit("BTCUSDT", { id: "tp-fill-001" });
|
|
7029
|
+
* ```
|
|
7030
|
+
*/
|
|
7031
|
+
declare function commitCreateTakeProfit(symbol: string, payload?: Partial<CommitPayload>): Promise<void>;
|
|
7032
|
+
/**
|
|
7033
|
+
* Reports that the pending position's stop-loss order was actually filled on the exchange
|
|
7034
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based SL check.
|
|
7035
|
+
*
|
|
7036
|
+
* The exchange and the strategy are parallel states: the framework evaluates TP/SL against VWAP,
|
|
7037
|
+
* but the real order may fill on high/low. The close is deferred and emitted with closeReason
|
|
7038
|
+
* "stop_loss" on the next tick. No-op if no pending signal exists.
|
|
7039
|
+
*
|
|
7040
|
+
* Automatically detects backtest/live mode from execution context.
|
|
7041
|
+
*
|
|
7042
|
+
* @param symbol - Trading pair symbol
|
|
7043
|
+
* @param payload - Optional commit payload with id and note
|
|
7044
|
+
* @returns Promise that resolves when the stop-loss fill is queued
|
|
7045
|
+
*
|
|
7046
|
+
* @example
|
|
7047
|
+
* ```typescript
|
|
7048
|
+
* import { commitCreateStopLoss } from "backtest-kit";
|
|
7049
|
+
*
|
|
7050
|
+
* // Report SL fill confirmed on the exchange
|
|
7051
|
+
* await commitCreateStopLoss("BTCUSDT", { id: "sl-fill-001" });
|
|
7052
|
+
* ```
|
|
7053
|
+
*/
|
|
7054
|
+
declare function commitCreateStopLoss(symbol: string, payload?: Partial<CommitPayload>): Promise<void>;
|
|
6638
7055
|
/**
|
|
6639
7056
|
* Returns the in-memory deferred strategy-state snapshot for the current iteration: the queued
|
|
6640
7057
|
* createSignal, commit queue and deferred user-action flags, plus the current pending signal id.
|
|
@@ -9524,6 +9941,111 @@ declare function listenSchedulePing(fn: (event: SchedulePingContract) => void):
|
|
|
9524
9941
|
* ```
|
|
9525
9942
|
*/
|
|
9526
9943
|
declare function listenSchedulePingOnce(filterFn: (event: SchedulePingContract) => boolean, fn: (event: SchedulePingContract) => void): () => void;
|
|
9944
|
+
/**
|
|
9945
|
+
* Subscribes to scheduled signal lifecycle events (creation and cancellation) with queued async processing.
|
|
9946
|
+
*
|
|
9947
|
+
* Emitted when a scheduled signal is created (action "scheduled") or cancelled before activation
|
|
9948
|
+
* (action "cancelled" with reason "timeout" / "price_reject" / "user"), in both live and backtest.
|
|
9949
|
+
*
|
|
9950
|
+
* IMPORTANT: The scheduled -> active transition (activation) is NOT reported here. Activation
|
|
9951
|
+
* produces an "opened" event on the regular signal emitters (listenSignal) instead.
|
|
9952
|
+
*
|
|
9953
|
+
* Events are processed sequentially in order received, even if callback is async.
|
|
9954
|
+
*
|
|
9955
|
+
* @param fn - Callback function to handle scheduled lifecycle events
|
|
9956
|
+
* @returns Unsubscribe function to stop listening
|
|
9957
|
+
*
|
|
9958
|
+
* @example
|
|
9959
|
+
* ```typescript
|
|
9960
|
+
* import { listenScheduleEvent } from "./function/event";
|
|
9961
|
+
*
|
|
9962
|
+
* const unsubscribe = listenScheduleEvent((event) => {
|
|
9963
|
+
* if (event.action === "scheduled") {
|
|
9964
|
+
* console.log(`Scheduled ${event.symbol} @ ${event.data.priceOpen}`);
|
|
9965
|
+
* } else {
|
|
9966
|
+
* console.log(`Cancelled ${event.symbol} (reason: ${event.reason})`);
|
|
9967
|
+
* }
|
|
9968
|
+
* });
|
|
9969
|
+
*
|
|
9970
|
+
* // Later: stop listening
|
|
9971
|
+
* unsubscribe();
|
|
9972
|
+
* ```
|
|
9973
|
+
*/
|
|
9974
|
+
declare function listenScheduleEvent(fn: (event: ScheduleEventContract) => void): () => void;
|
|
9975
|
+
/**
|
|
9976
|
+
* Subscribes to filtered scheduled lifecycle events with one-time execution.
|
|
9977
|
+
*
|
|
9978
|
+
* Listens for events matching the filter predicate, then executes callback once
|
|
9979
|
+
* and automatically unsubscribes. Useful for waiting for a specific scheduled creation
|
|
9980
|
+
* or cancellation.
|
|
9981
|
+
*
|
|
9982
|
+
* @param filterFn - Predicate to filter which events trigger the callback
|
|
9983
|
+
* @param fn - Callback function to handle the filtered event (called only once)
|
|
9984
|
+
* @returns Unsubscribe function to cancel the listener before it fires
|
|
9985
|
+
*
|
|
9986
|
+
* @example
|
|
9987
|
+
* ```typescript
|
|
9988
|
+
* import { listenScheduleEventOnce } from "./function/event";
|
|
9989
|
+
*
|
|
9990
|
+
* // Wait for the first cancellation on BTCUSDT
|
|
9991
|
+
* listenScheduleEventOnce(
|
|
9992
|
+
* (event) => event.symbol === "BTCUSDT" && event.action === "cancelled",
|
|
9993
|
+
* (event) => console.log("BTCUSDT scheduled cancelled:", event.reason)
|
|
9994
|
+
* );
|
|
9995
|
+
* ```
|
|
9996
|
+
*/
|
|
9997
|
+
declare function listenScheduleEventOnce(filterFn: (event: ScheduleEventContract) => boolean, fn: (event: ScheduleEventContract) => void): () => void;
|
|
9998
|
+
/**
|
|
9999
|
+
* Subscribes to pending signal lifecycle events (open and close) with queued async processing.
|
|
10000
|
+
*
|
|
10001
|
+
* Emitted when a pending position is opened (action "opened": new signal / immediate / scheduled
|
|
10002
|
+
* or user activation) or closed (action "closed" with closeReason "take_profit" / "stop_loss" /
|
|
10003
|
+
* "time_expired" / "closed"), in both live and backtest.
|
|
10004
|
+
*
|
|
10005
|
+
* Events are processed sequentially in order received, even if callback is async.
|
|
10006
|
+
*
|
|
10007
|
+
* @param fn - Callback function to handle pending lifecycle events
|
|
10008
|
+
* @returns Unsubscribe function to stop listening
|
|
10009
|
+
*
|
|
10010
|
+
* @example
|
|
10011
|
+
* ```typescript
|
|
10012
|
+
* import { listenSignalEvent } from "./function/event";
|
|
10013
|
+
*
|
|
10014
|
+
* const unsubscribe = listenSignalEvent((event) => {
|
|
10015
|
+
* if (event.action === "opened") {
|
|
10016
|
+
* console.log(`Opened ${event.symbol} @ ${event.data.priceOpen}`);
|
|
10017
|
+
* } else {
|
|
10018
|
+
* console.log(`Closed ${event.symbol} (reason: ${event.closeReason})`);
|
|
10019
|
+
* }
|
|
10020
|
+
* });
|
|
10021
|
+
*
|
|
10022
|
+
* // Later: stop listening
|
|
10023
|
+
* unsubscribe();
|
|
10024
|
+
* ```
|
|
10025
|
+
*/
|
|
10026
|
+
declare function listenSignalEvent(fn: (event: SignalEventContract) => void): () => void;
|
|
10027
|
+
/**
|
|
10028
|
+
* Subscribes to filtered pending lifecycle events with one-time execution.
|
|
10029
|
+
*
|
|
10030
|
+
* Listens for events matching the filter predicate, then executes callback once
|
|
10031
|
+
* and automatically unsubscribes. Useful for waiting for a specific open or close.
|
|
10032
|
+
*
|
|
10033
|
+
* @param filterFn - Predicate to filter which events trigger the callback
|
|
10034
|
+
* @param fn - Callback function to handle the filtered event (called only once)
|
|
10035
|
+
* @returns Unsubscribe function to cancel the listener before it fires
|
|
10036
|
+
*
|
|
10037
|
+
* @example
|
|
10038
|
+
* ```typescript
|
|
10039
|
+
* import { listenSignalEventOnce } from "./function/event";
|
|
10040
|
+
*
|
|
10041
|
+
* // Wait for the first close on BTCUSDT
|
|
10042
|
+
* listenSignalEventOnce(
|
|
10043
|
+
* (event) => event.symbol === "BTCUSDT" && event.action === "closed",
|
|
10044
|
+
* (event) => console.log("BTCUSDT closed:", event.closeReason)
|
|
10045
|
+
* );
|
|
10046
|
+
* ```
|
|
10047
|
+
*/
|
|
10048
|
+
declare function listenSignalEventOnce(filterFn: (event: SignalEventContract) => boolean, fn: (event: SignalEventContract) => void): () => void;
|
|
9527
10049
|
/**
|
|
9528
10050
|
* Subscribes to active ping events with queued async processing.
|
|
9529
10051
|
*
|
|
@@ -14350,6 +14872,18 @@ type StrategyData = {
|
|
|
14350
14872
|
cancelledSignal: IScheduledSignalCancelRow | null;
|
|
14351
14873
|
/** Deferred user-initiated scheduled activate (activateScheduled), or null if none pending */
|
|
14352
14874
|
activatedSignal: IScheduledSignalActivateRow | null;
|
|
14875
|
+
/**
|
|
14876
|
+
* Deferred broker-confirmed take-profit fill (createTakeProfit), or null if none pending.
|
|
14877
|
+
* Set when the exchange reports the TP order was actually filled (e.g. by candle high/low),
|
|
14878
|
+
* independent of the VWAP-based TP check. Drained on the next tick to close with "take_profit".
|
|
14879
|
+
*/
|
|
14880
|
+
takeProfitSignal: ISignalCloseRow | null;
|
|
14881
|
+
/**
|
|
14882
|
+
* Deferred broker-confirmed stop-loss fill (createStopLoss), or null if none pending.
|
|
14883
|
+
* Set when the exchange reports the SL order was actually filled (e.g. by candle high/low),
|
|
14884
|
+
* independent of the VWAP-based SL check. Drained on the next tick to close with "stop_loss".
|
|
14885
|
+
*/
|
|
14886
|
+
stopLossSignal: ISignalCloseRow | null;
|
|
14353
14887
|
};
|
|
14354
14888
|
/**
|
|
14355
14889
|
* Per-context deferred strategy state persistence instance interface.
|
|
@@ -18979,6 +19513,62 @@ declare class BacktestUtils {
|
|
|
18979
19513
|
exchangeName: ExchangeName;
|
|
18980
19514
|
frameName: FrameName;
|
|
18981
19515
|
}, dto: ISignalDto) => Promise<void>;
|
|
19516
|
+
/**
|
|
19517
|
+
* Reports that the pending position's take-profit order was actually filled on the exchange
|
|
19518
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based TP check.
|
|
19519
|
+
*
|
|
19520
|
+
* The exchange and the strategy are parallel states: the framework evaluates TP/SL against VWAP,
|
|
19521
|
+
* but the real order may fill on high/low. The close is deferred and emitted with closeReason
|
|
19522
|
+
* "take_profit" on the next backtest tick. No-op if no pending signal exists.
|
|
19523
|
+
*
|
|
19524
|
+
* @param symbol - Trading pair symbol
|
|
19525
|
+
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
19526
|
+
* @param payload - Optional commit payload with id and note
|
|
19527
|
+
* @returns Promise that resolves when the take-profit fill is queued
|
|
19528
|
+
*
|
|
19529
|
+
* @example
|
|
19530
|
+
* ```typescript
|
|
19531
|
+
* // Report TP fill confirmed on the exchange
|
|
19532
|
+
* await Backtest.commitCreateTakeProfit("BTCUSDT", {
|
|
19533
|
+
* exchangeName: "binance",
|
|
19534
|
+
* strategyName: "my-strategy",
|
|
19535
|
+
* frameName: "1m"
|
|
19536
|
+
* }, { id: "tp-fill-001" });
|
|
19537
|
+
* ```
|
|
19538
|
+
*/
|
|
19539
|
+
commitCreateTakeProfit: (symbol: string, context: {
|
|
19540
|
+
strategyName: StrategyName;
|
|
19541
|
+
exchangeName: ExchangeName;
|
|
19542
|
+
frameName: FrameName;
|
|
19543
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
19544
|
+
/**
|
|
19545
|
+
* Reports that the pending position's stop-loss order was actually filled on the exchange
|
|
19546
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based SL check.
|
|
19547
|
+
*
|
|
19548
|
+
* The exchange and the strategy are parallel states: the framework evaluates TP/SL against VWAP,
|
|
19549
|
+
* but the real order may fill on high/low. The close is deferred and emitted with closeReason
|
|
19550
|
+
* "stop_loss" on the next backtest tick. No-op if no pending signal exists.
|
|
19551
|
+
*
|
|
19552
|
+
* @param symbol - Trading pair symbol
|
|
19553
|
+
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
19554
|
+
* @param payload - Optional commit payload with id and note
|
|
19555
|
+
* @returns Promise that resolves when the stop-loss fill is queued
|
|
19556
|
+
*
|
|
19557
|
+
* @example
|
|
19558
|
+
* ```typescript
|
|
19559
|
+
* // Report SL fill confirmed on the exchange
|
|
19560
|
+
* await Backtest.commitCreateStopLoss("BTCUSDT", {
|
|
19561
|
+
* exchangeName: "binance",
|
|
19562
|
+
* strategyName: "my-strategy",
|
|
19563
|
+
* frameName: "1m"
|
|
19564
|
+
* }, { id: "sl-fill-001" });
|
|
19565
|
+
* ```
|
|
19566
|
+
*/
|
|
19567
|
+
commitCreateStopLoss: (symbol: string, context: {
|
|
19568
|
+
strategyName: StrategyName;
|
|
19569
|
+
exchangeName: ExchangeName;
|
|
19570
|
+
frameName: FrameName;
|
|
19571
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
18982
19572
|
/**
|
|
18983
19573
|
* Returns the in-memory deferred strategy-state snapshot for the current backtest iteration.
|
|
18984
19574
|
*
|
|
@@ -20489,6 +21079,40 @@ declare class LiveUtils {
|
|
|
20489
21079
|
strategyName: StrategyName;
|
|
20490
21080
|
exchangeName: ExchangeName;
|
|
20491
21081
|
}, dto: ISignalDto) => Promise<void>;
|
|
21082
|
+
/**
|
|
21083
|
+
* Reports that the pending position's take-profit order was actually filled on the exchange
|
|
21084
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based TP check.
|
|
21085
|
+
*
|
|
21086
|
+
* The exchange and the strategy are parallel states: the framework evaluates TP/SL against VWAP,
|
|
21087
|
+
* but the real order may fill on high/low. The close is deferred and emitted with closeReason
|
|
21088
|
+
* "take_profit" on the next live tick. No-op if no pending signal exists.
|
|
21089
|
+
*
|
|
21090
|
+
* @param symbol - Trading pair symbol
|
|
21091
|
+
* @param context - Execution context with strategyName and exchangeName
|
|
21092
|
+
* @param payload - Optional commit payload with id and note
|
|
21093
|
+
* @returns Promise that resolves when the take-profit fill is queued
|
|
21094
|
+
*/
|
|
21095
|
+
commitCreateTakeProfit: (symbol: string, context: {
|
|
21096
|
+
strategyName: StrategyName;
|
|
21097
|
+
exchangeName: ExchangeName;
|
|
21098
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
21099
|
+
/**
|
|
21100
|
+
* Reports that the pending position's stop-loss order was actually filled on the exchange
|
|
21101
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based SL check.
|
|
21102
|
+
*
|
|
21103
|
+
* The exchange and the strategy are parallel states: the framework evaluates TP/SL against VWAP,
|
|
21104
|
+
* but the real order may fill on high/low. The close is deferred and emitted with closeReason
|
|
21105
|
+
* "stop_loss" on the next live tick. No-op if no pending signal exists.
|
|
21106
|
+
*
|
|
21107
|
+
* @param symbol - Trading pair symbol
|
|
21108
|
+
* @param context - Execution context with strategyName and exchangeName
|
|
21109
|
+
* @param payload - Optional commit payload with id and note
|
|
21110
|
+
* @returns Promise that resolves when the stop-loss fill is queued
|
|
21111
|
+
*/
|
|
21112
|
+
commitCreateStopLoss: (symbol: string, context: {
|
|
21113
|
+
strategyName: StrategyName;
|
|
21114
|
+
exchangeName: ExchangeName;
|
|
21115
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
20492
21116
|
/**
|
|
20493
21117
|
* Returns the in-memory deferred strategy-state snapshot for the current live iteration.
|
|
20494
21118
|
*
|
|
@@ -28795,7 +29419,7 @@ type BrokerSignalClosePayload = {
|
|
|
28795
29419
|
*
|
|
28796
29420
|
* Emitted automatically via syncPendingSubject on every live tick while a pending signal is
|
|
28797
29421
|
* monitored, BEFORE the framework evaluates TP/SL/time. Forwarded to the registered IBroker
|
|
28798
|
-
* adapter via `
|
|
29422
|
+
* adapter via `onOrderCheck`.
|
|
28799
29423
|
*
|
|
28800
29424
|
* The adapter should query the exchange by `signalId` and THROW ONLY when the order is
|
|
28801
29425
|
* definitively NOT FOUND by that id (filled, cancelled, or liquidated externally). A throw
|
|
@@ -28854,6 +29478,316 @@ type BrokerSignalPendingPayload = {
|
|
|
28854
29478
|
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
28855
29479
|
backtest: boolean;
|
|
28856
29480
|
};
|
|
29481
|
+
/**
|
|
29482
|
+
* Payload for the active-ping broker event.
|
|
29483
|
+
*
|
|
29484
|
+
* Emitted automatically via activePingSubject on every live tick while a pending (open) signal is
|
|
29485
|
+
* monitored. Forwarded to the registered IBroker adapter via `onSignalActivePing`. Purely
|
|
29486
|
+
* informational — unlike `onOrderCheck` a throw here does NOT close the position.
|
|
29487
|
+
*
|
|
29488
|
+
* @example
|
|
29489
|
+
* ```typescript
|
|
29490
|
+
* const payload: BrokerActivePingPayload = {
|
|
29491
|
+
* symbol: "BTCUSDT",
|
|
29492
|
+
* position: "long",
|
|
29493
|
+
* currentPrice: 50500,
|
|
29494
|
+
* priceOpen: 50000,
|
|
29495
|
+
* priceTakeProfit: 55000,
|
|
29496
|
+
* priceStopLoss: 48000,
|
|
29497
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29498
|
+
* backtest: false,
|
|
29499
|
+
* };
|
|
29500
|
+
* ```
|
|
29501
|
+
*/
|
|
29502
|
+
type BrokerActivePingPayload = {
|
|
29503
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29504
|
+
symbol: string;
|
|
29505
|
+
/** Unique signal identifier (UUID v4) of the monitored position */
|
|
29506
|
+
signalId: string;
|
|
29507
|
+
/** Position direction */
|
|
29508
|
+
position: "long" | "short";
|
|
29509
|
+
/** Market price at the moment of the ping */
|
|
29510
|
+
currentPrice: number;
|
|
29511
|
+
/** Effective entry price (may differ from priceOpen after DCA averaging) */
|
|
29512
|
+
priceOpen: number;
|
|
29513
|
+
/** Effective take-profit price at the moment of the ping */
|
|
29514
|
+
priceTakeProfit: number;
|
|
29515
|
+
/** Effective stop-loss price at the moment of the ping */
|
|
29516
|
+
priceStopLoss: number;
|
|
29517
|
+
/** Unrealized PnL of the open position at the moment of the ping */
|
|
29518
|
+
pnl: IStrategyPnL;
|
|
29519
|
+
/** Strategy/exchange/frame routing context */
|
|
29520
|
+
context: {
|
|
29521
|
+
strategyName: StrategyName;
|
|
29522
|
+
exchangeName: ExchangeName;
|
|
29523
|
+
frameName?: FrameName;
|
|
29524
|
+
};
|
|
29525
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29526
|
+
backtest: boolean;
|
|
29527
|
+
};
|
|
29528
|
+
/**
|
|
29529
|
+
* Payload for the schedule-ping broker event.
|
|
29530
|
+
*
|
|
29531
|
+
* Emitted automatically via schedulePingSubject on every live tick while a scheduled signal is
|
|
29532
|
+
* monitored (waiting for priceOpen activation). Forwarded to the registered IBroker adapter via
|
|
29533
|
+
* `onSignalSchedulePing`. Purely informational.
|
|
29534
|
+
*
|
|
29535
|
+
* @example
|
|
29536
|
+
* ```typescript
|
|
29537
|
+
* const payload: BrokerSchedulePingPayload = {
|
|
29538
|
+
* symbol: "BTCUSDT",
|
|
29539
|
+
* position: "long",
|
|
29540
|
+
* currentPrice: 49800,
|
|
29541
|
+
* priceOpen: 50000,
|
|
29542
|
+
* priceTakeProfit: 55000,
|
|
29543
|
+
* priceStopLoss: 48000,
|
|
29544
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29545
|
+
* backtest: false,
|
|
29546
|
+
* };
|
|
29547
|
+
* ```
|
|
29548
|
+
*/
|
|
29549
|
+
type BrokerSchedulePingPayload = {
|
|
29550
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29551
|
+
symbol: string;
|
|
29552
|
+
/** Unique signal identifier (UUID v4) of the scheduled signal */
|
|
29553
|
+
signalId: string;
|
|
29554
|
+
/** Position direction */
|
|
29555
|
+
position: "long" | "short";
|
|
29556
|
+
/** Market price at the moment of the ping */
|
|
29557
|
+
currentPrice: number;
|
|
29558
|
+
/** Pending entry price the scheduled signal is waiting for */
|
|
29559
|
+
priceOpen: number;
|
|
29560
|
+
/** Take-profit price configured for the scheduled signal */
|
|
29561
|
+
priceTakeProfit: number;
|
|
29562
|
+
/** Stop-loss price configured for the scheduled signal */
|
|
29563
|
+
priceStopLoss: number;
|
|
29564
|
+
/** Strategy/exchange/frame routing context */
|
|
29565
|
+
context: {
|
|
29566
|
+
strategyName: StrategyName;
|
|
29567
|
+
exchangeName: ExchangeName;
|
|
29568
|
+
frameName?: FrameName;
|
|
29569
|
+
};
|
|
29570
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29571
|
+
backtest: boolean;
|
|
29572
|
+
};
|
|
29573
|
+
/**
|
|
29574
|
+
* Payload for the idle-ping broker event.
|
|
29575
|
+
*
|
|
29576
|
+
* Emitted automatically via idlePingSubject on every live tick while the strategy has no pending or
|
|
29577
|
+
* scheduled signal. Forwarded to the registered IBroker adapter via `onSignalIdlePing`. Purely
|
|
29578
|
+
* informational — carries no signal because none is active.
|
|
29579
|
+
*
|
|
29580
|
+
* @example
|
|
29581
|
+
* ```typescript
|
|
29582
|
+
* const payload: BrokerIdlePingPayload = {
|
|
29583
|
+
* symbol: "BTCUSDT",
|
|
29584
|
+
* currentPrice: 50500,
|
|
29585
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29586
|
+
* backtest: false,
|
|
29587
|
+
* };
|
|
29588
|
+
* ```
|
|
29589
|
+
*/
|
|
29590
|
+
type BrokerIdlePingPayload = {
|
|
29591
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29592
|
+
symbol: string;
|
|
29593
|
+
/** Market price at the moment of the ping */
|
|
29594
|
+
currentPrice: number;
|
|
29595
|
+
/** Strategy/exchange/frame routing context */
|
|
29596
|
+
context: {
|
|
29597
|
+
strategyName: StrategyName;
|
|
29598
|
+
exchangeName: ExchangeName;
|
|
29599
|
+
frameName?: FrameName;
|
|
29600
|
+
};
|
|
29601
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29602
|
+
backtest: boolean;
|
|
29603
|
+
};
|
|
29604
|
+
/**
|
|
29605
|
+
* Payload for the scheduled-signal-open broker event.
|
|
29606
|
+
*
|
|
29607
|
+
* Emitted automatically via scheduleEventSubject (action "scheduled") when a new scheduled signal is
|
|
29608
|
+
* created and starts waiting for priceOpen activation. Forwarded to the registered IBroker adapter
|
|
29609
|
+
* via `onSignalScheduleOpen`. The scheduled -> active transition is NOT reported here — activation
|
|
29610
|
+
* arrives through `onSignalOpenCommit`.
|
|
29611
|
+
*
|
|
29612
|
+
* @example
|
|
29613
|
+
* ```typescript
|
|
29614
|
+
* const payload: BrokerScheduleOpenPayload = {
|
|
29615
|
+
* symbol: "BTCUSDT",
|
|
29616
|
+
* position: "long",
|
|
29617
|
+
* currentPrice: 49800,
|
|
29618
|
+
* priceOpen: 50000,
|
|
29619
|
+
* priceTakeProfit: 55000,
|
|
29620
|
+
* priceStopLoss: 48000,
|
|
29621
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29622
|
+
* backtest: false,
|
|
29623
|
+
* };
|
|
29624
|
+
* ```
|
|
29625
|
+
*/
|
|
29626
|
+
type BrokerScheduleOpenPayload = {
|
|
29627
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29628
|
+
symbol: string;
|
|
29629
|
+
/** Unique signal identifier (UUID v4) of the scheduled signal */
|
|
29630
|
+
signalId: string;
|
|
29631
|
+
/** Position direction */
|
|
29632
|
+
position: "long" | "short";
|
|
29633
|
+
/** Market price at the moment the scheduled signal was created */
|
|
29634
|
+
currentPrice: number;
|
|
29635
|
+
/** Pending entry price the scheduled signal waits for */
|
|
29636
|
+
priceOpen: number;
|
|
29637
|
+
/** Take-profit price configured for the scheduled signal */
|
|
29638
|
+
priceTakeProfit: number;
|
|
29639
|
+
/** Stop-loss price configured for the scheduled signal */
|
|
29640
|
+
priceStopLoss: number;
|
|
29641
|
+
/** Strategy/exchange/frame routing context */
|
|
29642
|
+
context: {
|
|
29643
|
+
strategyName: StrategyName;
|
|
29644
|
+
exchangeName: ExchangeName;
|
|
29645
|
+
frameName?: FrameName;
|
|
29646
|
+
};
|
|
29647
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29648
|
+
backtest: boolean;
|
|
29649
|
+
};
|
|
29650
|
+
/**
|
|
29651
|
+
* Payload for the scheduled-signal-cancelled broker event.
|
|
29652
|
+
*
|
|
29653
|
+
* Emitted automatically via scheduleEventSubject (action "cancelled") when a scheduled signal is
|
|
29654
|
+
* removed before it ever activated. Forwarded to the registered IBroker adapter via
|
|
29655
|
+
* `onSignalScheduleCancelled`. The `reason` distinguishes timeout / price reject / user cancel.
|
|
29656
|
+
*
|
|
29657
|
+
* @example
|
|
29658
|
+
* ```typescript
|
|
29659
|
+
* const payload: BrokerScheduleCancelledPayload = {
|
|
29660
|
+
* symbol: "BTCUSDT",
|
|
29661
|
+
* position: "long",
|
|
29662
|
+
* currentPrice: 47500,
|
|
29663
|
+
* priceOpen: 50000,
|
|
29664
|
+
* priceTakeProfit: 55000,
|
|
29665
|
+
* priceStopLoss: 48000,
|
|
29666
|
+
* reason: "price_reject",
|
|
29667
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29668
|
+
* backtest: false,
|
|
29669
|
+
* };
|
|
29670
|
+
* ```
|
|
29671
|
+
*/
|
|
29672
|
+
type BrokerScheduleCancelledPayload = {
|
|
29673
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29674
|
+
symbol: string;
|
|
29675
|
+
/** Unique signal identifier (UUID v4) of the cancelled scheduled signal */
|
|
29676
|
+
signalId: string;
|
|
29677
|
+
/** Position direction */
|
|
29678
|
+
position: "long" | "short";
|
|
29679
|
+
/** Market price at the moment of cancellation */
|
|
29680
|
+
currentPrice: number;
|
|
29681
|
+
/** Pending entry price the scheduled signal had been waiting for */
|
|
29682
|
+
priceOpen: number;
|
|
29683
|
+
/** Take-profit price that had been configured for the scheduled signal */
|
|
29684
|
+
priceTakeProfit: number;
|
|
29685
|
+
/** Stop-loss price that had been configured for the scheduled signal */
|
|
29686
|
+
priceStopLoss: number;
|
|
29687
|
+
/** Why the scheduled signal was cancelled: "timeout" / "price_reject" / "user" */
|
|
29688
|
+
reason?: StrategyCancelReason;
|
|
29689
|
+
/** Strategy/exchange/frame routing context */
|
|
29690
|
+
context: {
|
|
29691
|
+
strategyName: StrategyName;
|
|
29692
|
+
exchangeName: ExchangeName;
|
|
29693
|
+
frameName?: FrameName;
|
|
29694
|
+
};
|
|
29695
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29696
|
+
backtest: boolean;
|
|
29697
|
+
};
|
|
29698
|
+
/**
|
|
29699
|
+
* Payload for the pending-signal-open broker event.
|
|
29700
|
+
*
|
|
29701
|
+
* Emitted automatically via signalEventSubject (action "opened") when a pending position is opened
|
|
29702
|
+
* (new signal / immediate entry / scheduled or user activation). Forwarded to the registered IBroker
|
|
29703
|
+
* adapter via `onSignalPendingOpen`.
|
|
29704
|
+
*
|
|
29705
|
+
* @example
|
|
29706
|
+
* ```typescript
|
|
29707
|
+
* const payload: BrokerPendingOpenPayload = {
|
|
29708
|
+
* symbol: "BTCUSDT",
|
|
29709
|
+
* position: "long",
|
|
29710
|
+
* currentPrice: 50000,
|
|
29711
|
+
* priceOpen: 50000,
|
|
29712
|
+
* priceTakeProfit: 55000,
|
|
29713
|
+
* priceStopLoss: 48000,
|
|
29714
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29715
|
+
* backtest: false,
|
|
29716
|
+
* };
|
|
29717
|
+
* ```
|
|
29718
|
+
*/
|
|
29719
|
+
type BrokerPendingOpenPayload = {
|
|
29720
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29721
|
+
symbol: string;
|
|
29722
|
+
/** Unique signal identifier (UUID v4) of the opened position */
|
|
29723
|
+
signalId: string;
|
|
29724
|
+
/** Position direction */
|
|
29725
|
+
position: "long" | "short";
|
|
29726
|
+
/** Effective entry price at the moment the position opened */
|
|
29727
|
+
currentPrice: number;
|
|
29728
|
+
/** Effective entry price (may differ from currentPrice after DCA averaging) */
|
|
29729
|
+
priceOpen: number;
|
|
29730
|
+
/** Take-profit price configured for the position */
|
|
29731
|
+
priceTakeProfit: number;
|
|
29732
|
+
/** Stop-loss price configured for the position */
|
|
29733
|
+
priceStopLoss: number;
|
|
29734
|
+
/** Strategy/exchange/frame routing context */
|
|
29735
|
+
context: {
|
|
29736
|
+
strategyName: StrategyName;
|
|
29737
|
+
exchangeName: ExchangeName;
|
|
29738
|
+
frameName?: FrameName;
|
|
29739
|
+
};
|
|
29740
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29741
|
+
backtest: boolean;
|
|
29742
|
+
};
|
|
29743
|
+
/**
|
|
29744
|
+
* Payload for the pending-signal-close broker event.
|
|
29745
|
+
*
|
|
29746
|
+
* Emitted automatically via signalEventSubject (action "closed") when a pending position is closed.
|
|
29747
|
+
* Forwarded to the registered IBroker adapter via `onSignalPendingClose`. The `closeReason`
|
|
29748
|
+
* distinguishes take_profit / stop_loss / time_expired / user-close / broker fill / order gone.
|
|
29749
|
+
*
|
|
29750
|
+
* @example
|
|
29751
|
+
* ```typescript
|
|
29752
|
+
* const payload: BrokerPendingClosePayload = {
|
|
29753
|
+
* symbol: "BTCUSDT",
|
|
29754
|
+
* position: "long",
|
|
29755
|
+
* currentPrice: 55000,
|
|
29756
|
+
* priceOpen: 50000,
|
|
29757
|
+
* priceTakeProfit: 55000,
|
|
29758
|
+
* priceStopLoss: 48000,
|
|
29759
|
+
* closeReason: "take_profit",
|
|
29760
|
+
* context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
|
|
29761
|
+
* backtest: false,
|
|
29762
|
+
* };
|
|
29763
|
+
* ```
|
|
29764
|
+
*/
|
|
29765
|
+
type BrokerPendingClosePayload = {
|
|
29766
|
+
/** Trading pair symbol, e.g. "BTCUSDT" */
|
|
29767
|
+
symbol: string;
|
|
29768
|
+
/** Unique signal identifier (UUID v4) of the closed position */
|
|
29769
|
+
signalId: string;
|
|
29770
|
+
/** Position direction */
|
|
29771
|
+
position: "long" | "short";
|
|
29772
|
+
/** Market price at the moment of close */
|
|
29773
|
+
currentPrice: number;
|
|
29774
|
+
/** Effective entry price of the closed position */
|
|
29775
|
+
priceOpen: number;
|
|
29776
|
+
/** Effective take-profit price of the closed position */
|
|
29777
|
+
priceTakeProfit: number;
|
|
29778
|
+
/** Effective stop-loss price of the closed position */
|
|
29779
|
+
priceStopLoss: number;
|
|
29780
|
+
/** Why the position closed: "take_profit" / "stop_loss" / "time_expired" / "closed" */
|
|
29781
|
+
closeReason?: StrategyCloseReason;
|
|
29782
|
+
/** Strategy/exchange/frame routing context */
|
|
29783
|
+
context: {
|
|
29784
|
+
strategyName: StrategyName;
|
|
29785
|
+
exchangeName: ExchangeName;
|
|
29786
|
+
frameName?: FrameName;
|
|
29787
|
+
};
|
|
29788
|
+
/** true when called during a backtest run — adapter should skip exchange calls */
|
|
29789
|
+
backtest: boolean;
|
|
29790
|
+
};
|
|
28857
29791
|
/**
|
|
28858
29792
|
* Payload for a partial-profit close broker event.
|
|
28859
29793
|
*
|
|
@@ -29143,9 +30077,36 @@ type BrokerAverageBuyPayload = {
|
|
|
29143
30077
|
interface IBroker {
|
|
29144
30078
|
/** Called once before first use. Connect to exchange, load credentials, etc. */
|
|
29145
30079
|
waitForInit(): Promise<void>;
|
|
29146
|
-
/**
|
|
30080
|
+
/**
|
|
30081
|
+
* Called when a signal is being closed (take-profit, stop-loss, or manual close). Emitted via
|
|
30082
|
+
* syncSubject BEFORE the framework mutates strategy state, so it is also the close **gate**.
|
|
30083
|
+
*
|
|
30084
|
+
* MANUAL WIRING — EXCEPTION-BASED: place the real exit order here (tag/look up by `payload.signalId`)
|
|
30085
|
+
* and record final PnL. This is the confirmed-close commit; like `onSignalSync` (signal-close) it
|
|
30086
|
+
* shares the gate semantics — a THROW means "the exchange did not close the position" and the
|
|
30087
|
+
* framework SKIPS the close, leaving the position open and retrying on the next tick. Return
|
|
30088
|
+
* normally to let the close proceed. Backtest short-circuits this (no live exchange), so the gate is
|
|
30089
|
+
* live-only.
|
|
30090
|
+
*
|
|
30091
|
+
* This differs from `onSignalPendingClose`, which is the informational lifecycle hook that fires
|
|
30092
|
+
* AFTER the close is committed (and cannot veto it).
|
|
30093
|
+
*/
|
|
29147
30094
|
onSignalCloseCommit(payload: BrokerSignalClosePayload): Promise<void>;
|
|
29148
|
-
/**
|
|
30095
|
+
/**
|
|
30096
|
+
* Called when a signal is being opened (position entry). Emitted via syncSubject BEFORE the
|
|
30097
|
+
* framework mutates strategy state, so it is also the open **gate**.
|
|
30098
|
+
*
|
|
30099
|
+
* MANUAL WIRING — EXCEPTION-BASED: place the real entry order here (tag the exchange order with
|
|
30100
|
+
* `payload.signalId` so later `onOrderCheck` / `onSignalActivePing` can find it). Like `onSignalSync`
|
|
30101
|
+
* (signal-open) it shares the gate semantics — a THROW means "the exchange did not fill the entry"
|
|
30102
|
+
* (e.g. limit order rejected) and the framework ROLLS BACK the open: the pending signal returns to
|
|
30103
|
+
* idle (a scheduled activation is cancelled) and is retried on the next tick. Return normally to let
|
|
30104
|
+
* the open proceed. Also the point where a scheduled signal's activation surfaces. Backtest
|
|
30105
|
+
* short-circuits this, so the gate is live-only.
|
|
30106
|
+
*
|
|
30107
|
+
* This differs from `onSignalPendingOpen`, which is the informational lifecycle hook that fires
|
|
30108
|
+
* AFTER the open is committed (and cannot veto it).
|
|
30109
|
+
*/
|
|
29149
30110
|
onSignalOpenCommit(payload: BrokerSignalOpenPayload): Promise<void>;
|
|
29150
30111
|
/**
|
|
29151
30112
|
* Called on every live tick while a pending signal is monitored, BEFORE TP/SL/time evaluation.
|
|
@@ -29156,8 +30117,186 @@ interface IBroker {
|
|
|
29156
30117
|
* CRITICAL: swallow transient/network errors (timeout, 5xx, rate limit, disconnect) — return
|
|
29157
30118
|
* normally instead of throwing, otherwise a connectivity blip would wrongly close an open
|
|
29158
30119
|
* position. Throw exclusively on a confirmed "order not found by id" result.
|
|
30120
|
+
*
|
|
30121
|
+
* Manual wiring — EXCEPTION-BASED VARIANT
|
|
30122
|
+
*
|
|
30123
|
+
* This is the throw-driven **alternative** to the imperative commit-function wiring in
|
|
30124
|
+
* `onSignalActivePing`:
|
|
30125
|
+
* - **Exception-based (here):** THROW → framework closes the position with closeReason "closed".
|
|
30126
|
+
* One binary gate, no reason distinction. Good when "order gone" is the only condition you handle.
|
|
30127
|
+
* - **Imperative (`onSignalActivePing` + `src/function/strategy.ts`):** call
|
|
30128
|
+
* `commitClosePending` / `commitCreateTakeProfit` / `commitCreateStopLoss` to close with the
|
|
30129
|
+
* correct reason and handle TP vs SL vs no-counterparty separately.
|
|
30130
|
+
*
|
|
30131
|
+
* Pick ONE per condition — do not both throw here AND `commitClosePending` in the active-ping for
|
|
30132
|
+
* the same "order gone" event.
|
|
30133
|
+
*
|
|
30134
|
+
* @example
|
|
30135
|
+
* ```typescript
|
|
30136
|
+
* async onOrderCheck(payload: BrokerSignalPendingPayload) {
|
|
30137
|
+
* let order: Order | null;
|
|
30138
|
+
* try {
|
|
30139
|
+
* order = await this.exchange.getOrderById(payload.signalId);
|
|
30140
|
+
* } catch (networkError) {
|
|
30141
|
+
* return; // transient — keep the position open, retry next tick
|
|
30142
|
+
* }
|
|
30143
|
+
* if (!order) {
|
|
30144
|
+
* throw new Error(`Order ${payload.signalId} not found`); // confirmed gone -> close "closed"
|
|
30145
|
+
* }
|
|
30146
|
+
* }
|
|
30147
|
+
* ```
|
|
30148
|
+
*/
|
|
30149
|
+
onOrderCheck(payload: BrokerSignalPendingPayload): Promise<void>;
|
|
30150
|
+
/**
|
|
30151
|
+
* Called on every live tick while a pending (open) signal is monitored.
|
|
30152
|
+
* Purely informational mirror of the active-ping lifecycle — a throw here does NOT close the
|
|
30153
|
+
* position (unlike `onOrderCheck`).
|
|
30154
|
+
*
|
|
30155
|
+
* Manual wiring — EVENT-BASED (driving an open position from real exchange state)
|
|
30156
|
+
*
|
|
30157
|
+
* Primary per-tick **event-based** hook for an open position (a throw does NOT close it — react to
|
|
30158
|
+
* the event and decide imperatively). This is where you reconcile the framework's VWAP view with
|
|
30159
|
+
* real fills: catch a **SL that gapped through** the level, or a **TP that filled before VWAP**
|
|
30160
|
+
* reached it. Poll your real order and translate its state into strategy state via the
|
|
30161
|
+
* commit-functions from `src/function/strategy.ts` (callable here because the ping is emitted inside
|
|
30162
|
+
* the strategy tick; effects are deferred to the next tick):
|
|
30163
|
+
* - `commitCreateTakeProfit(symbol, { id })` — real TP order filled (possibly before VWAP reached
|
|
30164
|
+
* the level) → force close, reason "take_profit".
|
|
30165
|
+
* - `commitCreateStopLoss(symbol, { id })` — real SL order filled (e.g. price gapped through SL) →
|
|
30166
|
+
* force close, reason "stop_loss".
|
|
30167
|
+
* - `commitClosePending(symbol, { id })` — no counterparty (no buyer/seller, liquidity gap) → close
|
|
30168
|
+
* now with reason "closed", instead of throwing.
|
|
30169
|
+
*
|
|
30170
|
+
* @example
|
|
30171
|
+
* ```typescript
|
|
30172
|
+
* import { commitCreateTakeProfit, commitCreateStopLoss, commitClosePending } from "backtest-kit";
|
|
30173
|
+
*
|
|
30174
|
+
* async onSignalActivePing(payload: BrokerActivePingPayload) {
|
|
30175
|
+
* const order = await this.exchange.getOrderById(payload.signalId);
|
|
30176
|
+
* if (order?.status === "filled" && order.kind === "take_profit") {
|
|
30177
|
+
* await commitCreateTakeProfit(payload.symbol, { id: order.id });
|
|
30178
|
+
* } else if (order?.status === "filled" && order.kind === "stop_loss") {
|
|
30179
|
+
* await commitCreateStopLoss(payload.symbol, { id: order.id });
|
|
30180
|
+
* } else if (order?.status === "no_counterparty") {
|
|
30181
|
+
* await commitClosePending(payload.symbol, { id: order.id });
|
|
30182
|
+
* }
|
|
30183
|
+
* }
|
|
30184
|
+
* ```
|
|
30185
|
+
*/
|
|
30186
|
+
onSignalActivePing(payload: BrokerActivePingPayload): Promise<void>;
|
|
30187
|
+
/**
|
|
30188
|
+
* Called on every live tick while a scheduled signal is monitored (waiting for priceOpen
|
|
30189
|
+
* activation). Purely informational.
|
|
30190
|
+
*
|
|
30191
|
+
* Manual wiring — EVENT-BASED (driving the scheduled phase from real exchange state)
|
|
30192
|
+
*
|
|
30193
|
+
* Per-tick **event-based** hook (a throw does NOT veto anything — react and decide imperatively).
|
|
30194
|
+
* Poll your real resting/limit order and translate it via the commit-functions from
|
|
30195
|
+
* `src/function/strategy.ts` (deferred to the next tick):
|
|
30196
|
+
* - `commitActivateScheduled(symbol, { id })` — resting order filled/resolved → activate now,
|
|
30197
|
+
* without waiting for VWAP to reach priceOpen (surfaces as `onSignalOpenCommit` next tick).
|
|
30198
|
+
* - `commitCancelScheduled(symbol, { id })` — resting order cancelled/rejected externally → drop it.
|
|
30199
|
+
*
|
|
30200
|
+
* @example
|
|
30201
|
+
* ```typescript
|
|
30202
|
+
* import { commitActivateScheduled, commitCancelScheduled } from "backtest-kit";
|
|
30203
|
+
*
|
|
30204
|
+
* async onSignalSchedulePing(payload: BrokerSchedulePingPayload) {
|
|
30205
|
+
* const order = await this.exchange.getOrderById(payload.signalId);
|
|
30206
|
+
* if (order?.status === "filled" || order?.status === "resolved") {
|
|
30207
|
+
* await commitActivateScheduled(payload.symbol, { id: order.id });
|
|
30208
|
+
* } else if (order?.status === "cancelled" || order?.status === "rejected") {
|
|
30209
|
+
* await commitCancelScheduled(payload.symbol, { id: order.id });
|
|
30210
|
+
* }
|
|
30211
|
+
* }
|
|
30212
|
+
* ```
|
|
30213
|
+
*/
|
|
30214
|
+
onSignalSchedulePing(payload: BrokerSchedulePingPayload): Promise<void>;
|
|
30215
|
+
/**
|
|
30216
|
+
* Called on every live tick while the strategy is idle (no pending or scheduled signal).
|
|
30217
|
+
* Purely informational.
|
|
30218
|
+
*
|
|
30219
|
+
* MANUAL WIRING — EVENT-BASED: no signal is active, so there is nothing to commit; use it for idle
|
|
30220
|
+
* heartbeats / housekeeping. A throw does not affect strategy state.
|
|
30221
|
+
*/
|
|
30222
|
+
onSignalIdlePing(payload: BrokerIdlePingPayload): Promise<void>;
|
|
30223
|
+
/**
|
|
30224
|
+
* Called when a new scheduled signal is created and starts waiting for priceOpen activation.
|
|
30225
|
+
* The scheduled -> active transition is reported via `onSignalOpenCommit`, not here.
|
|
30226
|
+
*
|
|
30227
|
+
* Manual wiring — EVENT-BASED (placing the resting order)
|
|
30228
|
+
*
|
|
30229
|
+
* Fires ONCE at creation — place the real resting/limit order (tag it with `payload.signalId` so
|
|
30230
|
+
* `onSignalSchedulePing` can poll it later). If it resolves immediately, promote it with
|
|
30231
|
+
* `commitActivateScheduled(symbol, { id })`; if rejected, drop it with
|
|
30232
|
+
* `commitCancelScheduled(symbol, { id })`. Use `onSignalSchedulePing` for ongoing polling.
|
|
30233
|
+
*
|
|
30234
|
+
* @example
|
|
30235
|
+
* ```typescript
|
|
30236
|
+
* import { commitActivateScheduled, commitCancelScheduled } from "backtest-kit";
|
|
30237
|
+
*
|
|
30238
|
+
* async onSignalScheduleOpen(payload: BrokerScheduleOpenPayload) {
|
|
30239
|
+
* const order = await this.exchange.placeLimitOrder({
|
|
30240
|
+
* id: payload.signalId,
|
|
30241
|
+
* symbol: payload.symbol,
|
|
30242
|
+
* side: payload.position,
|
|
30243
|
+
* price: payload.priceOpen,
|
|
30244
|
+
* });
|
|
30245
|
+
* if (order.status === "filled") await commitActivateScheduled(payload.symbol, { id: order.id });
|
|
30246
|
+
* else if (order.status === "rejected") await commitCancelScheduled(payload.symbol, { id: order.id });
|
|
30247
|
+
* }
|
|
30248
|
+
* ```
|
|
30249
|
+
*/
|
|
30250
|
+
onSignalScheduleOpen(payload: BrokerScheduleOpenPayload): Promise<void>;
|
|
30251
|
+
/**
|
|
30252
|
+
* Called when a scheduled signal is cancelled before it ever activated
|
|
30253
|
+
* (reason: timeout / price_reject / user).
|
|
30254
|
+
*
|
|
30255
|
+
* Manual wiring — EVENT-BASED (tearing down the resting order)
|
|
30256
|
+
*
|
|
30257
|
+
* Outbound side — the framework has already dropped the scheduled signal, so there is nothing to
|
|
30258
|
+
* `commitCancelScheduled` here; instead cancel the real resting order you placed in
|
|
30259
|
+
* `onSignalScheduleOpen` (look it up by `payload.signalId`). `payload.reason` tells you why.
|
|
30260
|
+
*
|
|
30261
|
+
* @example
|
|
30262
|
+
* ```typescript
|
|
30263
|
+
* async onSignalScheduleCancelled(payload: BrokerScheduleCancelledPayload) {
|
|
30264
|
+
* await this.exchange.cancelOrderById(payload.signalId);
|
|
30265
|
+
* }
|
|
30266
|
+
* ```
|
|
30267
|
+
*/
|
|
30268
|
+
onSignalScheduleCancelled(payload: BrokerScheduleCancelledPayload): Promise<void>;
|
|
30269
|
+
/**
|
|
30270
|
+
* Called when a pending position is opened (new signal / immediate / scheduled or user
|
|
30271
|
+
* activation). Purely informational lifecycle hook for the active phase of a signal.
|
|
30272
|
+
*
|
|
30273
|
+
* Manual wiring — EVENT-BASED (placing entry + protective orders)
|
|
30274
|
+
*
|
|
30275
|
+
* Fires ONCE at open — place the real entry confirmation and protective TP/SL orders (tag them with
|
|
30276
|
+
* `payload.signalId`). Drive the rest per-tick from `onSignalActivePing`. This hook does not gate
|
|
30277
|
+
* the position; for a true entry gate use `onSignalSync` (signal-open).
|
|
29159
30278
|
*/
|
|
29160
|
-
|
|
30279
|
+
onSignalPendingOpen(payload: BrokerPendingOpenPayload): Promise<void>;
|
|
30280
|
+
/**
|
|
30281
|
+
* Called when a pending position is closed
|
|
30282
|
+
* (reason: take_profit / stop_loss / time_expired / closed).
|
|
30283
|
+
*
|
|
30284
|
+
* Manual wiring — EVENT-BASED (tearing down the position)
|
|
30285
|
+
*
|
|
30286
|
+
* Outbound side — the framework has already removed the pending signal, so there is nothing to
|
|
30287
|
+
* `commitClosePending` here; instead flatten the real position and cancel leftover TP/SL orders by
|
|
30288
|
+
* `payload.signalId`, and record final PnL. `payload.closeReason` says which path closed it. If you
|
|
30289
|
+
* need to FORCE the close yourself (e.g. no counterparty), do it earlier in `onSignalActivePing`.
|
|
30290
|
+
*
|
|
30291
|
+
* @example
|
|
30292
|
+
* ```typescript
|
|
30293
|
+
* async onSignalPendingClose(payload: BrokerPendingClosePayload) {
|
|
30294
|
+
* await this.exchange.flatten(payload.symbol);
|
|
30295
|
+
* await this.exchange.cancelProtectiveOrders(payload.signalId);
|
|
30296
|
+
* }
|
|
30297
|
+
* ```
|
|
30298
|
+
*/
|
|
30299
|
+
onSignalPendingClose(payload: BrokerPendingClosePayload): Promise<void>;
|
|
29161
30300
|
/** Called when a partial profit close is committed. */
|
|
29162
30301
|
onPartialProfitCommit(payload: BrokerPartialProfitPayload): Promise<void>;
|
|
29163
30302
|
/** Called when a partial loss close is committed. */
|
|
@@ -29290,6 +30429,72 @@ declare class BrokerAdapter {
|
|
|
29290
30429
|
* @param payload - Pending ping details: symbol, position, prices, pnl, context, backtest flag
|
|
29291
30430
|
*/
|
|
29292
30431
|
commitSignalPending: (payload: BrokerSignalPendingPayload) => Promise<void>;
|
|
30432
|
+
/**
|
|
30433
|
+
* Forwards an active-ping to the registered broker adapter.
|
|
30434
|
+
*
|
|
30435
|
+
* Called automatically via activePingSubject when `enable()` is active, on every live tick while a
|
|
30436
|
+
* pending signal is monitored. Skipped silently in backtest mode or when no adapter is registered.
|
|
30437
|
+
* Purely informational — a throw does NOT close the position.
|
|
30438
|
+
*
|
|
30439
|
+
* @param payload - Active ping details: symbol, signalId, position, prices, pnl, context, backtest
|
|
30440
|
+
*/
|
|
30441
|
+
commitActivePing: (payload: BrokerActivePingPayload) => Promise<void>;
|
|
30442
|
+
/**
|
|
30443
|
+
* Forwards a schedule-ping to the registered broker adapter.
|
|
30444
|
+
*
|
|
30445
|
+
* Called automatically via schedulePingSubject when `enable()` is active, on every live tick while
|
|
30446
|
+
* a scheduled signal is monitored. Skipped silently in backtest mode or when no adapter is
|
|
30447
|
+
* registered. Purely informational.
|
|
30448
|
+
*
|
|
30449
|
+
* @param payload - Schedule ping details: symbol, signalId, position, prices, context, backtest
|
|
30450
|
+
*/
|
|
30451
|
+
commitSchedulePing: (payload: BrokerSchedulePingPayload) => Promise<void>;
|
|
30452
|
+
/**
|
|
30453
|
+
* Forwards an idle-ping to the registered broker adapter.
|
|
30454
|
+
*
|
|
30455
|
+
* Called automatically via idlePingSubject when `enable()` is active, on every live tick while the
|
|
30456
|
+
* strategy has no pending or scheduled signal. Skipped silently in backtest mode or when no adapter
|
|
30457
|
+
* is registered. Purely informational.
|
|
30458
|
+
*
|
|
30459
|
+
* @param payload - Idle ping details: symbol, currentPrice, context, backtest
|
|
30460
|
+
*/
|
|
30461
|
+
commitIdlePing: (payload: BrokerIdlePingPayload) => Promise<void>;
|
|
30462
|
+
/**
|
|
30463
|
+
* Forwards a scheduled-signal-open to the registered broker adapter.
|
|
30464
|
+
*
|
|
30465
|
+
* Called automatically via scheduleEventSubject (action "scheduled") when a scheduled signal is
|
|
30466
|
+
* created. Skipped silently in backtest mode or when no adapter is registered.
|
|
30467
|
+
*
|
|
30468
|
+
* @param payload - Scheduled open details: symbol, signalId, position, prices, context, backtest
|
|
30469
|
+
*/
|
|
30470
|
+
commitScheduleOpen: (payload: BrokerScheduleOpenPayload) => Promise<void>;
|
|
30471
|
+
/**
|
|
30472
|
+
* Forwards a scheduled-signal-cancelled to the registered broker adapter.
|
|
30473
|
+
*
|
|
30474
|
+
* Called automatically via scheduleEventSubject (action "cancelled") when a scheduled signal is
|
|
30475
|
+
* removed before activation. Skipped silently in backtest mode or when no adapter is registered.
|
|
30476
|
+
*
|
|
30477
|
+
* @param payload - Scheduled cancel details: symbol, signalId, position, prices, reason, context, backtest
|
|
30478
|
+
*/
|
|
30479
|
+
commitScheduleCancelled: (payload: BrokerScheduleCancelledPayload) => Promise<void>;
|
|
30480
|
+
/**
|
|
30481
|
+
* Forwards a pending-signal-open to the registered broker adapter.
|
|
30482
|
+
*
|
|
30483
|
+
* Called automatically via signalEventSubject (action "opened") when a pending position is opened.
|
|
30484
|
+
* Skipped silently in backtest mode or when no adapter is registered.
|
|
30485
|
+
*
|
|
30486
|
+
* @param payload - Pending open details: symbol, signalId, position, prices, context, backtest
|
|
30487
|
+
*/
|
|
30488
|
+
commitPendingOpen: (payload: BrokerPendingOpenPayload) => Promise<void>;
|
|
30489
|
+
/**
|
|
30490
|
+
* Forwards a pending-signal-close to the registered broker adapter.
|
|
30491
|
+
*
|
|
30492
|
+
* Called automatically via signalEventSubject (action "closed") when a pending position is closed.
|
|
30493
|
+
* Skipped silently in backtest mode or when no adapter is registered.
|
|
30494
|
+
*
|
|
30495
|
+
* @param payload - Pending close details: symbol, signalId, position, prices, closeReason, context, backtest
|
|
30496
|
+
*/
|
|
30497
|
+
commitPendingClose: (payload: BrokerPendingClosePayload) => Promise<void>;
|
|
29293
30498
|
/**
|
|
29294
30499
|
* Intercepts a partial-profit close before DI-core mutation.
|
|
29295
30500
|
*
|
|
@@ -29606,24 +30811,32 @@ declare class BrokerBase implements IBroker {
|
|
|
29606
30811
|
*/
|
|
29607
30812
|
waitForInit(): Promise<void>;
|
|
29608
30813
|
/**
|
|
29609
|
-
* Called when a
|
|
30814
|
+
* Called when a position is being opened (signal activated).
|
|
29610
30815
|
*
|
|
29611
30816
|
* Triggered automatically via syncSubject when a scheduled signal's priceOpen is hit.
|
|
29612
30817
|
* Use to place the actual entry order on the exchange.
|
|
29613
30818
|
*
|
|
29614
30819
|
* Default implementation: Logs signal-open event.
|
|
29615
30820
|
*
|
|
30821
|
+
* Manual wiring — EXCEPTION-BASED GATE: emitted BEFORE the framework mutates state, so a THROW here
|
|
30822
|
+
* (e.g. limit order rejected) rolls back the open — the pending signal returns to idle and retries
|
|
30823
|
+
* next tick; return normally to let it open. Live-only (backtest short-circuits). See
|
|
30824
|
+
* {@link IBroker.onSignalOpenCommit} for the full semantics.
|
|
30825
|
+
*
|
|
29616
30826
|
* @param payload - Signal open details: symbol, cost, position, priceOpen, priceTakeProfit, priceStopLoss, context, backtest
|
|
29617
30827
|
*
|
|
29618
30828
|
* @example
|
|
29619
30829
|
* ```typescript
|
|
29620
30830
|
* async onSignalOpenCommit(payload: BrokerSignalOpenPayload) {
|
|
29621
30831
|
* super.onSignalOpenCommit(payload); // Keep parent logging
|
|
29622
|
-
* await this.exchange.placeMarketOrder({
|
|
30832
|
+
* const order = await this.exchange.placeMarketOrder({
|
|
29623
30833
|
* symbol: payload.symbol,
|
|
29624
30834
|
* side: payload.position === "long" ? "BUY" : "SELL",
|
|
29625
30835
|
* quantity: payload.cost / payload.priceOpen,
|
|
29626
30836
|
* });
|
|
30837
|
+
* if (!order.filled) {
|
|
30838
|
+
* throw new Error(`Entry not filled for ${payload.symbol}`); // -> roll back the open, retry next tick
|
|
30839
|
+
* }
|
|
29627
30840
|
* }
|
|
29628
30841
|
* ```
|
|
29629
30842
|
*/
|
|
@@ -29640,42 +30853,118 @@ declare class BrokerBase implements IBroker {
|
|
|
29640
30853
|
* normally instead of throwing. A thrown network error would wrongly close an open position; only
|
|
29641
30854
|
* a confirmed "order not found by id" response is a valid reason to throw.
|
|
29642
30855
|
*
|
|
30856
|
+
* Manual wiring — EXCEPTION-BASED VARIANT: the throw-driven alternative to the imperative
|
|
30857
|
+
* commit-function wiring in `onSignalActivePing`. See {@link IBroker.onOrderCheck} for the full
|
|
30858
|
+
* comparison and example.
|
|
30859
|
+
*
|
|
29643
30860
|
* @param payload - Pending ping details: symbol, signalId, position, prices, pnl, context, backtest
|
|
30861
|
+
*/
|
|
30862
|
+
onOrderCheck(payload: BrokerSignalPendingPayload): Promise<void>;
|
|
30863
|
+
/**
|
|
30864
|
+
* Called on every live tick while a pending (open) signal is monitored.
|
|
29644
30865
|
*
|
|
29645
|
-
*
|
|
29646
|
-
*
|
|
29647
|
-
*
|
|
29648
|
-
*
|
|
29649
|
-
*
|
|
29650
|
-
*
|
|
29651
|
-
*
|
|
29652
|
-
*
|
|
29653
|
-
*
|
|
29654
|
-
|
|
29655
|
-
|
|
29656
|
-
|
|
29657
|
-
*
|
|
29658
|
-
*
|
|
29659
|
-
*
|
|
29660
|
-
*
|
|
29661
|
-
*
|
|
30866
|
+
* Purely informational mirror of the active-ping lifecycle — unlike `onOrderCheck`, a throw here
|
|
30867
|
+
* does NOT close the position. Override to mirror live monitoring state into your own systems.
|
|
30868
|
+
* The default implementation logs.
|
|
30869
|
+
*
|
|
30870
|
+
* Manual wiring — EVENT-BASED: this is the primary per-tick hook to drive an open position from real exchange
|
|
30871
|
+
* state (`commitCreateTakeProfit` / `commitCreateStopLoss` / `commitClosePending`). See the
|
|
30872
|
+
* {@link IBroker.onSignalActivePing} contract docs for the full guidance and example.
|
|
30873
|
+
*
|
|
30874
|
+
* @param payload - Active ping details: symbol, signalId, position, prices, pnl, context, backtest
|
|
30875
|
+
*/
|
|
30876
|
+
onSignalActivePing(payload: BrokerActivePingPayload): Promise<void>;
|
|
30877
|
+
/**
|
|
30878
|
+
* Called on every live tick while a scheduled signal is monitored (waiting for priceOpen).
|
|
30879
|
+
*
|
|
30880
|
+
* Purely informational. Override to mirror scheduled-monitoring state. The default logs.
|
|
30881
|
+
*
|
|
30882
|
+
* Manual wiring — EVENT-BASED: per-tick hook to drive a scheduled (resting) order from real exchange state
|
|
30883
|
+
* (`commitActivateScheduled` / `commitCancelScheduled`). See {@link IBroker.onSignalSchedulePing}
|
|
30884
|
+
* for full guidance and example.
|
|
30885
|
+
*
|
|
30886
|
+
* @param payload - Schedule ping details: symbol, signalId, position, prices, context, backtest
|
|
29662
30887
|
*/
|
|
29663
|
-
|
|
30888
|
+
onSignalSchedulePing(payload: BrokerSchedulePingPayload): Promise<void>;
|
|
29664
30889
|
/**
|
|
29665
|
-
* Called
|
|
30890
|
+
* Called on every live tick while the strategy is idle (no pending or scheduled signal).
|
|
30891
|
+
*
|
|
30892
|
+
* Purely informational. Override to track idle heartbeats. The default logs.
|
|
30893
|
+
*
|
|
30894
|
+
* @param payload - Idle ping details: symbol, currentPrice, context, backtest
|
|
30895
|
+
*/
|
|
30896
|
+
onSignalIdlePing(payload: BrokerIdlePingPayload): Promise<void>;
|
|
30897
|
+
/**
|
|
30898
|
+
* Called when a new scheduled signal is created and starts waiting for priceOpen activation.
|
|
30899
|
+
*
|
|
30900
|
+
* The scheduled -> active transition is reported via `onSignalOpenCommit`, not here. Override to
|
|
30901
|
+
* place a resting/limit order on the exchange. The default logs.
|
|
30902
|
+
*
|
|
30903
|
+
* Manual wiring — EVENT-BASED: fires ONCE at creation — place the real resting order (tag it with
|
|
30904
|
+
* `payload.signalId`) and optionally `commitActivateScheduled` / `commitCancelScheduled`. See
|
|
30905
|
+
* {@link IBroker.onSignalScheduleOpen} for full guidance and example.
|
|
30906
|
+
*
|
|
30907
|
+
* @param payload - Scheduled open details: symbol, signalId, position, prices, context, backtest
|
|
30908
|
+
*/
|
|
30909
|
+
onSignalScheduleOpen(payload: BrokerScheduleOpenPayload): Promise<void>;
|
|
30910
|
+
/**
|
|
30911
|
+
* Called when a scheduled signal is cancelled before activation (timeout / price_reject / user).
|
|
30912
|
+
*
|
|
30913
|
+
* Override to cancel the resting/limit order on the exchange. The default logs.
|
|
30914
|
+
*
|
|
30915
|
+
* Manual wiring — EVENT-BASED (outbound): the strategy already dropped the scheduled signal — cancel the matching
|
|
30916
|
+
* exchange order by `payload.signalId`. See {@link IBroker.onSignalScheduleCancelled}.
|
|
30917
|
+
*
|
|
30918
|
+
* @param payload - Scheduled cancel details: symbol, signalId, position, prices, reason, context, backtest
|
|
30919
|
+
*/
|
|
30920
|
+
onSignalScheduleCancelled(payload: BrokerScheduleCancelledPayload): Promise<void>;
|
|
30921
|
+
/**
|
|
30922
|
+
* Called when a pending position is opened (new signal / immediate / scheduled or user activation).
|
|
30923
|
+
*
|
|
30924
|
+
* Informational lifecycle hook. Override to mirror the open into your own systems. The default logs.
|
|
30925
|
+
*
|
|
30926
|
+
* Manual wiring — EVENT-BASED: fires ONCE at open — place entry + protective TP/SL orders (tag with
|
|
30927
|
+
* `payload.signalId`), then drive per-tick from `onSignalActivePing`. See
|
|
30928
|
+
* {@link IBroker.onSignalPendingOpen}.
|
|
30929
|
+
*
|
|
30930
|
+
* @param payload - Pending open details: symbol, signalId, position, prices, context, backtest
|
|
30931
|
+
*/
|
|
30932
|
+
onSignalPendingOpen(payload: BrokerPendingOpenPayload): Promise<void>;
|
|
30933
|
+
/**
|
|
30934
|
+
* Called when a pending position is closed (take_profit / stop_loss / time_expired / closed).
|
|
30935
|
+
*
|
|
30936
|
+
* Informational lifecycle hook. Override to mirror the close into your own systems. The default logs.
|
|
30937
|
+
*
|
|
30938
|
+
* Manual wiring — EVENT-BASED (outbound): the strategy already removed the pending signal — flatten the real
|
|
30939
|
+
* position and cancel leftover TP/SL orders by `payload.signalId`. See
|
|
30940
|
+
* {@link IBroker.onSignalPendingClose}.
|
|
30941
|
+
*
|
|
30942
|
+
* @param payload - Pending close details: symbol, signalId, position, prices, closeReason, context, backtest
|
|
30943
|
+
*/
|
|
30944
|
+
onSignalPendingClose(payload: BrokerPendingClosePayload): Promise<void>;
|
|
30945
|
+
/**
|
|
30946
|
+
* Called when a position is being closed (SL/TP hit or manual close).
|
|
29666
30947
|
*
|
|
29667
30948
|
* Triggered automatically via syncSubject when a pending signal is closed.
|
|
29668
30949
|
* Use to place the exit order and record final PnL.
|
|
29669
30950
|
*
|
|
29670
30951
|
* Default implementation: Logs signal-close event.
|
|
29671
30952
|
*
|
|
30953
|
+
* Manual wiring — EXCEPTION-BASED GATE: emitted BEFORE the framework mutates state, so a THROW here
|
|
30954
|
+
* (e.g. exit order failed) SKIPS the close — the position stays open and the close retries next
|
|
30955
|
+
* tick; return normally to let it close. Live-only (backtest short-circuits). See
|
|
30956
|
+
* {@link IBroker.onSignalCloseCommit} for the full semantics.
|
|
30957
|
+
*
|
|
29672
30958
|
* @param payload - Signal close details: symbol, cost, position, currentPrice, pnl, totalEntries, totalPartials, context, backtest
|
|
29673
30959
|
*
|
|
29674
30960
|
* @example
|
|
29675
30961
|
* ```typescript
|
|
29676
30962
|
* async onSignalCloseCommit(payload: BrokerSignalClosePayload) {
|
|
29677
30963
|
* super.onSignalCloseCommit(payload); // Keep parent logging
|
|
29678
|
-
* await this.exchange.closePosition(payload.symbol);
|
|
30964
|
+
* const ok = await this.exchange.closePosition(payload.symbol);
|
|
30965
|
+
* if (!ok) {
|
|
30966
|
+
* throw new Error(`Exit not filled for ${payload.symbol}`); // -> keep position open, retry next tick
|
|
30967
|
+
* }
|
|
29679
30968
|
* await this.db.recordTrade({ symbol: payload.symbol, pnl: payload.pnl });
|
|
29680
30969
|
* }
|
|
29681
30970
|
* ```
|
|
@@ -29993,6 +31282,22 @@ declare const riskSubject: Subject<RiskContract>;
|
|
|
29993
31282
|
* Allows users to track scheduled signal lifecycle and implement custom cancellation logic.
|
|
29994
31283
|
*/
|
|
29995
31284
|
declare const schedulePingSubject: Subject<SchedulePingContract>;
|
|
31285
|
+
/**
|
|
31286
|
+
* Scheduled signal lifecycle emitter (creation and cancellation).
|
|
31287
|
+
* Emits when a scheduled signal is created (action "scheduled") or cancelled before
|
|
31288
|
+
* activation (action "cancelled": timeout / price_reject / user) during tick()/backtest().
|
|
31289
|
+
*
|
|
31290
|
+
* The scheduled -> active transition (activation) is intentionally NOT emitted here — that
|
|
31291
|
+
* produces an "opened" signal on the regular signal emitters instead.
|
|
31292
|
+
*/
|
|
31293
|
+
declare const scheduleEventSubject: Subject<ScheduleEventContract>;
|
|
31294
|
+
/**
|
|
31295
|
+
* Pending signal lifecycle emitter (open and close).
|
|
31296
|
+
* Emits when a pending position is opened (action "opened": new signal / immediate / scheduled
|
|
31297
|
+
* or user activation) or closed (action "closed" with closeReason take_profit / stop_loss /
|
|
31298
|
+
* time_expired / closed) during tick()/backtest().
|
|
31299
|
+
*/
|
|
31300
|
+
declare const signalEventSubject: Subject<SignalEventContract>;
|
|
29996
31301
|
/**
|
|
29997
31302
|
* Active ping emitter for active pending signal monitoring events.
|
|
29998
31303
|
* Emits every minute when an active pending signal is being monitored.
|
|
@@ -30081,10 +31386,12 @@ declare const emitters_performanceEmitter: typeof performanceEmitter;
|
|
|
30081
31386
|
declare const emitters_progressBacktestEmitter: typeof progressBacktestEmitter;
|
|
30082
31387
|
declare const emitters_progressWalkerEmitter: typeof progressWalkerEmitter;
|
|
30083
31388
|
declare const emitters_riskSubject: typeof riskSubject;
|
|
31389
|
+
declare const emitters_scheduleEventSubject: typeof scheduleEventSubject;
|
|
30084
31390
|
declare const emitters_schedulePingSubject: typeof schedulePingSubject;
|
|
30085
31391
|
declare const emitters_shutdownEmitter: typeof shutdownEmitter;
|
|
30086
31392
|
declare const emitters_signalBacktestEmitter: typeof signalBacktestEmitter;
|
|
30087
31393
|
declare const emitters_signalEmitter: typeof signalEmitter;
|
|
31394
|
+
declare const emitters_signalEventSubject: typeof signalEventSubject;
|
|
30088
31395
|
declare const emitters_signalLiveEmitter: typeof signalLiveEmitter;
|
|
30089
31396
|
declare const emitters_signalNotifySubject: typeof signalNotifySubject;
|
|
30090
31397
|
declare const emitters_strategyCommitSubject: typeof strategyCommitSubject;
|
|
@@ -30095,7 +31402,7 @@ declare const emitters_walkerCompleteSubject: typeof walkerCompleteSubject;
|
|
|
30095
31402
|
declare const emitters_walkerEmitter: typeof walkerEmitter;
|
|
30096
31403
|
declare const emitters_walkerStopSubject: typeof walkerStopSubject;
|
|
30097
31404
|
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 };
|
|
31405
|
+
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
31406
|
}
|
|
30100
31407
|
|
|
30101
31408
|
/**
|
|
@@ -31228,6 +32535,38 @@ declare class ActionCoreService implements TAction$1 {
|
|
|
31228
32535
|
exchangeName: ExchangeName;
|
|
31229
32536
|
frameName: FrameName;
|
|
31230
32537
|
}) => Promise<void>;
|
|
32538
|
+
/**
|
|
32539
|
+
* Routes a scheduled signal lifecycle event (creation / cancellation) to all registered actions.
|
|
32540
|
+
*
|
|
32541
|
+
* Retrieves action list from strategy schema (IStrategySchema.actions) and invokes the
|
|
32542
|
+
* scheduleEvent handler on each ClientAction instance sequentially. Called once on creation
|
|
32543
|
+
* (action "scheduled") and once on cancellation before activation (action "cancelled").
|
|
32544
|
+
*
|
|
32545
|
+
* @param backtest - Whether running in backtest mode (true) or live mode (false)
|
|
32546
|
+
* @param event - Scheduled lifecycle event data (action discriminates created vs cancelled)
|
|
32547
|
+
* @param context - Strategy execution context with strategyName, exchangeName, frameName
|
|
32548
|
+
*/
|
|
32549
|
+
scheduleEvent: (backtest: boolean, event: ScheduleEventContract, context: {
|
|
32550
|
+
strategyName: StrategyName;
|
|
32551
|
+
exchangeName: ExchangeName;
|
|
32552
|
+
frameName: FrameName;
|
|
32553
|
+
}) => Promise<void>;
|
|
32554
|
+
/**
|
|
32555
|
+
* Routes a pending signal lifecycle event (open / close) to all registered actions.
|
|
32556
|
+
*
|
|
32557
|
+
* Retrieves action list from strategy schema (IStrategySchema.actions) and invokes the
|
|
32558
|
+
* pendingEvent handler on each ClientAction instance sequentially. Called once on open
|
|
32559
|
+
* (action "opened") and once on close (action "closed").
|
|
32560
|
+
*
|
|
32561
|
+
* @param backtest - Whether running in backtest mode (true) or live mode (false)
|
|
32562
|
+
* @param event - Pending lifecycle event data (action discriminates opened vs closed)
|
|
32563
|
+
* @param context - Strategy execution context with strategyName, exchangeName, frameName
|
|
32564
|
+
*/
|
|
32565
|
+
pendingEvent: (backtest: boolean, event: SignalEventContract, context: {
|
|
32566
|
+
strategyName: StrategyName;
|
|
32567
|
+
exchangeName: ExchangeName;
|
|
32568
|
+
frameName: FrameName;
|
|
32569
|
+
}) => Promise<void>;
|
|
31231
32570
|
/**
|
|
31232
32571
|
* Routes active ping event to all registered actions for the strategy.
|
|
31233
32572
|
*
|
|
@@ -31298,7 +32637,7 @@ declare class ActionCoreService implements TAction$1 {
|
|
|
31298
32637
|
* @param event - Pending-ping event with action "signal-ping"
|
|
31299
32638
|
* @param context - Strategy execution context
|
|
31300
32639
|
*/
|
|
31301
|
-
|
|
32640
|
+
orderCheck: (backtest: boolean, event: SignalPingContract, context: {
|
|
31302
32641
|
strategyName: StrategyName;
|
|
31303
32642
|
exchangeName: ExchangeName;
|
|
31304
32643
|
frameName: FrameName;
|
|
@@ -32707,6 +34046,42 @@ declare class StrategyConnectionService implements TStrategy$1 {
|
|
|
32707
34046
|
exchangeName: ExchangeName;
|
|
32708
34047
|
frameName: FrameName;
|
|
32709
34048
|
}) => Promise<void>;
|
|
34049
|
+
/**
|
|
34050
|
+
* Reports that the pending position's take-profit order was actually filled on the exchange
|
|
34051
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based TP check.
|
|
34052
|
+
*
|
|
34053
|
+
* Delegates to ClientStrategy.createTakeProfit(). The close is deferred and emitted with
|
|
34054
|
+
* closeReason "take_profit" on the next tick()/backtest(). Works out of the execution context.
|
|
34055
|
+
*
|
|
34056
|
+
* @param backtest - Whether running in backtest mode
|
|
34057
|
+
* @param symbol - Trading pair symbol
|
|
34058
|
+
* @param context - Context with strategyName, exchangeName, frameName
|
|
34059
|
+
* @param payload - Optional commit payload with id and note
|
|
34060
|
+
* @returns Promise that resolves when the take-profit fill is queued
|
|
34061
|
+
*/
|
|
34062
|
+
createTakeProfit: (backtest: boolean, symbol: string, context: {
|
|
34063
|
+
strategyName: StrategyName;
|
|
34064
|
+
exchangeName: ExchangeName;
|
|
34065
|
+
frameName: FrameName;
|
|
34066
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
34067
|
+
/**
|
|
34068
|
+
* Reports that the pending position's stop-loss order was actually filled on the exchange
|
|
34069
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based SL check.
|
|
34070
|
+
*
|
|
34071
|
+
* Delegates to ClientStrategy.createStopLoss(). The close is deferred and emitted with
|
|
34072
|
+
* closeReason "stop_loss" on the next tick()/backtest(). Works out of the execution context.
|
|
34073
|
+
*
|
|
34074
|
+
* @param backtest - Whether running in backtest mode
|
|
34075
|
+
* @param symbol - Trading pair symbol
|
|
34076
|
+
* @param context - Context with strategyName, exchangeName, frameName
|
|
34077
|
+
* @param payload - Optional commit payload with id and note
|
|
34078
|
+
* @returns Promise that resolves when the stop-loss fill is queued
|
|
34079
|
+
*/
|
|
34080
|
+
createStopLoss: (backtest: boolean, symbol: string, context: {
|
|
34081
|
+
strategyName: StrategyName;
|
|
34082
|
+
exchangeName: ExchangeName;
|
|
34083
|
+
frameName: FrameName;
|
|
34084
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
32710
34085
|
/**
|
|
32711
34086
|
* Returns the in-memory deferred strategy-state snapshot for this iteration.
|
|
32712
34087
|
*
|
|
@@ -33328,6 +34703,27 @@ declare class ActionProxy implements IPublicAction {
|
|
|
33328
34703
|
* @returns Promise resolving to user's pingScheduled() result or null on error
|
|
33329
34704
|
*/
|
|
33330
34705
|
pingScheduled(event: SchedulePingContract): Promise<any>;
|
|
34706
|
+
/**
|
|
34707
|
+
* Handles scheduled signal lifecycle events with error capture.
|
|
34708
|
+
*
|
|
34709
|
+
* Wraps the user's scheduleEvent() method to catch and log any errors. Called once when a
|
|
34710
|
+
* scheduled signal is created (action "scheduled") and once when it is cancelled before
|
|
34711
|
+
* activation (action "cancelled").
|
|
34712
|
+
*
|
|
34713
|
+
* @param event - Scheduled lifecycle data (action discriminates created vs cancelled)
|
|
34714
|
+
* @returns Promise resolving to user's scheduleEvent() result or null on error
|
|
34715
|
+
*/
|
|
34716
|
+
scheduleEvent(event: ScheduleEventContract): Promise<any>;
|
|
34717
|
+
/**
|
|
34718
|
+
* Handles pending signal lifecycle events with error capture.
|
|
34719
|
+
*
|
|
34720
|
+
* Wraps the user's pendingEvent() method to catch and log any errors. Called once when a
|
|
34721
|
+
* pending position is opened (action "opened") and once when it is closed (action "closed").
|
|
34722
|
+
*
|
|
34723
|
+
* @param event - Pending lifecycle data (action discriminates opened vs closed)
|
|
34724
|
+
* @returns Promise resolving to user's pendingEvent() result or null on error
|
|
34725
|
+
*/
|
|
34726
|
+
pendingEvent(event: SignalEventContract): Promise<any>;
|
|
33331
34727
|
/**
|
|
33332
34728
|
* Handles active ping events with error capture.
|
|
33333
34729
|
*
|
|
@@ -33371,7 +34767,7 @@ declare class ActionProxy implements IPublicAction {
|
|
|
33371
34767
|
*
|
|
33372
34768
|
* @param event - Pending-ping event with action "signal-ping"
|
|
33373
34769
|
*/
|
|
33374
|
-
|
|
34770
|
+
orderCheck(event: SignalPingContract): Promise<void>;
|
|
33375
34771
|
/**
|
|
33376
34772
|
* Cleans up resources with error capture.
|
|
33377
34773
|
*
|
|
@@ -33506,6 +34902,22 @@ declare class ClientAction implements IAction {
|
|
|
33506
34902
|
* Handles scheduled ping events during scheduled signal monitoring.
|
|
33507
34903
|
*/
|
|
33508
34904
|
pingScheduled(event: SchedulePingContract): Promise<void>;
|
|
34905
|
+
/**
|
|
34906
|
+
* Handles scheduled signal lifecycle events (creation / cancellation).
|
|
34907
|
+
*
|
|
34908
|
+
* Manual wiring — EVENT-BASED: users implement {@link IActionCallbacks.onScheduleEvent} (via `addActionSchema`)
|
|
34909
|
+
* to drive the exchange (`commitActivateScheduled` / `commitCancelScheduled`); see that contract
|
|
34910
|
+
* for the full guidance and example. This internal dispatch forwards to the handler/callback.
|
|
34911
|
+
*/
|
|
34912
|
+
scheduleEvent(event: ScheduleEventContract): Promise<void>;
|
|
34913
|
+
/**
|
|
34914
|
+
* Handles pending signal lifecycle events (open / close).
|
|
34915
|
+
*
|
|
34916
|
+
* Manual wiring — EVENT-BASED: users implement {@link IActionCallbacks.onPendingEvent} (via `addActionSchema`) to
|
|
34917
|
+
* drive the exchange; for per-tick fills use `onPingActive`. See that contract for the full
|
|
34918
|
+
* guidance and example. This internal dispatch forwards to the handler/callback.
|
|
34919
|
+
*/
|
|
34920
|
+
pendingEvent(event: SignalEventContract): Promise<void>;
|
|
33509
34921
|
/**
|
|
33510
34922
|
* Handles active ping events during active pending signal monitoring.
|
|
33511
34923
|
*/
|
|
@@ -33527,7 +34939,7 @@ declare class ClientAction implements IAction {
|
|
|
33527
34939
|
* Gate for the pending-order ping (order still open on exchange?).
|
|
33528
34940
|
* NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_PENDING_FN.
|
|
33529
34941
|
*/
|
|
33530
|
-
|
|
34942
|
+
orderCheck(event: SignalPingContract): Promise<void>;
|
|
33531
34943
|
/**
|
|
33532
34944
|
* Cleans up resources and subscriptions when action handler is no longer needed.
|
|
33533
34945
|
* Uses singleshot pattern to ensure cleanup happens exactly once.
|
|
@@ -33693,6 +35105,32 @@ declare class ActionConnectionService implements TAction {
|
|
|
33693
35105
|
exchangeName: ExchangeName;
|
|
33694
35106
|
frameName: FrameName;
|
|
33695
35107
|
}) => Promise<void>;
|
|
35108
|
+
/**
|
|
35109
|
+
* Routes a scheduled signal lifecycle event (creation / cancellation) to the ClientAction instance.
|
|
35110
|
+
*
|
|
35111
|
+
* @param event - Scheduled lifecycle event data (action discriminates created vs cancelled)
|
|
35112
|
+
* @param backtest - Whether running in backtest mode
|
|
35113
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
35114
|
+
*/
|
|
35115
|
+
scheduleEvent: (event: ScheduleEventContract, backtest: boolean, context: {
|
|
35116
|
+
actionName: ActionName;
|
|
35117
|
+
strategyName: StrategyName;
|
|
35118
|
+
exchangeName: ExchangeName;
|
|
35119
|
+
frameName: FrameName;
|
|
35120
|
+
}) => Promise<void>;
|
|
35121
|
+
/**
|
|
35122
|
+
* Routes a pending signal lifecycle event (open / close) to the ClientAction instance.
|
|
35123
|
+
*
|
|
35124
|
+
* @param event - Pending lifecycle event data (action discriminates opened vs closed)
|
|
35125
|
+
* @param backtest - Whether running in backtest mode
|
|
35126
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
35127
|
+
*/
|
|
35128
|
+
pendingEvent: (event: SignalEventContract, backtest: boolean, context: {
|
|
35129
|
+
actionName: ActionName;
|
|
35130
|
+
strategyName: StrategyName;
|
|
35131
|
+
exchangeName: ExchangeName;
|
|
35132
|
+
frameName: FrameName;
|
|
35133
|
+
}) => Promise<void>;
|
|
33696
35134
|
/**
|
|
33697
35135
|
* Routes active ping event to appropriate ClientAction instance.
|
|
33698
35136
|
*
|
|
@@ -33748,14 +35186,14 @@ declare class ActionConnectionService implements TAction {
|
|
|
33748
35186
|
frameName: FrameName;
|
|
33749
35187
|
}) => Promise<void>;
|
|
33750
35188
|
/**
|
|
33751
|
-
* Routes
|
|
35189
|
+
* Routes orderCheck event to appropriate ClientAction instance.
|
|
33752
35190
|
* NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_PENDING_FN.
|
|
33753
35191
|
*
|
|
33754
35192
|
* @param event - Pending-ping event with action "signal-ping"
|
|
33755
35193
|
* @param backtest - Whether running in backtest mode
|
|
33756
35194
|
* @param context - Execution context
|
|
33757
35195
|
*/
|
|
33758
|
-
|
|
35196
|
+
orderCheck: (event: SignalPingContract, backtest: boolean, context: {
|
|
33759
35197
|
actionName: ActionName;
|
|
33760
35198
|
strategyName: StrategyName;
|
|
33761
35199
|
exchangeName: ExchangeName;
|
|
@@ -34344,6 +35782,44 @@ declare class StrategyCoreService implements TStrategy {
|
|
|
34344
35782
|
exchangeName: ExchangeName;
|
|
34345
35783
|
frameName: FrameName;
|
|
34346
35784
|
}) => Promise<void>;
|
|
35785
|
+
/**
|
|
35786
|
+
* Reports that the pending position's take-profit order was actually filled on the exchange
|
|
35787
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based TP check.
|
|
35788
|
+
*
|
|
35789
|
+
* Validates the context, then delegates to StrategyConnectionService.createTakeProfit().
|
|
35790
|
+
* The close is deferred and emitted with closeReason "take_profit" on the next tick/backtest.
|
|
35791
|
+
* Does not require execution context.
|
|
35792
|
+
*
|
|
35793
|
+
* @param backtest - Whether running in backtest mode
|
|
35794
|
+
* @param symbol - Trading pair symbol
|
|
35795
|
+
* @param context - Context with strategyName, exchangeName, frameName
|
|
35796
|
+
* @param payload - Optional commit payload with id and note
|
|
35797
|
+
* @returns Promise that resolves when the take-profit fill is queued
|
|
35798
|
+
*/
|
|
35799
|
+
createTakeProfit: (backtest: boolean, symbol: string, context: {
|
|
35800
|
+
strategyName: StrategyName;
|
|
35801
|
+
exchangeName: ExchangeName;
|
|
35802
|
+
frameName: FrameName;
|
|
35803
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
35804
|
+
/**
|
|
35805
|
+
* Reports that the pending position's stop-loss order was actually filled on the exchange
|
|
35806
|
+
* (e.g. by candle high/low), forcing a close that bypasses the VWAP-based SL check.
|
|
35807
|
+
*
|
|
35808
|
+
* Validates the context, then delegates to StrategyConnectionService.createStopLoss().
|
|
35809
|
+
* The close is deferred and emitted with closeReason "stop_loss" on the next tick/backtest.
|
|
35810
|
+
* Does not require execution context.
|
|
35811
|
+
*
|
|
35812
|
+
* @param backtest - Whether running in backtest mode
|
|
35813
|
+
* @param symbol - Trading pair symbol
|
|
35814
|
+
* @param context - Context with strategyName, exchangeName, frameName
|
|
35815
|
+
* @param payload - Optional commit payload with id and note
|
|
35816
|
+
* @returns Promise that resolves when the stop-loss fill is queued
|
|
35817
|
+
*/
|
|
35818
|
+
createStopLoss: (backtest: boolean, symbol: string, context: {
|
|
35819
|
+
strategyName: StrategyName;
|
|
35820
|
+
exchangeName: ExchangeName;
|
|
35821
|
+
frameName: FrameName;
|
|
35822
|
+
}, payload?: Partial<CommitPayload>) => Promise<void>;
|
|
34347
35823
|
/**
|
|
34348
35824
|
* Returns the in-memory deferred strategy-state snapshot for this iteration.
|
|
34349
35825
|
*
|
|
@@ -38100,4 +39576,4 @@ declare const getTotalClosed: (signal: Signal) => {
|
|
|
38100
39576
|
*/
|
|
38101
39577
|
declare const getPriceScale: (value: number) => number;
|
|
38102
39578
|
|
|
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 };
|
|
39579
|
+
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 BrokerPartialLossPayload, type BrokerPartialProfitPayload, type BrokerPendingClosePayload, type BrokerPendingOpenPayload, type BrokerScheduleCancelledPayload, type BrokerScheduleOpenPayload, type BrokerSchedulePingPayload, 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 ScheduleEventContract, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, Session, SessionBacktest, type SessionData, SessionLive, type SignalCancelledNotification, type SignalCloseContract, type SignalClosedNotification, type SignalData, type SignalEventContract, 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, 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, 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, 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 };
|