@lumencharts/trading-platform 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +55 -0
  3. package/README.md +53 -2
  4. package/dist/asset-entry.d.ts +3 -0
  5. package/dist/asset.d.ts +3 -0
  6. package/dist/asset.js +21689 -0
  7. package/dist/chart/bracket-links.d.ts +8 -0
  8. package/dist/chart/context-actions.d.ts +7 -0
  9. package/dist/chart/edit-presentation.d.ts +32 -0
  10. package/dist/chart/edit-preview.d.ts +26 -0
  11. package/dist/chart/exit-profit.d.ts +32 -0
  12. package/dist/chart/frame-batch.d.ts +15 -0
  13. package/dist/chart/overlay-coordinator.d.ts +18 -0
  14. package/dist/chart/overlay-events.d.ts +3 -0
  15. package/dist/chart/overlay-gesture.d.ts +40 -0
  16. package/dist/chart/overlay-index.d.ts +30 -0
  17. package/dist/chart/overlay-projection.d.ts +51 -0
  18. package/dist/chart/overlay-types.d.ts +42 -0
  19. package/dist/chart/parent-links.d.ts +33 -0
  20. package/dist/chart/position-profit.d.ts +15 -0
  21. package/dist/chart/review-lock.d.ts +14 -0
  22. package/dist/chart/ticket-projection.d.ts +36 -0
  23. package/dist/compat/default-formatters.d.ts +6 -0
  24. package/dist/compat/delegate.d.ts +11 -0
  25. package/dist/compat/factory.d.ts +5 -0
  26. package/dist/compat/formatters.d.ts +26 -0
  27. package/dist/compat/host-dialogs.d.ts +5 -0
  28. package/dist/compat/host-preferences.d.ts +8 -0
  29. package/dist/compat/host.d.ts +39 -0
  30. package/dist/compat/watched-value.d.ts +25 -0
  31. package/dist/conformance/index.d.ts +78 -0
  32. package/dist/conformance/index.js +6859 -0
  33. package/dist/conformance/replay.d.ts +35 -0
  34. package/dist/contracts/broker.d.ts +1122 -0
  35. package/dist/contracts/broker.js +168 -0
  36. package/dist/contracts/index.d.ts +3 -0
  37. package/dist/contracts/index.js +168 -0
  38. package/dist/contracts/market-data.d.ts +289 -0
  39. package/dist/contracts/market-data.js +11 -0
  40. package/dist/contracts/ports.d.ts +469 -0
  41. package/dist/contracts/ports.js +5 -0
  42. package/dist/core/account-datasets.d.ts +29 -0
  43. package/dist/core/account-lifecycle.d.ts +70 -0
  44. package/dist/core/account-types.d.ts +6 -0
  45. package/dist/core/bounded-map.d.ts +12 -0
  46. package/dist/core/bracket-input.d.ts +32 -0
  47. package/dist/core/bracket-modification.d.ts +6 -0
  48. package/dist/core/bracket-parent.d.ts +11 -0
  49. package/dist/core/broker-debug.d.ts +10 -0
  50. package/dist/core/capabilities.d.ts +34 -0
  51. package/dist/core/capability-metadata.d.ts +60 -0
  52. package/dist/core/capability-policy.d.ts +32 -0
  53. package/dist/core/chart-exit-level.d.ts +11 -0
  54. package/dist/core/chart-order-edit.d.ts +50 -0
  55. package/dist/core/clock.d.ts +2 -0
  56. package/dist/core/close-commands.d.ts +24 -0
  57. package/dist/core/close-flow.d.ts +14 -0
  58. package/dist/core/command-context.d.ts +16 -0
  59. package/dist/core/command-coordinator.d.ts +71 -0
  60. package/dist/core/command-follow.d.ts +32 -0
  61. package/dist/core/command-keys.d.ts +11 -0
  62. package/dist/core/context-orders.d.ts +19 -0
  63. package/dist/core/deferred.d.ts +5 -0
  64. package/dist/core/dialog-coordinator.d.ts +73 -0
  65. package/dist/core/display-preferences.d.ts +10 -0
  66. package/dist/core/disposal.d.ts +8 -0
  67. package/dist/core/entity-store.d.ts +56 -0
  68. package/dist/core/entity-validation.d.ts +9 -0
  69. package/dist/core/errors.d.ts +24 -0
  70. package/dist/core/execution-demand.d.ts +11 -0
  71. package/dist/core/execution-sound.d.ts +10 -0
  72. package/dist/core/exit-level-draft.d.ts +9 -0
  73. package/dist/core/exit-level-summary.d.ts +3 -0
  74. package/dist/core/exit-level-template.d.ts +16 -0
  75. package/dist/core/features.d.ts +39 -0
  76. package/dist/core/financial-rules.d.ts +70 -0
  77. package/dist/core/history-limit.d.ts +11 -0
  78. package/dist/core/identity.d.ts +14 -0
  79. package/dist/core/immutable.d.ts +8 -0
  80. package/dist/core/keyed-ref-count.d.ts +18 -0
  81. package/dist/core/leverage-commands.d.ts +42 -0
  82. package/dist/core/modification-context.d.ts +22 -0
  83. package/dist/core/modification-routing.d.ts +43 -0
  84. package/dist/core/notification-log.d.ts +33 -0
  85. package/dist/core/number-precision.d.ts +4 -0
  86. package/dist/core/order-commands.d.ts +50 -0
  87. package/dist/core/order-duration.d.ts +14 -0
  88. package/dist/core/order-labels.d.ts +7 -0
  89. package/dist/core/order-matching.d.ts +16 -0
  90. package/dist/core/order-modification.d.ts +20 -0
  91. package/dist/core/order-notifications.d.ts +30 -0
  92. package/dist/core/order-protection.d.ts +4 -0
  93. package/dist/core/parent-protection.d.ts +10 -0
  94. package/dist/core/position-commands.d.ts +45 -0
  95. package/dist/core/position-custom-fields.d.ts +5 -0
  96. package/dist/core/position-estimates.d.ts +22 -0
  97. package/dist/core/position-protection-permissions.d.ts +4 -0
  98. package/dist/core/preferences-key.d.ts +2 -0
  99. package/dist/core/preview-leases.d.ts +12 -0
  100. package/dist/core/protection-legs.d.ts +23 -0
  101. package/dist/core/protection-notifications.d.ts +9 -0
  102. package/dist/core/protection-rules.d.ts +21 -0
  103. package/dist/core/quantity-input.d.ts +53 -0
  104. package/dist/core/read-coordinator.d.ts +15 -0
  105. package/dist/core/readers.d.ts +6 -0
  106. package/dist/core/relative-price.d.ts +4 -0
  107. package/dist/core/review-policy.d.ts +17 -0
  108. package/dist/core/session-types.d.ts +1 -0
  109. package/dist/core/session.d.ts +114 -0
  110. package/dist/core/snapshot-dataset.d.ts +47 -0
  111. package/dist/core/symbol-catalog.d.ts +37 -0
  112. package/dist/core/tradability.d.ts +26 -0
  113. package/dist/core/trading-commands.d.ts +104 -0
  114. package/dist/core/trading-rules.d.ts +14 -0
  115. package/dist/core/trading-settings.d.ts +39 -0
  116. package/dist/core/trading-state.d.ts +52 -0
  117. package/dist/core/value-store.d.ts +11 -0
  118. package/dist/index.d.ts +15 -0
  119. package/dist/index.js +6593 -0
  120. package/dist/market-data/depth-book.d.ts +18 -0
  121. package/dist/market-data/index.d.ts +3 -0
  122. package/dist/market-data/index.js +735 -0
  123. package/dist/market-data/session-demand.d.ts +15 -0
  124. package/dist/market-data/subscriptions.d.ts +13 -0
  125. package/dist/mock/broker.d.ts +75 -0
  126. package/dist/mock/clock.d.ts +12 -0
  127. package/dist/mock/feeds.d.ts +18 -0
  128. package/dist/mock/index.d.ts +5 -0
  129. package/dist/mock/index.js +1956 -0
  130. package/dist/mock/protection-cancellation.d.ts +7 -0
  131. package/dist/mock/scenarios.d.ts +5 -0
  132. package/dist/paper/broker.d.ts +41 -0
  133. package/dist/paper/index.d.ts +6 -0
  134. package/dist/paper/index.js +469 -0
  135. package/dist/paper/market.d.ts +57 -0
  136. package/dist/paper/rules.d.ts +40 -0
  137. package/dist/ui/account-manager/account-pages.d.ts +18 -0
  138. package/dist/ui/account-manager/column-presentation.d.ts +5 -0
  139. package/dist/ui/account-manager/context-menu.d.ts +13 -0
  140. package/dist/ui/account-manager/csv-downloads.d.ts +5 -0
  141. package/dist/ui/account-manager/custom-page.d.ts +16 -0
  142. package/dist/ui/account-manager/custom-table.d.ts +18 -0
  143. package/dist/ui/account-manager/format-account-value.d.ts +12 -0
  144. package/dist/ui/account-manager/position-reader.d.ts +19 -0
  145. package/dist/ui/account-manager/row-action-tracker.d.ts +12 -0
  146. package/dist/ui/account-manager/row-actions.d.ts +37 -0
  147. package/dist/ui/account-manager/status-counts.d.ts +6 -0
  148. package/dist/ui/account-manager/table-controls.d.ts +13 -0
  149. package/dist/ui/account-manager/table-export.d.ts +30 -0
  150. package/dist/ui/account-manager/table-model.d.ts +11 -0
  151. package/dist/ui/account-manager/table-toolbar.d.ts +25 -0
  152. package/dist/ui/account-manager/table.d.ts +24 -0
  153. package/dist/ui/account-manager/view.d.ts +19 -0
  154. package/dist/ui/account-manager/workspace.d.ts +15 -0
  155. package/dist/ui/chart-actions.d.ts +11 -0
  156. package/dist/ui/chart-controls/eligibility.d.ts +6 -0
  157. package/dist/ui/chart-controls/quote-buttons.d.ts +15 -0
  158. package/dist/ui/chart-controls/quote-controls.d.ts +12 -0
  159. package/dist/ui/chart-controls/quote-widths.d.ts +8 -0
  160. package/dist/ui/dialogs/close-amount-form.d.ts +8 -0
  161. package/dist/ui/dialogs/close-preview-dialog.d.ts +5 -0
  162. package/dist/ui/dialogs/confirm-dialog.d.ts +7 -0
  163. package/dist/ui/dialogs/dialog-body.d.ts +11 -0
  164. package/dist/ui/dialogs/leverage-form.d.ts +10 -0
  165. package/dist/ui/dialogs/message-dialog.d.ts +6 -0
  166. package/dist/ui/dialogs/position-protection.d.ts +14 -0
  167. package/dist/ui/dialogs/properties-dialog.d.ts +9 -0
  168. package/dist/ui/dialogs/sanitize-html.d.ts +2 -0
  169. package/dist/ui/dialogs/types.d.ts +5 -0
  170. package/dist/ui/dialogs/view.d.ts +5 -0
  171. package/dist/ui/dock-sizes.d.ts +20 -0
  172. package/dist/ui/dom/controller.d.ts +34 -0
  173. package/dist/ui/dom/ladder.d.ts +23 -0
  174. package/dist/ui/dom/view.d.ts +8 -0
  175. package/dist/ui/dom/workspace.d.ts +17 -0
  176. package/dist/ui/effective-mode.d.ts +11 -0
  177. package/dist/ui/financial-lease.d.ts +3 -0
  178. package/dist/ui/icons.d.ts +4 -0
  179. package/dist/ui/index.d.ts +9 -0
  180. package/dist/ui/index.js +15918 -0
  181. package/dist/ui/layout.d.ts +5 -0
  182. package/dist/ui/mount.d.ts +11 -0
  183. package/dist/ui/notifications/log.d.ts +6 -0
  184. package/dist/ui/notifications/toasts.d.ts +5 -0
  185. package/dist/ui/number-input.d.ts +2 -0
  186. package/dist/ui/order-ticket/chart-draft-controls.d.ts +8 -0
  187. package/dist/ui/order-ticket/chart-projection.d.ts +9 -0
  188. package/dist/ui/order-ticket/controller.d.ts +41 -0
  189. package/dist/ui/order-ticket/custom-field.d.ts +9 -0
  190. package/dist/ui/order-ticket/duration-input.d.ts +9 -0
  191. package/dist/ui/order-ticket/exit-input.d.ts +34 -0
  192. package/dist/ui/order-ticket/financial-controls.d.ts +10 -0
  193. package/dist/ui/order-ticket/layout-context.d.ts +7 -0
  194. package/dist/ui/order-ticket/market.d.ts +12 -0
  195. package/dist/ui/order-ticket/menu.d.ts +6 -0
  196. package/dist/ui/order-ticket/mode-rules.d.ts +4 -0
  197. package/dist/ui/order-ticket/modification-fields.d.ts +23 -0
  198. package/dist/ui/order-ticket/move-handle.d.ts +4 -0
  199. package/dist/ui/order-ticket/order-sent.d.ts +4 -0
  200. package/dist/ui/order-ticket/placement.d.ts +27 -0
  201. package/dist/ui/order-ticket/preview-message.d.ts +4 -0
  202. package/dist/ui/order-ticket/price-input.d.ts +14 -0
  203. package/dist/ui/order-ticket/quantity-input.d.ts +26 -0
  204. package/dist/ui/order-ticket/review-panel.d.ts +10 -0
  205. package/dist/ui/order-ticket/rules.d.ts +16 -0
  206. package/dist/ui/order-ticket/stop-input.d.ts +17 -0
  207. package/dist/ui/order-ticket/submit-bar.d.ts +13 -0
  208. package/dist/ui/order-ticket/symbol-search-controller.d.ts +50 -0
  209. package/dist/ui/order-ticket/symbol-search.d.ts +12 -0
  210. package/dist/ui/order-ticket/untradable-notice.d.ts +8 -0
  211. package/dist/ui/order-ticket/view.d.ts +16 -0
  212. package/dist/ui/panel-visibility.d.ts +6 -0
  213. package/dist/ui/pointer-drag.d.ts +20 -0
  214. package/dist/ui/popup-mount.d.ts +4 -0
  215. package/dist/ui/primitives.d.ts +29 -0
  216. package/dist/ui/protection/editor.d.ts +18 -0
  217. package/dist/ui/protection/fields.d.ts +30 -0
  218. package/dist/ui/protection/level.d.ts +14 -0
  219. package/dist/ui/protection/protected-size.d.ts +5 -0
  220. package/dist/ui/protection/ticket-workspace.d.ts +7 -0
  221. package/dist/ui/resize-handle.css +34 -0
  222. package/dist/ui/resize-handle.d.ts +20 -0
  223. package/dist/ui/resize-handle.js +185 -0
  224. package/dist/ui/select.d.ts +26 -0
  225. package/dist/ui/surface-theme.d.ts +3 -0
  226. package/dist/ui/switch.d.ts +7 -0
  227. package/dist/ui/symbol-logo.d.ts +7 -0
  228. package/dist/ui/tabs.d.ts +19 -0
  229. package/dist/ui/ticket-dock.d.ts +18 -0
  230. package/dist/ui/ticket-shell.d.ts +15 -0
  231. package/dist/ui/trading.css +1808 -0
  232. package/dist/ui/trap-tab.d.ts +11 -0
  233. package/dist/vendor/solid-ui/index.d.ts +3 -0
  234. package/dist/vendor/solid-ui/paged-list-window.d.ts +27 -0
  235. package/dist/vendor/solid-ui/virtual-list.d.ts +21 -0
  236. package/package.json +104 -3
@@ -0,0 +1,39 @@
1
+ /** Trading-owned defaults from the pinned TradingTerminalFeatureset declarations.
2
+ * Inherited chart features remain owned by the chart resolver.
3
+ */
4
+ export declare const tradingFeatureDefaults: Readonly<{
5
+ readonly chart_crosshair_menu: true;
6
+ readonly open_account_manager: true;
7
+ readonly trading_notifications: true;
8
+ readonly show_trading_notifications_history: true;
9
+ readonly always_pass_called_order_to_modify: false;
10
+ readonly always_require_order_confirmation: false;
11
+ readonly trading_account_manager: true;
12
+ readonly right_toolbar: true;
13
+ readonly order_panel: true;
14
+ readonly order_info: true;
15
+ readonly buy_sell_buttons: true;
16
+ readonly broker_button: true;
17
+ readonly show_order_panel_on_start: false;
18
+ readonly order_panel_close_button: true;
19
+ readonly order_panel_undock: true;
20
+ readonly chart_hide_close_position_button: false;
21
+ readonly chart_hide_close_order_button: false;
22
+ readonly dom_widget: false;
23
+ readonly dom_raw_volume_values: false;
24
+ readonly hide_right_toolbar: false;
25
+ readonly hide_right_toolbar_tabs: false;
26
+ readonly show_symbol_logo_in_account_manager: true;
27
+ readonly show_symbol_logo_in_close_position_dialog: true;
28
+ readonly show_symbol_logo_in_cancel_order_dialog: true;
29
+ readonly prefer_symbol_name_over_fullname: true;
30
+ readonly static_dom: false;
31
+ readonly show_buy_sell_buttons_on_unsupported_resolution: false;
32
+ }>;
33
+ export type TradingFeature = keyof typeof tradingFeatureDefaults;
34
+ export type TradingFeatures = Readonly<Record<TradingFeature, boolean>>;
35
+ /** Unknown and inherited names are ignored. Explicit disable always wins. */
36
+ export declare function resolveTradingFeatures(enabled?: readonly string[], disabled?: readonly string[]): TradingFeatures;
37
+ /** prefer_symbol_name_over_fullname shows the symbol name instead of the `exchange:name` combination. */
38
+ /** Trading display name: the instrument's `brokerSymbol` when the broker supplies one, else the chart symbol. */
39
+ export declare function symbolLabel(chartSymbol: string, features: Pick<TradingFeatures, "prefer_symbol_name_over_fullname">, brokerSymbol?: string): string;
@@ -0,0 +1,70 @@
1
+ import type { TradingProfitDisplayMode } from "../contracts/ports.js";
2
+ import { Side } from "../contracts/broker.js";
3
+ import type { IndividualPosition, InstrumentInfo, Order, PipValues, Position, PreOrder, QuantityMetainfo, TradingQuotes } from "../contracts/broker.js";
4
+ export type ProfitDisplayMode = TradingProfitDisplayMode;
5
+ /** Broker pip values are already in account currency; never multiply by an invented FX rate. */
6
+ export declare function sidePipValue(side: Side, instrument: InstrumentInfo, dynamic?: PipValues): number | undefined;
7
+ /** Account-currency value of one minimum tick for one quantity unit. */
8
+ export declare function instrumentTickValue(side: Side, instrument: InstrumentInfo, dynamic?: PipValues): number | undefined;
9
+ export declare function executablePrice(side: Side, quotes?: TradingQuotes): number | undefined;
10
+ export declare function liquidationPrice(side: Side, quotes?: TradingQuotes): number | undefined;
11
+ export declare function orderEntryPrice(order: PreOrder, quotes?: TradingQuotes): number | undefined;
12
+ /**
13
+ * Price a position's TP/SL must sit around: the current price it would close at (bid for a long, ask for a
14
+ * short), so a stop can trail into profit; the entry price when no quote is available.
15
+ */
16
+ export declare function positionProtectionReference(position: Readonly<Position | IndividualPosition>, quotes?: TradingQuotes): number | undefined;
17
+ /** Entry price of a working order, net position (average) or individual position (fill). */
18
+ export declare function entityEntryPrice(kind: "order" | "position" | "individualPosition", entity: Readonly<Order | Position | IndividualPosition>): number | undefined;
19
+ export declare function oppositeSide(side: Side): Side;
20
+ export declare function positionProfit(input: {
21
+ readonly position: Pick<Position, "side" | "qty" | "avgPrice" | "extra">;
22
+ readonly instrument: InstrumentInfo;
23
+ readonly quotes?: TradingQuotes;
24
+ readonly pipValues?: PipValues;
25
+ readonly mode: ProfitDisplayMode;
26
+ readonly supportPLUpdate: boolean;
27
+ readonly source: "chart" | "table";
28
+ readonly tablePL?: number;
29
+ /** `positionPLInInstrumentCurrency`: money estimates stay in the instrument currency (no pip value conversion). */
30
+ readonly inInstrumentCurrency?: boolean;
31
+ }): number | undefined;
32
+ /** Precision needed to retain the smallest tick as a fraction of the displayed pip unit. */
33
+ export declare function profitTickPrecision(instrument: InstrumentInfo): number | undefined;
34
+ export declare function riskBudget(value: number, kind: "money" | "percentage", equity?: number): number | undefined;
35
+ export interface RiskSizingContext {
36
+ readonly entry?: number;
37
+ readonly stop?: number;
38
+ readonly instrument: InstrumentInfo;
39
+ readonly side: Side;
40
+ readonly pipValues?: PipValues;
41
+ readonly currency: "account" | "instrument";
42
+ readonly accountCurrency?: string;
43
+ }
44
+ /** Value of one price point per quantity unit, in the explicitly selected currency. */
45
+ export declare function monetaryPointValue(input: {
46
+ readonly instrument: InstrumentInfo;
47
+ readonly pipValue?: number;
48
+ readonly currency: "account" | "instrument";
49
+ readonly accountCurrency?: string;
50
+ }): number | undefined;
51
+ /** Monetary loss for one quantity unit at the stop, in the selected known currency. */
52
+ export declare function riskPerUnit(input: RiskSizingContext): number | undefined;
53
+ export declare function quantityForRisk(input: RiskSizingContext & {
54
+ readonly budget?: number;
55
+ }): {
56
+ readonly qty: number;
57
+ readonly perUnitRisk: number;
58
+ readonly actualRisk: number;
59
+ } | undefined;
60
+ export declare function cryptoBaseQuantity(quoteAmount: number, price: number | undefined, quantity: QuantityMetainfo): number | undefined;
61
+ export declare function cryptoQuoteAmount(baseQuantity: number, price?: number): number | undefined;
62
+ /** Notional/margin is shown only when its monetary unit is known and compatible. */
63
+ /** Instrument-currency value of one price unit per quantity: big point value, lot size, or 1 for stocks/crypto. */
64
+ /**
65
+ * Money per one-point price move per unit of quantity. Only stocks and spot crypto default to 1; a futures contract's
66
+ * multiplier is a broker fact (`bigPointValue`), never guessed, so a missing one leaves money estimates unavailable.
67
+ */
68
+ export declare function instrumentPointValue(instrument: InstrumentInfo): number | undefined;
69
+ export declare function orderNotional(qty: number, price: number | undefined, instrument: InstrumentInfo): number | undefined;
70
+ export declare function marginRequired(notional: number | undefined, marginRate: number | undefined, instrumentCurrency?: string, accountCurrency?: string): number | undefined;
@@ -0,0 +1,11 @@
1
+ import type { Order } from "../contracts/broker.js";
2
+ /** Default most order-history rows kept from one read. */
3
+ export declare const DEFAULT_HISTORY_LIMIT = 5000;
4
+ /**
5
+ * Keeps the newest `limit` history rows: by `updateTime` when every row has one, otherwise the last rows in
6
+ * arrival order. Returns the kept rows (in their original order) and how many were dropped.
7
+ */
8
+ export declare function limitHistory<T extends Pick<Order, "updateTime">>(rows: readonly T[], limit: number): {
9
+ readonly rows: readonly T[];
10
+ readonly dropped: number;
11
+ };
@@ -0,0 +1,14 @@
1
+ import type { TradingChartBinding } from "../contracts/ports.js";
2
+ export interface AccountGeneration {
3
+ readonly accountId?: string;
4
+ readonly generation: number;
5
+ }
6
+ export declare function sameAccountGeneration(left: AccountGeneration, right: AccountGeneration): boolean;
7
+ /** Chart lifetime identity; validate the symbol separately when a command captures it. */
8
+ export declare function sameBinding(left: Pick<TradingChartBinding, "id" | "generation"> | undefined, right: Pick<TradingChartBinding, "id" | "generation">): boolean;
9
+ export declare function bindingKey(binding: Pick<TradingChartBinding, "id" | "generation">): string;
10
+ /** Currency of an account in the broker's account list; undefined while unknown. */
11
+ export declare function accountCurrency(accounts: readonly {
12
+ readonly id: string;
13
+ readonly currency?: string;
14
+ }[] | undefined, accountId: string | undefined): string | undefined;
@@ -0,0 +1,8 @@
1
+ /** Tests a DTO record without enumerating unrelated provider fields. */
2
+ export declare function isOrdinaryDataRecord(value: unknown): value is Record<string, unknown>;
3
+ /**
4
+ * Deep-frozen clone that never executes broker getters. A value this function already produced is returned as
5
+ * is, so the host boundary's copy is the one defensive pass for each push.
6
+ * Typed as T so callers keep their own readonly annotations. Callback-bearing configuration has its own path. */
7
+ export declare function snapshot<T>(value: T): T;
8
+ export declare function equalData(a: unknown, b: unknown): boolean;
@@ -0,0 +1,18 @@
1
+ import type { Dispose } from "../contracts/ports.js";
2
+ /** Always attempt releases in insertion order, then preserve the first failure. */
3
+ export declare function releaseAll(releases: Iterable<Dispose>): void;
4
+ /** Keyed demand with idempotent leases and optional consumer identity deduplication. */
5
+ export declare class KeyedRefCount<K, D> {
6
+ private readonly dispose;
7
+ private readonly entries;
8
+ constructor(dispose: (value: D, key: K) => void);
9
+ get(key: K): D | undefined;
10
+ values(): IterableIterator<D>;
11
+ [Symbol.iterator](): IterableIterator<[K, D]>;
12
+ acquire(key: K, create: () => D, owner?: unknown): {
13
+ value: D;
14
+ first: boolean;
15
+ release: () => void;
16
+ };
17
+ releaseAll(): void;
18
+ }
@@ -0,0 +1,42 @@
1
+ import type { IBrokerTerminal, LeverageInfo, LeverageInfoParams, LeveragePreviewResult, LeverageSetParams } from "../contracts/broker.js";
2
+ import type { CapabilityPolicy } from "./capabilities.js";
3
+ import type { TradingCommandContext } from "./trading-commands.js";
4
+ import type { CommandCoordinator, TradingCommandResult } from "./command-coordinator.js";
5
+ export interface LeverageRequest {
6
+ readonly context: TradingCommandContext;
7
+ readonly params: LeverageInfoParams;
8
+ }
9
+ export interface LeverageChangeRequest {
10
+ readonly context: TradingCommandContext;
11
+ readonly params: LeverageSetParams;
12
+ readonly previewToken?: string;
13
+ }
14
+ export interface LeverageReview {
15
+ readonly token: string;
16
+ readonly info: Readonly<LeverageInfo>;
17
+ readonly preview?: Readonly<LeveragePreviewResult>;
18
+ }
19
+ interface Services {
20
+ readonly broker: IBrokerTerminal;
21
+ readonly coordinator: CommandCoordinator;
22
+ readonly policy: (symbol?: string) => CapabilityPolicy;
23
+ readonly validateContext: (context: TradingCommandContext) => void;
24
+ readonly read: <T>(load: () => T | Promise<T>) => Promise<T>;
25
+ readonly refreshDependencies: (symbol: string) => Promise<void>;
26
+ readonly invalidatePreviews: (symbol: string) => void;
27
+ readonly refresh: () => void;
28
+ }
29
+ /** No leverage push exists in the pinned host; confirm with an explicit broker information read. */
30
+ export declare class LeverageCommands {
31
+ private readonly services;
32
+ private readonly reviews;
33
+ constructor(services: Services);
34
+ clearReviews(): void;
35
+ private assert;
36
+ info(input: LeverageRequest): Promise<Readonly<LeverageInfo>>;
37
+ private validateValue;
38
+ review(input: LeverageChangeRequest): Promise<LeverageReview>;
39
+ private confirm;
40
+ set(input: LeverageChangeRequest): Promise<TradingCommandResult>;
41
+ }
42
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { Order } from "../contracts/broker.js";
2
+ import { type BracketParentKind } from "./bracket-parent.js";
3
+ import type { TradingState } from "./trading-state.js";
4
+ type ModificationState = {
5
+ readonly [K in "orders" | "positions" | "individualPositions"]: Pick<TradingState[K], "get" | "revision">;
6
+ };
7
+ export interface ModificationParentContext {
8
+ readonly kind: BracketParentKind;
9
+ readonly id: string;
10
+ readonly revision: number;
11
+ }
12
+ export declare function captureModificationParent(state: ModificationState, id: string): ModificationParentContext | undefined;
13
+ /** The called child and its owner form one review identity, even when their IDs happen to match. */
14
+ export declare function assertModificationParent(state: ModificationState, order: Readonly<Order>, context?: ModificationParentContext): {
15
+ value: Readonly<import("../contracts/broker.js").PlacedOrder> | Readonly<import("../contracts/broker.js").Position> | Readonly<import("../contracts/broker.js").IndividualPosition>;
16
+ kind: BracketParentKind;
17
+ id: string;
18
+ key: string;
19
+ } | undefined;
20
+ /** True when a protection child's owner is present and live; an orphan may be cancelled but not edited. */
21
+ export declare function modificationParentAvailable(state: ModificationState, order: Readonly<Order>): boolean;
22
+ export {};
@@ -0,0 +1,43 @@
1
+ import type { Brackets, IndividualPosition, InstrumentInfo, Position, PreOrder, TradingQuotes } from "../contracts/broker.js";
2
+ import type { CapabilityPolicy } from "./capabilities.js";
3
+ import type { TradingState } from "./trading-state.js";
4
+ import type { ModificationParentContext } from "./modification-context.js";
5
+ import { assertModificationParent } from "./modification-context.js";
6
+ /** ID of the working order a draft modifies; undefined for new placements. */
7
+ export declare function existingOrderId(order: PreOrder): string | undefined;
8
+ export type ModificationParent = NonNullable<ReturnType<typeof assertModificationParent>>;
9
+ /** A parent with its active child legs folded in, as a child edit starts from. */
10
+ export declare function protectionOwner(state: TradingState, parent: ModificationParent): Readonly<Readonly<import("../contracts/broker.js").PlacedOrder> | Readonly<Position> | Readonly<IndividualPosition>>;
11
+ export interface ModificationInput {
12
+ readonly state: TradingState;
13
+ readonly order: PreOrder;
14
+ readonly parentContext?: ModificationParentContext;
15
+ readonly policy: CapabilityPolicy;
16
+ readonly instrument: InstrumentInfo;
17
+ readonly quotes?: TradingQuotes;
18
+ readonly maxLevels?: number;
19
+ /** `always_pass_called_order_to_modify`: send the edited child itself rather than its parent. */
20
+ readonly passCalledOrder?: boolean;
21
+ }
22
+ /**
23
+ * Where a draft goes and what is sent:
24
+ * - `plain`: a new order or an order edited directly; the payload has normalised protection.
25
+ * - `order`: a child exit of a parent order; the parent (or, with `passCalledOrder`, the child) is modified.
26
+ * - `position`: a child exit of a position; the position's protection is edited with `brackets`.
27
+ */
28
+ export type ModificationRoute = {
29
+ readonly route: "plain";
30
+ readonly payload: PreOrder;
31
+ } | {
32
+ readonly route: "order";
33
+ readonly payload: PreOrder;
34
+ readonly parent: ModificationParent;
35
+ } | {
36
+ readonly route: "position";
37
+ readonly payload: PreOrder;
38
+ readonly parent: ModificationParent;
39
+ /** The protection the child edit asks for, before normalisation (sent through the position path). */
40
+ readonly brackets: Brackets;
41
+ };
42
+ /** Validates a draft against current state and decides its route. Pure over the given state snapshot. */
43
+ export declare function routeModification(input: ModificationInput): ModificationRoute;
@@ -0,0 +1,33 @@
1
+ import type { NotificationType } from "../contracts/broker.js";
2
+ import type { ReadonlyValue } from "../contracts/ports.js";
3
+ import type { OrderNotification } from "./order-notifications.js";
4
+ export interface TradingNotification {
5
+ readonly id: number;
6
+ readonly time: number;
7
+ readonly title: string;
8
+ readonly text: string;
9
+ readonly type: NotificationType;
10
+ readonly symbol?: string;
11
+ readonly orderId?: string;
12
+ readonly accountGeneration?: number;
13
+ readonly event?: OrderNotification["event"];
14
+ readonly market?: boolean;
15
+ readonly trade?: OrderNotification["trade"];
16
+ readonly audience?: "history" | "toast";
17
+ }
18
+ export type NotificationInput = Omit<TradingNotification, "id" | "time"> & {
19
+ readonly time?: number;
20
+ };
21
+ /** One bounded history for broker messages and authoritative order transitions. */
22
+ export declare class NotificationLog implements ReadonlyValue<readonly TradingNotification[]> {
23
+ private readonly now;
24
+ private readonly entries;
25
+ private sequence;
26
+ private disposed;
27
+ constructor(now?: () => number);
28
+ get(): readonly TradingNotification[];
29
+ subscribe(listener: (entries: readonly TradingNotification[]) => void): () => void;
30
+ push(notification: NotificationInput): void;
31
+ pushBatch(notifications: readonly NotificationInput[]): void;
32
+ destroy(): void;
33
+ }
@@ -0,0 +1,4 @@
1
+ /** Decimal places, including scientific notation, within the formatter's supported range. */
2
+ export declare function decimalPlaces(value: number): number;
3
+ /** A percentage with two decimals ("62.50%"), or "—" when unknown. */
4
+ export declare function formatPercent(value: number | undefined): string;
@@ -0,0 +1,50 @@
1
+ import type { Side } from "../contracts/broker.js";
2
+ import type { TradingCommandResult } from "./command-coordinator.js";
3
+ import { type PositionCommandServices } from "./position-commands.js";
4
+ import type { EntityRequest, LumenOrderPreview, ModifyRequest, PlaceRequest, TradingCommandContext, TradingCommandServices } from "./trading-commands.js";
5
+ /** What order commands use; positions are reached through `editTradingProtection` for child exits of positions. */
6
+ export type OrderCommandServices = PositionCommandServices & Pick<TradingCommandServices, "alwaysPassCalledOrderToModify" | "orderPreviewEnabled" | "now" | "clockSkewToleranceSeconds" | "read" | "orderOptions">;
7
+ /** Placement, modification, cancellation and order previews. */
8
+ export declare class OrderCommands {
9
+ private readonly services;
10
+ private readonly previews;
11
+ constructor(services: OrderCommandServices, nextSequence: () => number);
12
+ clear(): void;
13
+ /** Leverage changes invalidate reviews for their symbol. */
14
+ invalidateSymbol(symbol: string): void;
15
+ validateContext(context: TradingCommandContext, id?: string): void;
16
+ private currentContext;
17
+ private requiresOrderPreview;
18
+ /**
19
+ * The reviewed preview must still match this request when the broker supports previews for it.
20
+ * Passing the prepared order consumes the lease at dispatch.
21
+ */
22
+ private assertPreview;
23
+ private requirePreview;
24
+ place(request: PlaceRequest): Promise<TradingCommandResult>;
25
+ private validateModificationContext;
26
+ private route;
27
+ private validateOrderDraft;
28
+ private modificationOptions;
29
+ /** Loaded protection options for a draft that has, or edits, protection. */
30
+ private loadProtectionOptions;
31
+ validate(request: PlaceRequest): Promise<void>;
32
+ /** Validation shared by validate(), preview() and modify(); returns what it loaded so callers do not ask again. */
33
+ private checkDraft;
34
+ preview(request: PlaceRequest): Promise<LumenOrderPreview>;
35
+ modify(request: ModifyRequest): Promise<TradingCommandResult>;
36
+ cancel(request: EntityRequest): Promise<TradingCommandResult>;
37
+ cancelMany(request: {
38
+ context: TradingCommandContext;
39
+ symbol: string;
40
+ side?: Side;
41
+ orders: readonly {
42
+ id: string;
43
+ revision: number;
44
+ }[];
45
+ }): Promise<readonly {
46
+ id: string;
47
+ result?: TradingCommandResult;
48
+ error?: unknown;
49
+ }[]>;
50
+ }
@@ -0,0 +1,14 @@
1
+ import { OrderType } from "../contracts/broker.js";
2
+ import type { InstrumentInfo, OrderDuration, PreOrder } from "../contracts/broker.js";
3
+ import type { CapabilityPolicy } from "./capabilities.js";
4
+ export declare function durationOptions(policy: CapabilityPolicy, type: OrderType, instrument?: InstrumentInfo): import("../contracts/broker.js").OrderDurationMetaInfo[];
5
+ export declare function defaultDuration(policy: CapabilityPolicy, type: OrderType, instrument?: InstrumentInfo): OrderDuration | undefined;
6
+ /** Broker defaults apply to new orders, including silent placement; existing orders retain their explicit fields. */
7
+ export declare function withDefaultDuration<T extends PreOrder>(order: T, policy: CapabilityPolicy, instrument?: InstrumentInfo): T;
8
+ export interface DisplayDateTime {
9
+ readonly date: string;
10
+ readonly time: string;
11
+ }
12
+ export declare function displayDateTime(seconds: number, timezone: string): DisplayDateTime | undefined;
13
+ /** Reject DST gaps and repeated local times rather than silently choosing a different instant. */
14
+ export declare function expirationSeconds(input: DisplayDateTime, timezone: string): number | undefined;
@@ -0,0 +1,7 @@
1
+ import { OrderType, Side } from "../contracts/broker.js";
2
+ import type { PreOrder } from "../contracts/broker.js";
3
+ /** User-facing order type wording shared by the ticket, chart lines, dialogs and notifications. */
4
+ export declare function orderTypeName(type: OrderType): string;
5
+ export declare function sideName(side: Side): "Buy" | "Sell";
6
+ /** Price shown next to an order: the limit price for limit and stop-limit orders, otherwise the stop price. */
7
+ export declare function orderDisplayPrice(order: Pick<PreOrder, "type" | "limitPrice" | "stopPrice">): number | undefined;
@@ -0,0 +1,16 @@
1
+ import type { InstrumentInfo, Order, PreOrder } from "../contracts/broker.js";
2
+ type MatchInstrument = Pick<InstrumentInfo, "minTick" | "variableMinTick"> & {
3
+ readonly qty?: Pick<InstrumentInfo["qty"], "step">;
4
+ };
5
+ /**
6
+ * Whether a broker order reflects the submitted fields: prices within half a tick and quantity within half a
7
+ * quantity step of the instrument; every other submitted field exactly. Used for uncorrelated candidates and
8
+ * modifications.
9
+ */
10
+ export declare function matchesOrder(order: Readonly<Order>, submitted: PreOrder | Order, instrument?: MatchInstrument): boolean;
11
+ /**
12
+ * The broker returned this order's ID: identity plus symbol, side and type confirm it. Brokers may round,
13
+ * normalise or drop other fields (custom fields, for example) in their echo.
14
+ */
15
+ export declare function matchesIdentifiedOrder(order: Readonly<Order>, submitted: PreOrder | Order): boolean;
16
+ export {};
@@ -0,0 +1,20 @@
1
+ import { type BracketParentKind } from "./bracket-parent.js";
2
+ import type { Order, PreOrder } from "../contracts/broker.js";
3
+ import type { CapabilityPolicy } from "./capabilities.js";
4
+ export declare const editableOrderFields: readonly ["qty", "side", "type", "limitPrice", "stopPrice", "stopType", "stopLoss", "takeProfit", "guaranteedStop", "trailingStopPips", "duration", "customFields", "exitLevels"];
5
+ /** Both preview and dispatch enforce the same current broker and symbol permissions. */
6
+ export declare function assertOrderModification(previous: Readonly<Order> | undefined, order: Readonly<PreOrder>, policy: CapabilityPolicy): void;
7
+ /** Which parts of an existing order a host may offer for editing; commands enforce the same rules on dispatch. */
8
+ export interface OrderEditability {
9
+ /** Owner kind when the order is a protection child. */
10
+ readonly protection: BracketParentKind | undefined;
11
+ readonly price: boolean;
12
+ readonly qty: boolean;
13
+ readonly type: boolean;
14
+ readonly duration: boolean;
15
+ /** Nested TP/SL editing on a parent order. */
16
+ readonly brackets: boolean;
17
+ readonly trailingDistance: boolean;
18
+ }
19
+ export declare function orderEditability(order: Readonly<Order>, policy: CapabilityPolicy, parentAvailable: boolean): OrderEditability;
20
+ export declare function canModifyOrder(editability: OrderEditability): boolean;
@@ -0,0 +1,30 @@
1
+ import { NotificationType } from "../contracts/broker.js";
2
+ import type { Order } from "../contracts/broker.js";
3
+ import type { EntityReader } from "./entity-store.js";
4
+ export declare enum OrderNotice {
5
+ Placed = "placed",
6
+ Executed = "executed",
7
+ PartialFill = "partially filled",
8
+ Modified = "modified",
9
+ Cancelled = "cancelled",
10
+ Rejected = "rejected"
11
+ }
12
+ export interface OrderNotification {
13
+ readonly title: string;
14
+ readonly text: string;
15
+ readonly type: NotificationType;
16
+ readonly event: OrderNotice;
17
+ readonly symbol: string;
18
+ readonly orderId: string;
19
+ readonly market: boolean;
20
+ readonly trade?: {
21
+ readonly side: Order["side"];
22
+ readonly quantity: number;
23
+ readonly detail: string;
24
+ };
25
+ }
26
+ export declare function protectionNoticeName(order: Readonly<Order>): string | undefined;
27
+ export declare function notificationPrice(value: number): string;
28
+ export declare function describeOrderNotification(order: Readonly<Order>, event: OrderNotice, previous?: Readonly<Order>): OrderNotification;
29
+ /** Snapshots refresh the baseline silently. Live notices report broker transitions and confirmed edits. */
30
+ export declare function watchOrderNotifications(orders: EntityReader<Order>, live: () => boolean, customFields: readonly string[], push: (notification: OrderNotification, order: Readonly<Order>) => void): () => void;
@@ -0,0 +1,4 @@
1
+ import type { InstrumentInfo, Order, PreOrder, TradingQuotes } from "../contracts/broker.js";
2
+ import type { CapabilityPolicy } from "./capabilities.js";
3
+ export declare function hasOrderProtection(order: PreOrder): boolean;
4
+ export declare function prepareOrderProtection<T extends PreOrder>(order: T, instrument: InstrumentInfo, policy: CapabilityPolicy, quotes?: TradingQuotes, maxLevels?: number, previous?: Readonly<Order>): T;
@@ -0,0 +1,10 @@
1
+ import type { Brackets, Order } from "../contracts/broker.js";
2
+ /** The five protection fields of an order or position, without the rest of the entity. */
3
+ export declare function protectionFields(source: Readonly<Brackets>): Brackets;
4
+ /**
5
+ * Some providers report protection only as child orders, or report the parent's aggregate fields partially.
6
+ * Retain broker IDs and allocation, never invent either, and never drop a leg that an active child proves exists.
7
+ */
8
+ export declare function completeParentProtection<T extends Brackets & {
9
+ qty: number;
10
+ }>(parent: Readonly<T>, children: readonly Readonly<Order>[]): Readonly<T>;
@@ -0,0 +1,45 @@
1
+ import { type AccountContext } from "./command-context.js";
2
+ import { ParentType } from "../contracts/broker.js";
3
+ import type { Brackets, IBrokerTerminal, InstrumentInfo, Order, TradingDialogOptions } from "../contracts/broker.js";
4
+ import type { LumenBrokerExtensions } from "../contracts/ports.js";
5
+ import type { CapabilityPolicy } from "./capabilities.js";
6
+ import type { TradingState } from "./trading-state.js";
7
+ import type { CommandCoordinator, TradingCommandResult } from "./command-coordinator.js";
8
+ export interface PositionContext extends AccountContext {
9
+ readonly revision?: number;
10
+ }
11
+ export interface PositionRequest {
12
+ readonly context: PositionContext;
13
+ readonly id: string;
14
+ readonly individual?: boolean;
15
+ /** Private command dependency for an edit initiated on a broker-owned bracket row. */
16
+ readonly sourceOrder?: {
17
+ readonly id: string;
18
+ readonly revision: number;
19
+ };
20
+ }
21
+ export interface CloseRequest extends PositionRequest {
22
+ readonly amount?: number;
23
+ readonly confirmId?: string;
24
+ readonly previewToken?: string;
25
+ }
26
+ export interface ProtectionRequest extends PositionRequest {
27
+ readonly brackets: Brackets;
28
+ /** Broker-specific position fields; confirmed through Position.extra using the field IDs. */
29
+ readonly customFields?: Readonly<Record<string, unknown>>;
30
+ }
31
+ export interface PositionCommandServices {
32
+ readonly broker: IBrokerTerminal;
33
+ readonly state: TradingState;
34
+ readonly coordinator: CommandCoordinator;
35
+ readonly policy: (symbol?: string) => CapabilityPolicy;
36
+ readonly symbolInfo: (symbol: string) => Promise<InstrumentInfo>;
37
+ readonly extensions?: LumenBrokerExtensions;
38
+ readonly positionOptions?: (symbol: string) => Promise<TradingDialogOptions | undefined>;
39
+ readonly refresh: () => void;
40
+ readonly refreshPositions?: () => Promise<void>;
41
+ readonly beginProtectionNotifications?: (context: AccountContext, parentType: ParentType, id: string, previous: readonly Readonly<Order>[]) => (confirmed: readonly Readonly<Order>[] | undefined) => void;
42
+ }
43
+ export declare function closeTradingPosition(services: PositionCommandServices, request: CloseRequest, previewApproved?: boolean, consumePreview?: () => void): Promise<TradingCommandResult>;
44
+ export declare function reverseTradingPosition(services: PositionCommandServices, request: PositionRequest): Promise<TradingCommandResult>;
45
+ export declare function editTradingProtection(services: PositionCommandServices, request: ProtectionRequest, beforeDispatch?: () => void): Promise<TradingCommandResult>;
@@ -0,0 +1,5 @@
1
+ import type { ExtraData, TradingDialogCustomField } from "../contracts/broker.js";
2
+ export declare function positionCustomValues(fields: readonly TradingDialogCustomField[], extra: Readonly<ExtraData> | undefined, overrides?: Readonly<Record<string, unknown>>): Record<string, unknown>;
3
+ /** Dialog defaults prepare a draft; only an explicit broker value confirms it. */
4
+ export declare function positionCustomMatches(values: Readonly<Record<string, unknown>> | undefined, extra: Readonly<ExtraData> | undefined): boolean;
5
+ export declare function validatePositionCustomFields(values: Readonly<Record<string, unknown>> | undefined, fields: readonly TradingDialogCustomField[], extra: Readonly<ExtraData> | undefined): Record<string, unknown> | undefined;
@@ -0,0 +1,22 @@
1
+ import type { Side } from "../contracts/broker.js";
2
+ import type { EntityReader } from "./entity-store.js";
3
+ import type { TradingSession } from "./session.js";
4
+ import type { ProfitDisplayMode } from "./financial-rules.js";
5
+ import type { FinancialValue } from "./trading-state.js";
6
+ interface PositionInput {
7
+ readonly id: string;
8
+ readonly symbol: string;
9
+ readonly side: Side;
10
+ readonly qty: number;
11
+ readonly avgPrice?: number;
12
+ readonly price?: number;
13
+ }
14
+ /** Display-only estimates. Demand and work are indexed by the positions' symbols. */
15
+ export declare function createPositionEstimates<T extends PositionInput>(session: Pick<TradingSession, "state" | "symbolInfo" | "acquireQuotes" | "acquireFinancial"> & Partial<Pick<TradingSession, "policy">>, source: EntityReader<T>, individual?: boolean, onError?: (cause: unknown) => void): {
16
+ reader: EntityReader<FinancialValue>;
17
+ setMode(value: ProfitDisplayMode): void;
18
+ setSymbols(symbols: readonly string[]): void;
19
+ setActive(value: boolean): void;
20
+ destroy(): void;
21
+ };
22
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { Brackets, IndividualPosition, Position } from "../contracts/broker.js";
2
+ import type { CapabilityPolicy } from "./capabilities.js";
3
+ /** The public command boundary owns permissions even when the built-in dialog is bypassed. */
4
+ export declare function assertPositionProtectionPermissions(previous: Readonly<Position | IndividualPosition>, brackets: Readonly<Brackets>, policy: CapabilityPolicy, individual: boolean): void;
@@ -0,0 +1,2 @@
1
+ /** Stable persisted namespace; callers retain ownership of suffix encoding and schema names. */
2
+ export declare function preferencesKey(namespace: string, suffix: string): string;
@@ -0,0 +1,12 @@
1
+ /** Reviews are consumed only by a matching dispatch; failed checks keep them available. */
2
+ export declare class PreviewLeases<T> {
3
+ private readonly prefix;
4
+ private readonly next;
5
+ private readonly leases;
6
+ private sequence;
7
+ constructor(prefix: string, capacity?: number, next?: () => number);
8
+ issue(value: T): string;
9
+ claim(token: string | undefined, matches: (value: T) => boolean, consume?: boolean): T | undefined;
10
+ invalidate(predicate: (value: T) => boolean): void;
11
+ clear(): void;
12
+ }
@@ -0,0 +1,23 @@
1
+ import { OrderType, StopType } from "../contracts/broker.js";
2
+ import type { Brackets, Order } from "../contracts/broker.js";
3
+ /** Bracket fields that brokers represent as separate child orders. */
4
+ export type ProtectionField = "takeProfit" | "stopLoss" | "guaranteedStop" | "trailingStopPips";
5
+ /** The bracket field a broker child order represents: limit → take profit, stop → its stop style. */
6
+ export declare function childProtectionField(child: Pick<Order, "type" | "stopType">): ProtectionField | undefined;
7
+ /** Value of that field on the child: trailing distance, limit price for take profit, otherwise stop price. */
8
+ export declare function childProtectionValue(child: Pick<Order, "limitPrice" | "stopPrice" | "trailingStopPips">, field: ProtectionField): number | undefined;
9
+ /** A child order the broker should report after protection is applied. */
10
+ export interface ExpectedProtectionLeg {
11
+ readonly type: OrderType;
12
+ /** Undefined for trailing stops, whose trigger price moves with the market. */
13
+ readonly price?: number;
14
+ /** Undefined for plain stop loss, which accepts any non-special stop type. */
15
+ readonly stopType?: StopType;
16
+ readonly levelId?: string;
17
+ readonly qty: number;
18
+ }
19
+ /** Child orders implied by legacy brackets (one level of `qty`) or by allocated exit levels. */
20
+ export declare function expectedProtectionLegs(brackets: Readonly<Brackets>, qty: number): ExpectedProtectionLeg[];
21
+ export declare function matchesProtectionLeg(child: Readonly<Order>, leg: ExpectedProtectionLeg): boolean;
22
+ /** Every expected leg has a matching live child, and there are no extra children. */
23
+ export declare function matchesProtectionLegs(children: readonly Readonly<Order>[], expected: readonly ExpectedProtectionLeg[]): boolean;
@@ -0,0 +1,9 @@
1
+ import type { Order, ParentType } from "../contracts/broker.js";
2
+ import type { AccountContext } from "./command-context.js";
3
+ import type { NotificationLog } from "./notification-log.js";
4
+ import { type OrderNotification } from "./order-notifications.js";
5
+ /** Correlate cancel/replace noise only with a dispatched position protection command. */
6
+ export declare function createProtectionNotifications(log: NotificationLog, now: () => number, current: () => AccountContext | undefined, live: () => boolean): {
7
+ order(notice: OrderNotification, order: Readonly<Order>): void;
8
+ begin(context: AccountContext, parentType: ParentType, id: string, previous: readonly Readonly<Order>[]): (confirmed: readonly Readonly<Order>[] | undefined) => void;
9
+ };