@lumencharts/trading-platform 0.0.0-stage → 0.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/CHANGELOG.md +25 -0
- package/LICENSE +55 -0
- package/README.md +53 -2
- package/dist/asset-entry.d.ts +3 -0
- package/dist/asset.d.ts +3 -0
- package/dist/asset.js +21689 -0
- package/dist/chart/bracket-links.d.ts +8 -0
- package/dist/chart/context-actions.d.ts +7 -0
- package/dist/chart/edit-presentation.d.ts +32 -0
- package/dist/chart/edit-preview.d.ts +26 -0
- package/dist/chart/exit-profit.d.ts +32 -0
- package/dist/chart/frame-batch.d.ts +15 -0
- package/dist/chart/overlay-coordinator.d.ts +18 -0
- package/dist/chart/overlay-events.d.ts +3 -0
- package/dist/chart/overlay-gesture.d.ts +40 -0
- package/dist/chart/overlay-index.d.ts +30 -0
- package/dist/chart/overlay-projection.d.ts +51 -0
- package/dist/chart/overlay-types.d.ts +42 -0
- package/dist/chart/parent-links.d.ts +33 -0
- package/dist/chart/position-profit.d.ts +15 -0
- package/dist/chart/review-lock.d.ts +14 -0
- package/dist/chart/ticket-projection.d.ts +36 -0
- package/dist/compat/default-formatters.d.ts +6 -0
- package/dist/compat/delegate.d.ts +11 -0
- package/dist/compat/factory.d.ts +5 -0
- package/dist/compat/formatters.d.ts +26 -0
- package/dist/compat/host-dialogs.d.ts +5 -0
- package/dist/compat/host-preferences.d.ts +8 -0
- package/dist/compat/host.d.ts +39 -0
- package/dist/compat/watched-value.d.ts +25 -0
- package/dist/conformance/index.d.ts +78 -0
- package/dist/conformance/index.js +6859 -0
- package/dist/conformance/replay.d.ts +35 -0
- package/dist/contracts/broker.d.ts +1122 -0
- package/dist/contracts/broker.js +168 -0
- package/dist/contracts/index.d.ts +3 -0
- package/dist/contracts/index.js +168 -0
- package/dist/contracts/market-data.d.ts +289 -0
- package/dist/contracts/market-data.js +11 -0
- package/dist/contracts/ports.d.ts +469 -0
- package/dist/contracts/ports.js +5 -0
- package/dist/core/account-datasets.d.ts +29 -0
- package/dist/core/account-lifecycle.d.ts +70 -0
- package/dist/core/account-types.d.ts +6 -0
- package/dist/core/bounded-map.d.ts +12 -0
- package/dist/core/bracket-input.d.ts +32 -0
- package/dist/core/bracket-modification.d.ts +6 -0
- package/dist/core/bracket-parent.d.ts +11 -0
- package/dist/core/broker-debug.d.ts +10 -0
- package/dist/core/capabilities.d.ts +34 -0
- package/dist/core/capability-metadata.d.ts +60 -0
- package/dist/core/capability-policy.d.ts +32 -0
- package/dist/core/chart-exit-level.d.ts +11 -0
- package/dist/core/chart-order-edit.d.ts +50 -0
- package/dist/core/clock.d.ts +2 -0
- package/dist/core/close-commands.d.ts +24 -0
- package/dist/core/close-flow.d.ts +14 -0
- package/dist/core/command-context.d.ts +16 -0
- package/dist/core/command-coordinator.d.ts +71 -0
- package/dist/core/command-follow.d.ts +32 -0
- package/dist/core/command-keys.d.ts +11 -0
- package/dist/core/context-orders.d.ts +19 -0
- package/dist/core/deferred.d.ts +5 -0
- package/dist/core/dialog-coordinator.d.ts +73 -0
- package/dist/core/display-preferences.d.ts +10 -0
- package/dist/core/disposal.d.ts +8 -0
- package/dist/core/entity-store.d.ts +56 -0
- package/dist/core/entity-validation.d.ts +9 -0
- package/dist/core/errors.d.ts +24 -0
- package/dist/core/execution-demand.d.ts +11 -0
- package/dist/core/execution-sound.d.ts +10 -0
- package/dist/core/exit-level-draft.d.ts +9 -0
- package/dist/core/exit-level-summary.d.ts +3 -0
- package/dist/core/exit-level-template.d.ts +16 -0
- package/dist/core/features.d.ts +39 -0
- package/dist/core/financial-rules.d.ts +70 -0
- package/dist/core/history-limit.d.ts +11 -0
- package/dist/core/identity.d.ts +14 -0
- package/dist/core/immutable.d.ts +8 -0
- package/dist/core/keyed-ref-count.d.ts +18 -0
- package/dist/core/leverage-commands.d.ts +42 -0
- package/dist/core/modification-context.d.ts +22 -0
- package/dist/core/modification-routing.d.ts +43 -0
- package/dist/core/notification-log.d.ts +33 -0
- package/dist/core/number-precision.d.ts +4 -0
- package/dist/core/order-commands.d.ts +50 -0
- package/dist/core/order-duration.d.ts +14 -0
- package/dist/core/order-labels.d.ts +7 -0
- package/dist/core/order-matching.d.ts +16 -0
- package/dist/core/order-modification.d.ts +20 -0
- package/dist/core/order-notifications.d.ts +30 -0
- package/dist/core/order-protection.d.ts +4 -0
- package/dist/core/parent-protection.d.ts +10 -0
- package/dist/core/position-commands.d.ts +45 -0
- package/dist/core/position-custom-fields.d.ts +5 -0
- package/dist/core/position-estimates.d.ts +22 -0
- package/dist/core/position-protection-permissions.d.ts +4 -0
- package/dist/core/preferences-key.d.ts +2 -0
- package/dist/core/preview-leases.d.ts +12 -0
- package/dist/core/protection-legs.d.ts +23 -0
- package/dist/core/protection-notifications.d.ts +9 -0
- package/dist/core/protection-rules.d.ts +21 -0
- package/dist/core/quantity-input.d.ts +53 -0
- package/dist/core/read-coordinator.d.ts +15 -0
- package/dist/core/readers.d.ts +6 -0
- package/dist/core/relative-price.d.ts +4 -0
- package/dist/core/review-policy.d.ts +17 -0
- package/dist/core/session-types.d.ts +1 -0
- package/dist/core/session.d.ts +114 -0
- package/dist/core/snapshot-dataset.d.ts +47 -0
- package/dist/core/symbol-catalog.d.ts +37 -0
- package/dist/core/tradability.d.ts +26 -0
- package/dist/core/trading-commands.d.ts +104 -0
- package/dist/core/trading-rules.d.ts +14 -0
- package/dist/core/trading-settings.d.ts +39 -0
- package/dist/core/trading-state.d.ts +52 -0
- package/dist/core/value-store.d.ts +11 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +6593 -0
- package/dist/market-data/depth-book.d.ts +18 -0
- package/dist/market-data/index.d.ts +3 -0
- package/dist/market-data/index.js +735 -0
- package/dist/market-data/session-demand.d.ts +15 -0
- package/dist/market-data/subscriptions.d.ts +13 -0
- package/dist/mock/broker.d.ts +75 -0
- package/dist/mock/clock.d.ts +12 -0
- package/dist/mock/feeds.d.ts +18 -0
- package/dist/mock/index.d.ts +5 -0
- package/dist/mock/index.js +1956 -0
- package/dist/mock/protection-cancellation.d.ts +7 -0
- package/dist/mock/scenarios.d.ts +5 -0
- package/dist/paper/broker.d.ts +41 -0
- package/dist/paper/index.d.ts +6 -0
- package/dist/paper/index.js +469 -0
- package/dist/paper/market.d.ts +57 -0
- package/dist/paper/rules.d.ts +40 -0
- package/dist/ui/account-manager/account-pages.d.ts +18 -0
- package/dist/ui/account-manager/column-presentation.d.ts +5 -0
- package/dist/ui/account-manager/context-menu.d.ts +13 -0
- package/dist/ui/account-manager/csv-downloads.d.ts +5 -0
- package/dist/ui/account-manager/custom-page.d.ts +16 -0
- package/dist/ui/account-manager/custom-table.d.ts +18 -0
- package/dist/ui/account-manager/format-account-value.d.ts +12 -0
- package/dist/ui/account-manager/position-reader.d.ts +19 -0
- package/dist/ui/account-manager/row-action-tracker.d.ts +12 -0
- package/dist/ui/account-manager/row-actions.d.ts +37 -0
- package/dist/ui/account-manager/status-counts.d.ts +6 -0
- package/dist/ui/account-manager/table-controls.d.ts +13 -0
- package/dist/ui/account-manager/table-export.d.ts +30 -0
- package/dist/ui/account-manager/table-model.d.ts +11 -0
- package/dist/ui/account-manager/table-toolbar.d.ts +25 -0
- package/dist/ui/account-manager/table.d.ts +24 -0
- package/dist/ui/account-manager/view.d.ts +19 -0
- package/dist/ui/account-manager/workspace.d.ts +15 -0
- package/dist/ui/chart-actions.d.ts +11 -0
- package/dist/ui/chart-controls/eligibility.d.ts +6 -0
- package/dist/ui/chart-controls/quote-buttons.d.ts +15 -0
- package/dist/ui/chart-controls/quote-controls.d.ts +12 -0
- package/dist/ui/chart-controls/quote-widths.d.ts +8 -0
- package/dist/ui/dialogs/close-amount-form.d.ts +8 -0
- package/dist/ui/dialogs/close-preview-dialog.d.ts +5 -0
- package/dist/ui/dialogs/confirm-dialog.d.ts +7 -0
- package/dist/ui/dialogs/dialog-body.d.ts +11 -0
- package/dist/ui/dialogs/leverage-form.d.ts +10 -0
- package/dist/ui/dialogs/message-dialog.d.ts +6 -0
- package/dist/ui/dialogs/position-protection.d.ts +14 -0
- package/dist/ui/dialogs/properties-dialog.d.ts +9 -0
- package/dist/ui/dialogs/sanitize-html.d.ts +2 -0
- package/dist/ui/dialogs/types.d.ts +5 -0
- package/dist/ui/dialogs/view.d.ts +5 -0
- package/dist/ui/dock-sizes.d.ts +20 -0
- package/dist/ui/dom/controller.d.ts +34 -0
- package/dist/ui/dom/ladder.d.ts +23 -0
- package/dist/ui/dom/view.d.ts +8 -0
- package/dist/ui/dom/workspace.d.ts +17 -0
- package/dist/ui/effective-mode.d.ts +11 -0
- package/dist/ui/financial-lease.d.ts +3 -0
- package/dist/ui/icons.d.ts +4 -0
- package/dist/ui/index.d.ts +9 -0
- package/dist/ui/index.js +15918 -0
- package/dist/ui/layout.d.ts +5 -0
- package/dist/ui/mount.d.ts +11 -0
- package/dist/ui/notifications/log.d.ts +6 -0
- package/dist/ui/notifications/toasts.d.ts +5 -0
- package/dist/ui/number-input.d.ts +2 -0
- package/dist/ui/order-ticket/chart-draft-controls.d.ts +8 -0
- package/dist/ui/order-ticket/chart-projection.d.ts +9 -0
- package/dist/ui/order-ticket/controller.d.ts +41 -0
- package/dist/ui/order-ticket/custom-field.d.ts +9 -0
- package/dist/ui/order-ticket/duration-input.d.ts +9 -0
- package/dist/ui/order-ticket/exit-input.d.ts +34 -0
- package/dist/ui/order-ticket/financial-controls.d.ts +10 -0
- package/dist/ui/order-ticket/layout-context.d.ts +7 -0
- package/dist/ui/order-ticket/market.d.ts +12 -0
- package/dist/ui/order-ticket/menu.d.ts +6 -0
- package/dist/ui/order-ticket/mode-rules.d.ts +4 -0
- package/dist/ui/order-ticket/modification-fields.d.ts +23 -0
- package/dist/ui/order-ticket/move-handle.d.ts +4 -0
- package/dist/ui/order-ticket/order-sent.d.ts +4 -0
- package/dist/ui/order-ticket/placement.d.ts +27 -0
- package/dist/ui/order-ticket/preview-message.d.ts +4 -0
- package/dist/ui/order-ticket/price-input.d.ts +14 -0
- package/dist/ui/order-ticket/quantity-input.d.ts +26 -0
- package/dist/ui/order-ticket/review-panel.d.ts +10 -0
- package/dist/ui/order-ticket/rules.d.ts +16 -0
- package/dist/ui/order-ticket/stop-input.d.ts +17 -0
- package/dist/ui/order-ticket/submit-bar.d.ts +13 -0
- package/dist/ui/order-ticket/symbol-search-controller.d.ts +50 -0
- package/dist/ui/order-ticket/symbol-search.d.ts +12 -0
- package/dist/ui/order-ticket/untradable-notice.d.ts +8 -0
- package/dist/ui/order-ticket/view.d.ts +16 -0
- package/dist/ui/panel-visibility.d.ts +6 -0
- package/dist/ui/pointer-drag.d.ts +20 -0
- package/dist/ui/popup-mount.d.ts +4 -0
- package/dist/ui/primitives.d.ts +29 -0
- package/dist/ui/protection/editor.d.ts +18 -0
- package/dist/ui/protection/fields.d.ts +30 -0
- package/dist/ui/protection/level.d.ts +14 -0
- package/dist/ui/protection/protected-size.d.ts +5 -0
- package/dist/ui/protection/ticket-workspace.d.ts +7 -0
- package/dist/ui/resize-handle.css +34 -0
- package/dist/ui/resize-handle.d.ts +20 -0
- package/dist/ui/resize-handle.js +185 -0
- package/dist/ui/select.d.ts +26 -0
- package/dist/ui/surface-theme.d.ts +3 -0
- package/dist/ui/switch.d.ts +7 -0
- package/dist/ui/symbol-logo.d.ts +7 -0
- package/dist/ui/tabs.d.ts +19 -0
- package/dist/ui/ticket-dock.d.ts +18 -0
- package/dist/ui/ticket-shell.d.ts +15 -0
- package/dist/ui/trading.css +1808 -0
- package/dist/ui/trap-tab.d.ts +11 -0
- package/dist/vendor/solid-ui/index.d.ts +3 -0
- package/dist/vendor/solid-ui/paged-list-window.d.ts +27 -0
- package/dist/vendor/solid-ui/virtual-list.d.ts +21 -0
- package/package.json +104 -3
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OrderType } from '../contracts/broker.js';
|
|
2
|
+
import type { BrokerConfigFlags, IBrokerTerminal, LumenBrokerExtensions, OrderDurationMetaInfo, SingleBrokerMetaInfo, SymbolSpecificTradingOptions } from '../contracts/index.js';
|
|
3
|
+
export { defaultFlags } from './capability-metadata.js';
|
|
4
|
+
export type CapabilityFlags = Readonly<Required<BrokerConfigFlags>>;
|
|
5
|
+
export interface CapabilityDiagnostic {
|
|
6
|
+
readonly capability: keyof BrokerConfigFlags | 'dom';
|
|
7
|
+
readonly missing: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
export interface CapabilityContext {
|
|
10
|
+
readonly broker?: Partial<IBrokerTerminal>;
|
|
11
|
+
readonly extensions?: LumenBrokerExtensions;
|
|
12
|
+
readonly quoteMethods?: boolean;
|
|
13
|
+
readonly depthMethods?: boolean;
|
|
14
|
+
readonly domFeature?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface CapabilityPolicy {
|
|
17
|
+
readonly flags: CapabilityFlags;
|
|
18
|
+
readonly orderTypes: readonly OrderType[];
|
|
19
|
+
readonly durations: readonly OrderDurationMetaInfo[];
|
|
20
|
+
readonly symbol: Readonly<SymbolSpecificTradingOptions>;
|
|
21
|
+
readonly diagnostics: readonly CapabilityDiagnostic[];
|
|
22
|
+
readonly dom: boolean;
|
|
23
|
+
/** The broker streams pip values (`subscribePipValue`/`unsubscribePipValue`); otherwise money estimates use the static instrument pip value. */
|
|
24
|
+
readonly pipValues: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** Config wins as a whole over the deprecated alias; runtime patches retain presence. */
|
|
27
|
+
export declare function normalizeBrokerConfig(config?: SingleBrokerMetaInfo, brokerConfig?: SingleBrokerMetaInfo): SingleBrokerMetaInfo;
|
|
28
|
+
export declare function resolveCapabilities(config?: SingleBrokerMetaInfo, patch?: Partial<BrokerConfigFlags>, symbolOptions?: SymbolSpecificTradingOptions, context?: CapabilityContext): CapabilityPolicy;
|
|
29
|
+
/** Durations are constrained by both the selected type and the resolved symbol policy. */
|
|
30
|
+
export declare function durationsForType(policy: CapabilityPolicy, type: OrderType): readonly OrderDurationMetaInfo[];
|
|
31
|
+
/** Crypto exchange ticket mode: a symbol's own setting wins, then the broker-wide and per-type flags. */
|
|
32
|
+
export declare function cryptoTicketMode(policy: CapabilityPolicy, instrumentType?: string): boolean;
|
|
33
|
+
/** Netting brokers that bracket individual fills but not the net position show individual positions instead of net rows. */
|
|
34
|
+
export declare function showsIndividualPositions(flags: Pick<CapabilityFlags, "supportPositionNetting" | "supportIndividualPositionBrackets" | "supportPositionBrackets">): boolean;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export declare const defaultFlags: Readonly<{
|
|
2
|
+
showQuantityInsteadOfAmount: false;
|
|
3
|
+
supportOrderBrackets: false;
|
|
4
|
+
supportStopLoss: true;
|
|
5
|
+
supportTrailingStop: false;
|
|
6
|
+
supportGuaranteedStop: false;
|
|
7
|
+
supportPositions: true;
|
|
8
|
+
supportPositionBrackets: false;
|
|
9
|
+
supportIndividualPositionBrackets: false;
|
|
10
|
+
supportPositionNetting: false;
|
|
11
|
+
supportClosePosition: false;
|
|
12
|
+
supportCloseIndividualPosition: false;
|
|
13
|
+
supportModifyOrderPrice: true;
|
|
14
|
+
supportEditAmount: true;
|
|
15
|
+
supportModifyBrackets: true;
|
|
16
|
+
supportLevel2Data: false;
|
|
17
|
+
supportMultiposition: false;
|
|
18
|
+
supportPLUpdate: true;
|
|
19
|
+
supportReversePosition: false;
|
|
20
|
+
supportNativeReversePosition: false;
|
|
21
|
+
supportMarketOrders: true;
|
|
22
|
+
supportLimitOrders: true;
|
|
23
|
+
supportStopOrders: true;
|
|
24
|
+
supportStopLimitOrders: false;
|
|
25
|
+
supportDemoLiveSwitcher: true;
|
|
26
|
+
supportMarketBrackets: true;
|
|
27
|
+
supportSymbolSearch: false;
|
|
28
|
+
supportModifyDuration: false;
|
|
29
|
+
supportModifyTrailingStop: true;
|
|
30
|
+
supportMargin: false;
|
|
31
|
+
supportPlaceOrderPreview: false;
|
|
32
|
+
supportModifyOrderPreview: false;
|
|
33
|
+
supportLeverage: false;
|
|
34
|
+
supportLeverageButton: true;
|
|
35
|
+
supportOrdersHistory: true;
|
|
36
|
+
supportAddBracketsToExistingOrder: true;
|
|
37
|
+
supportBalances: false;
|
|
38
|
+
closePositionCancelsOrders: false;
|
|
39
|
+
supportOnlyPairPositionBrackets: false;
|
|
40
|
+
supportOnlyPairOrderBrackets: false;
|
|
41
|
+
supportCryptoExchangeOrderTicket: false;
|
|
42
|
+
supportSymbolSpecificCryptoOrderTicket: false;
|
|
43
|
+
positionPLInInstrumentCurrency: false;
|
|
44
|
+
showRiskInInstrumentCurrency: false;
|
|
45
|
+
supportPartialClosePosition: false;
|
|
46
|
+
supportPartialCloseIndividualPosition: false;
|
|
47
|
+
supportCancellingBothBracketsOnly: false;
|
|
48
|
+
supportCryptoBrackets: false;
|
|
49
|
+
showNotificationsLog: true;
|
|
50
|
+
supportStopOrdersInBothDirections: false;
|
|
51
|
+
supportStopLimitOrdersInBothDirections: false;
|
|
52
|
+
supportStrictCheckingLimitOrderPrice: false;
|
|
53
|
+
supportExecutions: true;
|
|
54
|
+
supportModifyOrderType: false;
|
|
55
|
+
requiresFIFOCloseIndividualPositions: false;
|
|
56
|
+
supportMultipleExitLevels: false;
|
|
57
|
+
supportUnpairedExitLevels: false;
|
|
58
|
+
supportCustomOrderInfo: false;
|
|
59
|
+
supportPreviewClosePosition: false;
|
|
60
|
+
}>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BrokerConfigFlags, OrderDurationMetaInfo, SingleBrokerMetaInfo, SymbolSpecificTradingOptions } from "../contracts/broker.js";
|
|
2
|
+
import type { ReadonlyValue } from "../contracts/ports.js";
|
|
3
|
+
import { resolveCapabilities, type CapabilityContext, type CapabilityPolicy } from "./capabilities.js";
|
|
4
|
+
import { ValueStore } from "./value-store.js";
|
|
5
|
+
export interface CapabilityPolicyOptions {
|
|
6
|
+
readonly config?: SingleBrokerMetaInfo;
|
|
7
|
+
/** Live context: broker methods, extensions and market-data availability. */
|
|
8
|
+
readonly context: () => CapabilityContext;
|
|
9
|
+
/** Symbol options and their revision; a new revision invalidates per-symbol policies. */
|
|
10
|
+
readonly catalog: {
|
|
11
|
+
options(symbol: string): SymbolSpecificTradingOptions | undefined;
|
|
12
|
+
readonly revision: ReadonlyValue<number>;
|
|
13
|
+
};
|
|
14
|
+
/** Injectable for work-count tests. */
|
|
15
|
+
readonly resolve?: typeof resolveCapabilities;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Owns broker config, runtime patches and the published account policy, and memoises per-symbol policies.
|
|
19
|
+
* Policies are pure functions of config, patch, symbol options and broker context, so they are cached until one
|
|
20
|
+
* of those changes (`update`, a patch, durations or a symbol-options revision).
|
|
21
|
+
*/
|
|
22
|
+
export declare function createCapabilityPolicy(options: CapabilityPolicyOptions): {
|
|
23
|
+
policy: ValueStore<CapabilityPolicy>;
|
|
24
|
+
readonly config: SingleBrokerMetaInfo;
|
|
25
|
+
symbolPolicy: (symbol?: string) => CapabilityPolicy;
|
|
26
|
+
/** Re-resolves the account policy after a context change; the caller publishes it. */
|
|
27
|
+
resolveAccount(): CapabilityPolicy;
|
|
28
|
+
patchConfig(changes: Partial<BrokerConfigFlags>): void;
|
|
29
|
+
setDurations(durations: OrderDurationMetaInfo[]): void;
|
|
30
|
+
destroy(): void;
|
|
31
|
+
};
|
|
32
|
+
export type CapabilityPolicyOwner = ReturnType<typeof createCapabilityPolicy>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Brackets, InstrumentInfo } from "../contracts/broker.js";
|
|
2
|
+
import type { TradingProtectionLeg as ChartProtectionLeg } from "../contracts/ports.js";
|
|
3
|
+
/** Chart-created allocated levels are paired; use an explicit 1:1 mirror for the new opposite leg. */
|
|
4
|
+
export declare function appendChartExit<T extends Brackets & {
|
|
5
|
+
qty: number;
|
|
6
|
+
}>(parent: T, leg: ChartProtectionLeg, price: number, entry: number, instrument: InstrumentInfo, id: string, maximum?: number): T;
|
|
7
|
+
/**
|
|
8
|
+
* Moves one leg of an existing allocated level, keeping its ID and quantity so the broker updates that
|
|
9
|
+
* level instead of adding one. Other levels and legs are unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export declare function moveChartExitLevel<T extends Brackets>(parent: T, levelId: string, leg: ChartProtectionLeg, price: number): T;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { InstrumentInfo, Brackets, Order, Position, IndividualPosition, PreOrder } from "../contracts/broker.js";
|
|
2
|
+
import type { TradingChartBinding, TradingProtectionLeg } from "../contracts/ports.js";
|
|
3
|
+
import type { CommandEntityKind } from "./command-keys.js";
|
|
4
|
+
import type { TradingState } from "./trading-state.js";
|
|
5
|
+
import type { TradingCommandContext } from "./trading-commands.js";
|
|
6
|
+
export type ChartEditKind = CommandEntityKind;
|
|
7
|
+
export type ChartProtectionLeg = TradingProtectionLeg;
|
|
8
|
+
export interface ChartEditOptions {
|
|
9
|
+
/** Protection leg being dragged; omitted for an order entry price move. */
|
|
10
|
+
readonly leg?: ChartProtectionLeg;
|
|
11
|
+
/** Append an allocated exit level instead of replacing the legacy pair. */
|
|
12
|
+
readonly multiple?: boolean;
|
|
13
|
+
/** Existing allocated level whose `leg` moves; set when a confirmed exit of that level is dragged. */
|
|
14
|
+
readonly level?: string;
|
|
15
|
+
/** Parent with broker child legs folded in, when protection lives in child orders. */
|
|
16
|
+
readonly completed?: Readonly<Order | Position | IndividualPosition>;
|
|
17
|
+
}
|
|
18
|
+
export interface ChartOrderEdit {
|
|
19
|
+
readonly token: number;
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly kind: ChartEditKind;
|
|
22
|
+
readonly binding: TradingChartBinding;
|
|
23
|
+
readonly context: TradingCommandContext;
|
|
24
|
+
readonly order: Readonly<Order | Position | IndividualPosition>;
|
|
25
|
+
readonly phase: "dragging" | "reviewing" | "sending";
|
|
26
|
+
readonly leg?: ChartProtectionLeg;
|
|
27
|
+
readonly multiple?: boolean;
|
|
28
|
+
readonly level?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Exit level ID of the level a chart proposal appends; readers find the proposed price through it. */
|
|
31
|
+
export declare function chartExitLevelId(token: number): string;
|
|
32
|
+
/** Patch only the selected leg; existing allocated levels are never replaced by a legacy pair. */
|
|
33
|
+
export declare function chartProtectionPatch<T extends Brackets>(parent: T, leg: ChartProtectionLeg, price: number): T;
|
|
34
|
+
/** One session-owned proposal, separate from broker truth. The ticket and chart share this identity. */
|
|
35
|
+
export declare function createChartOrderEdit(state: TradingState, context: (id: string, kind: ChartEditKind) => TradingCommandContext): {
|
|
36
|
+
state: import("../contracts/ports.js").ReadonlyValue<Readonly<ChartOrderEdit | undefined>>;
|
|
37
|
+
begin(id: string, kind: ChartEditKind, binding: TradingChartBinding, options?: ChartEditOptions): Readonly<ChartOrderEdit>;
|
|
38
|
+
propose(price: number, levels?: {
|
|
39
|
+
entry: number;
|
|
40
|
+
instrument: InstrumentInfo;
|
|
41
|
+
maximum?: number;
|
|
42
|
+
}): Readonly<ChartOrderEdit>;
|
|
43
|
+
/** Ticket handoff for an order proposal; `undefined` ends it (closed or settled ticket). */
|
|
44
|
+
sync(order: Readonly<PreOrder | Order>, phase: "reviewing" | "sending" | undefined): void;
|
|
45
|
+
syncPosition(brackets: Brackets): void;
|
|
46
|
+
clear: () => void;
|
|
47
|
+
clearIf: (editToken: number | undefined) => void;
|
|
48
|
+
assertCurrent: (edit: Readonly<ChartOrderEdit>) => void;
|
|
49
|
+
destroy(): void;
|
|
50
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ClosePositionPreviewResult } from "../contracts/broker.js";
|
|
2
|
+
import type { TradingCommandResult } from "./command-coordinator.js";
|
|
3
|
+
import { type CloseRequest, type PositionCommandServices } from "./position-commands.js";
|
|
4
|
+
import type { TradingCommandServices } from "./trading-commands.js";
|
|
5
|
+
/** What closing uses: position commands plus the broker close-preview extension and custom close dialog. */
|
|
6
|
+
export type CloseCommandServices = PositionCommandServices & Pick<TradingCommandServices, "closePreview" | "customClose">;
|
|
7
|
+
/** Close reviews (broker extension or custom dialog) and the close command that consumes them. */
|
|
8
|
+
export declare class CloseCommands {
|
|
9
|
+
private readonly services;
|
|
10
|
+
private readonly closePreviews;
|
|
11
|
+
constructor(services: CloseCommandServices, nextSequence: () => number);
|
|
12
|
+
clear(): void;
|
|
13
|
+
private rememberClose;
|
|
14
|
+
private validateCloseContext;
|
|
15
|
+
previewClose(request: CloseRequest): Promise<{
|
|
16
|
+
token: string;
|
|
17
|
+
preview: Readonly<ClosePositionPreviewResult>;
|
|
18
|
+
}>;
|
|
19
|
+
confirmCustomClose(request: CloseRequest): Promise<{
|
|
20
|
+
approved: boolean;
|
|
21
|
+
token?: string;
|
|
22
|
+
} | undefined>;
|
|
23
|
+
close(request: CloseRequest): Promise<TradingCommandResult>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { InstrumentInfo } from "../contracts/broker.js";
|
|
2
|
+
import type { CloseRequest } from "./position-commands.js";
|
|
3
|
+
import type { TradingCommands } from "./trading-commands.js";
|
|
4
|
+
import type { TradingState } from "./trading-state.js";
|
|
5
|
+
import type { DialogCoordinator } from "./dialog-coordinator.js";
|
|
6
|
+
import type { CapabilityPolicy } from "./capabilities.js";
|
|
7
|
+
/** Confirmation, partial amount and preview orchestration; commands retain broker write ownership. */
|
|
8
|
+
export declare function createCloseFlow(services: {
|
|
9
|
+
readonly state: TradingState;
|
|
10
|
+
readonly dialogs: DialogCoordinator;
|
|
11
|
+
commands(): TradingCommands | undefined;
|
|
12
|
+
symbolPolicy(symbol: string): CapabilityPolicy;
|
|
13
|
+
symbolInfo(symbol: string): Promise<InstrumentInfo>;
|
|
14
|
+
}): (request: CloseRequest) => Promise<import("./command-coordinator.js").TradingCommandResult | undefined>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TradingState } from "./trading-state.js";
|
|
2
|
+
export interface AccountContext {
|
|
3
|
+
readonly accountId: string;
|
|
4
|
+
readonly generation: number;
|
|
5
|
+
}
|
|
6
|
+
export type TradingEntityKind = "order" | "position" | "individualPosition";
|
|
7
|
+
interface EntityStores {
|
|
8
|
+
order: TradingState["orders"];
|
|
9
|
+
position: TradingState["positions"];
|
|
10
|
+
individualPosition: TradingState["individualPositions"];
|
|
11
|
+
}
|
|
12
|
+
export declare function entityStore<K extends TradingEntityKind>(state: TradingState, kind: K): EntityStores[K];
|
|
13
|
+
export declare function isLiveContext(state: TradingState, context: AccountContext): boolean;
|
|
14
|
+
export declare function assertLiveContext(state: TradingState, context: AccountContext): void;
|
|
15
|
+
export declare function assertRevision(state: TradingState, kind: TradingEntityKind, id: string, revision: number | undefined): void;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { TradingClock } from "../contracts/ports.js";
|
|
2
|
+
import { EntityStore } from "./entity-store.js";
|
|
3
|
+
export type CommandOutcome = "confirmed" | "changed" | "unconfirmed";
|
|
4
|
+
export interface TradingCommandResult {
|
|
5
|
+
readonly commandId: string;
|
|
6
|
+
readonly outcome: CommandOutcome;
|
|
7
|
+
readonly entityIds: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
export interface PendingOperation {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly keys: readonly string[];
|
|
12
|
+
readonly stage: "dispatched" | "awaitingUpdate" | "confirmed" | "changed" | "rejected" | "unconfirmed";
|
|
13
|
+
readonly dispatchedAt: number;
|
|
14
|
+
readonly entityIds: readonly string[];
|
|
15
|
+
readonly error?: string;
|
|
16
|
+
/**
|
|
17
|
+
* True while an unconfirmed operation is still being reconciled after its deadline. An `unconfirmed` record whose
|
|
18
|
+
* reconciliation has ended is unresolved: only the user can decide what happened.
|
|
19
|
+
*/
|
|
20
|
+
readonly reconciling?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface CommandMatch {
|
|
23
|
+
readonly outcome: "confirmed" | "changed";
|
|
24
|
+
readonly entityIds: readonly string[];
|
|
25
|
+
}
|
|
26
|
+
export interface CommandSpec<T> {
|
|
27
|
+
readonly keys: readonly string[];
|
|
28
|
+
readonly dispatch: () => Promise<T>;
|
|
29
|
+
readonly match: (result: T | undefined, accepted: boolean) => CommandMatch | undefined;
|
|
30
|
+
readonly refresh: () => void;
|
|
31
|
+
readonly dispose?: () => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Transport acceptance and a matching authoritative update are separate conditions. The deadline only changes what
|
|
35
|
+
* callers are told: an unconfirmed operation keeps its keys and keeps asking the broker to reconcile for a bounded
|
|
36
|
+
* window, so a late match or rejection still settles its record and a repeat action cannot race it.
|
|
37
|
+
*/
|
|
38
|
+
export declare class CommandCoordinator {
|
|
39
|
+
private readonly clock;
|
|
40
|
+
/** Milliseconds from dispatch until an operation without a matching update is unconfirmed. */
|
|
41
|
+
private readonly deadline;
|
|
42
|
+
/** Milliseconds after the deadline that an unconfirmed operation keeps reconciling and holds its keys; 0 ends it at the deadline. */
|
|
43
|
+
private readonly reconcileWindow;
|
|
44
|
+
readonly pending: EntityStore<PendingOperation>;
|
|
45
|
+
private readonly operations;
|
|
46
|
+
private readonly locks;
|
|
47
|
+
private sequence;
|
|
48
|
+
private disposed;
|
|
49
|
+
constructor(clock: TradingClock,
|
|
50
|
+
/** Milliseconds from dispatch until an operation without a matching update is unconfirmed. */
|
|
51
|
+
deadline?: number,
|
|
52
|
+
/** Milliseconds after the deadline that an unconfirmed operation keeps reconciling and holds its keys; 0 ends it at the deadline. */
|
|
53
|
+
reconcileWindow?: number);
|
|
54
|
+
execute<T>(spec: CommandSpec<T>): Promise<TradingCommandResult>;
|
|
55
|
+
executeBatch(specs: readonly Omit<CommandSpec<void>, "dispatch">[], dispatch: () => Promise<void>): Promise<PromiseSettledResult<TradingCommandResult>[]>;
|
|
56
|
+
changed(): void;
|
|
57
|
+
private evaluate;
|
|
58
|
+
private settle;
|
|
59
|
+
private reject;
|
|
60
|
+
/** A transport rejection after the deadline corrects the unconfirmed record; the completion keeps its outcome. */
|
|
61
|
+
private rejectLate;
|
|
62
|
+
/** Asks the broker to reconcile again with backoff until a match, a rejection or the end of the reconcile period. */
|
|
63
|
+
private followUp;
|
|
64
|
+
private finishReconciling;
|
|
65
|
+
private unlock;
|
|
66
|
+
private dispose;
|
|
67
|
+
private evict;
|
|
68
|
+
/** Old-generation operations can never match, so their listeners are released at once. */
|
|
69
|
+
suspend(): void;
|
|
70
|
+
destroy(): void;
|
|
71
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { EntityReader } from "./entity-store.js";
|
|
2
|
+
import type { PendingOperation } from "./command-coordinator.js";
|
|
3
|
+
/**
|
|
4
|
+
* What an unconfirmed command has become: still `checking` with the broker, `unresolved` once reconciliation ended
|
|
5
|
+
* without evidence, or a final broker outcome.
|
|
6
|
+
*/
|
|
7
|
+
export type CommandFollowState = {
|
|
8
|
+
readonly kind: "checking";
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: "unresolved";
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: "confirmed";
|
|
13
|
+
readonly entityIds: readonly string[];
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: "changed";
|
|
16
|
+
readonly entityIds: readonly string[];
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: "rejected";
|
|
19
|
+
readonly error?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function commandFollowState(record: Readonly<PendingOperation> | undefined): CommandFollowState;
|
|
22
|
+
/**
|
|
23
|
+
* Reports an unconfirmed command's state now and on each change of its pending record, then stops by itself once the
|
|
24
|
+
* state is final (anything but `checking`). The returned dispose stops it earlier; callers fence their own lifetime.
|
|
25
|
+
*/
|
|
26
|
+
export declare function followCommand(pending: EntityReader<PendingOperation>, commandId: string, listener: (state: CommandFollowState) => void): () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Calls `onAccepted` once when the broker acknowledges a command holding `key` that was dispatched at or after
|
|
29
|
+
* `since`. A key is held by one command at a time, so a caller that has not yet received its command ID can still
|
|
30
|
+
* tell its own command from earlier ones. Acknowledgement is transport only: it never means confirmed.
|
|
31
|
+
*/
|
|
32
|
+
export declare function watchAcceptance(pending: EntityReader<PendingOperation>, key: string, since: number, onAccepted: () => void): () => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Kinds whose commands serialize per entity. Matches bracket parent kinds. */
|
|
2
|
+
export type CommandEntityKind = "order" | "position" | "individualPosition";
|
|
3
|
+
/** The only place coordinator lock keys are spelled; commands sharing a key never run concurrently. */
|
|
4
|
+
export declare const commandKeys: {
|
|
5
|
+
entity: (kind: CommandEntityKind, id: string) => string;
|
|
6
|
+
order: (id: string) => string;
|
|
7
|
+
position: (id: string, individual?: boolean) => string;
|
|
8
|
+
/** Account/symbol placements, including fallback closes that place an opposite order. */
|
|
9
|
+
place: (accountId: string, symbol: string) => string;
|
|
10
|
+
leverage: (accountId: string, symbol: string) => string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OrderType, Side } from "../contracts/broker.js";
|
|
2
|
+
/** A pending order at a chart price: buying below the market is a limit, above it a stop; selling mirrors that. */
|
|
3
|
+
export declare function contextOrderType(side: Side, price: number, market: number): OrderType.Limit | OrderType.Stop;
|
|
4
|
+
export declare const contextOrderTypeName: (type: OrderType.Limit | OrderType.Stop) => "Limit" | "Stop";
|
|
5
|
+
/**
|
|
6
|
+
* The one wording of a chart-price trade item: "Buy" for a market order, otherwise
|
|
7
|
+
* "Buy [qty] [SYMBOL] @ 99.40 Limit" (reference wording; quantity and symbol only where the menu shows them).
|
|
8
|
+
*/
|
|
9
|
+
export declare function contextTradeLabel(input: {
|
|
10
|
+
readonly side: Side;
|
|
11
|
+
readonly qty?: number;
|
|
12
|
+
readonly symbol?: string;
|
|
13
|
+
readonly formattedPrice?: string;
|
|
14
|
+
readonly type: OrderType;
|
|
15
|
+
}): string;
|
|
16
|
+
export declare function markDefaultTradeAction(action: object, side: Side): void;
|
|
17
|
+
export declare function defaultTradeActionSide(action: object): Side | undefined;
|
|
18
|
+
export declare function markTradingSettingsAction(action: object): void;
|
|
19
|
+
export declare function isTradingSettingsAction(action: object): boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { TradingChartBinding } from "../contracts/ports.js";
|
|
2
|
+
import type { ClosePositionPreviewResult, InstrumentInfo, LeverageInfo, LeverageInfoParams } from "../contracts/broker.js";
|
|
3
|
+
import type { TradingCommandContext } from "./trading-commands.js";
|
|
4
|
+
import type { Brackets, IndividualPosition, OrderTicketFocusControl, Position, PreOrder } from "../contracts/broker.js";
|
|
5
|
+
import { ValueStore } from "./value-store.js";
|
|
6
|
+
export type TradingDialogRequest = {
|
|
7
|
+
kind: "confirm";
|
|
8
|
+
title: string;
|
|
9
|
+
content: string | string[];
|
|
10
|
+
mainButtonText?: string;
|
|
11
|
+
cancelButtonText?: string;
|
|
12
|
+
showDisableConfirmationsCheckbox?: boolean;
|
|
13
|
+
/** Symbol shown with its logo when the matching show_symbol_logo_in_* feature is enabled. */
|
|
14
|
+
symbol?: {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly logo: "cancel" | "close";
|
|
17
|
+
};
|
|
18
|
+
} | {
|
|
19
|
+
kind: "message";
|
|
20
|
+
title: string;
|
|
21
|
+
content: string;
|
|
22
|
+
html: boolean;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "order";
|
|
25
|
+
order: PreOrder;
|
|
26
|
+
focus?: OrderTicketFocusControl;
|
|
27
|
+
binding?: TradingChartBinding;
|
|
28
|
+
} | {
|
|
29
|
+
kind: "position";
|
|
30
|
+
position: Position | IndividualPosition;
|
|
31
|
+
brackets: Brackets;
|
|
32
|
+
focus?: OrderTicketFocusControl;
|
|
33
|
+
} | {
|
|
34
|
+
kind: "properties";
|
|
35
|
+
} | {
|
|
36
|
+
kind: "closeAmount";
|
|
37
|
+
position: Position | IndividualPosition;
|
|
38
|
+
instrument: InstrumentInfo;
|
|
39
|
+
preview: boolean;
|
|
40
|
+
nativeFullClose?: boolean;
|
|
41
|
+
/** `closePositionCancelsOrders`: the broker also cancels this position's working brackets. */
|
|
42
|
+
cancelsBrackets?: boolean;
|
|
43
|
+
} | {
|
|
44
|
+
kind: "leverage";
|
|
45
|
+
context: TradingCommandContext;
|
|
46
|
+
params: LeverageInfoParams;
|
|
47
|
+
info: LeverageInfo;
|
|
48
|
+
} | {
|
|
49
|
+
kind: "closePreview";
|
|
50
|
+
preview: ClosePositionPreviewResult;
|
|
51
|
+
};
|
|
52
|
+
/** Presentation settles a dialog once; broker operation ownership stays with the invoking path. */
|
|
53
|
+
export declare class DialogCoordinator {
|
|
54
|
+
readonly current: ValueStore<{
|
|
55
|
+
readonly id: number;
|
|
56
|
+
readonly request: TradingDialogRequest;
|
|
57
|
+
} | undefined>;
|
|
58
|
+
private readonly queue;
|
|
59
|
+
private sequence;
|
|
60
|
+
private disposed;
|
|
61
|
+
request(request: Exclude<TradingDialogRequest, {
|
|
62
|
+
kind: "closeAmount";
|
|
63
|
+
}>, signal?: AbortSignal): Promise<boolean>;
|
|
64
|
+
requestAmount(request: Extract<TradingDialogRequest, {
|
|
65
|
+
kind: "closeAmount";
|
|
66
|
+
}>): Promise<number | undefined>;
|
|
67
|
+
private enqueue;
|
|
68
|
+
respond(id: number, approved: boolean): void;
|
|
69
|
+
respondAmount(id: number, amount: number): void;
|
|
70
|
+
cancelAll(): void;
|
|
71
|
+
private publish;
|
|
72
|
+
destroy(): void;
|
|
73
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TradingDisplaySettings, TradingLineAlignment, TradingProfitDisplayMode, TradingSettingsPort } from "../contracts/ports.js";
|
|
2
|
+
export declare function isProfitDisplayMode(value: unknown): value is TradingProfitDisplayMode;
|
|
3
|
+
export declare function isLineAlignment(value: unknown): value is TradingLineAlignment;
|
|
4
|
+
/** Scoped user choices; storage failures never turn a valid UI choice into a trading failure. */
|
|
5
|
+
export declare function createDisplayPreferences(storage: TradingSettingsPort, namespace: string, initial?: Partial<TradingDisplaySettings>): {
|
|
6
|
+
state: import("../contracts/ports.js").ReadonlyValue<Readonly<TradingDisplaySettings>>;
|
|
7
|
+
error: import("../contracts/ports.js").ReadonlyValue<Readonly<string | undefined>>;
|
|
8
|
+
update(input: Partial<TradingDisplaySettings>): void;
|
|
9
|
+
destroy(): void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Dispose } from '../contracts/ports.js';
|
|
2
|
+
/** Reverse acquisition order; a failing disposer never prevents the remaining cleanup. */
|
|
3
|
+
export declare class DisposalScope {
|
|
4
|
+
private readonly disposers;
|
|
5
|
+
private disposed;
|
|
6
|
+
own(dispose: Dispose): Dispose;
|
|
7
|
+
destroy(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Dispose } from "../contracts/ports.js";
|
|
2
|
+
export interface EntityChange {
|
|
3
|
+
readonly added: readonly string[];
|
|
4
|
+
readonly updated: readonly string[];
|
|
5
|
+
readonly removed: readonly string[];
|
|
6
|
+
readonly revision: number;
|
|
7
|
+
}
|
|
8
|
+
export interface EntityReader<T> {
|
|
9
|
+
ids(): readonly string[];
|
|
10
|
+
get(id: string): Readonly<T> | undefined;
|
|
11
|
+
revision(id: string): number;
|
|
12
|
+
subscribeChanges(listener: (change: EntityChange) => void): Dispose;
|
|
13
|
+
}
|
|
14
|
+
/** Keyed immutable state: a single update never scans or copies unrelated entities. */
|
|
15
|
+
/** A snapshot row the store refused; its ID (when readable) keeps its previous value. */
|
|
16
|
+
export interface QuarantinedRow {
|
|
17
|
+
readonly id?: string;
|
|
18
|
+
readonly message: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class EntityStore<T extends {
|
|
21
|
+
id: string;
|
|
22
|
+
}> implements EntityReader<T> {
|
|
23
|
+
private readonly validate;
|
|
24
|
+
private readonly accept;
|
|
25
|
+
private readonly entities;
|
|
26
|
+
private readonly revisions;
|
|
27
|
+
private readonly listeners;
|
|
28
|
+
private readonly before;
|
|
29
|
+
private idsSnapshot;
|
|
30
|
+
private sequence;
|
|
31
|
+
private depth;
|
|
32
|
+
private disposed;
|
|
33
|
+
constructor(validate: (entity: T) => void, accept?: (next: T, old: Readonly<T> | undefined) => boolean);
|
|
34
|
+
ids(): readonly string[];
|
|
35
|
+
get(id: string): Readonly<T> | undefined;
|
|
36
|
+
revision(id: string): number;
|
|
37
|
+
subscribeChanges(listener: (change: EntityChange) => void): Dispose;
|
|
38
|
+
private record;
|
|
39
|
+
upsert(entity: T, authoritative?: boolean): boolean;
|
|
40
|
+
patch(id: string, changes: Partial<T>): boolean;
|
|
41
|
+
remove(id: string): boolean;
|
|
42
|
+
transaction(operation: () => void): void;
|
|
43
|
+
/**
|
|
44
|
+
* Replaces the snapshot atomically: one malformed row rejects the whole read. With `quarantine`, invalid rows
|
|
45
|
+
* are set aside instead: valid rows commit, a quarantined ID keeps its previous value, and each failure is
|
|
46
|
+
* returned; a read with rows but none valid still fails as a whole.
|
|
47
|
+
*/
|
|
48
|
+
replace(entities: readonly T[], options?: {
|
|
49
|
+
readonly quarantine?: boolean;
|
|
50
|
+
readonly accept?: (entity: T) => boolean;
|
|
51
|
+
/** IDs quarantined by the previous read: quarantined again, they are removed instead of kept. */
|
|
52
|
+
readonly expire?: ReadonlySet<string>;
|
|
53
|
+
}): readonly QuarantinedRow[];
|
|
54
|
+
private publish;
|
|
55
|
+
destroy(): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OrderStatus } from '../contracts/broker.js';
|
|
2
|
+
import type { Execution, IndividualPosition, Order, Position } from '../contracts/broker.js';
|
|
3
|
+
export declare const terminalStatuses: Set<OrderStatus>;
|
|
4
|
+
export declare function finite(value: unknown, name: string): asserts value is number;
|
|
5
|
+
export declare function validateOrder(entity: Order): void;
|
|
6
|
+
export declare function acceptOrder(next: Order, old?: Readonly<Order>): boolean;
|
|
7
|
+
export declare function validatePosition(entity: Position): void;
|
|
8
|
+
export declare function validateIndividualPosition(entity: IndividualPosition): void;
|
|
9
|
+
export declare function validateExecution(entity: Execution): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type TradingErrorCode = 'invalid-input' | 'unsupported' | 'configuration' | 'disconnected' | 'stale-context' | 'operation-pending' | 'broker-rejected' | 'broker-unavailable' | 'asset-unavailable' | 'abi-mismatch' | 'disposed';
|
|
2
|
+
export declare class TradingError extends Error {
|
|
3
|
+
readonly code: TradingErrorCode;
|
|
4
|
+
static disposed(message?: string): TradingError;
|
|
5
|
+
static accountChanged(): TradingError;
|
|
6
|
+
static disconnected(): TradingError;
|
|
7
|
+
static brokerUnavailable(): TradingError;
|
|
8
|
+
static positionChanged(): TradingError;
|
|
9
|
+
constructor(code: TradingErrorCode, message: string, options?: ErrorOptions);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Maps what an adapter threw to a `TradingError`. A `BrokerRejection` shape (`{ code, message }`, as a plain
|
|
13
|
+
* object or on an Error) keeps the adapter's user-safe message; anything else gets the generic fallback wording.
|
|
14
|
+
*/
|
|
15
|
+
export declare function brokerRejectionError(cause: unknown, fallback: string): TradingError;
|
|
16
|
+
/** Most characters of a broker-supplied message shown to users. */
|
|
17
|
+
export declare const MAX_BROKER_MESSAGE = 240;
|
|
18
|
+
/** One line of plain text: control characters and line breaks become spaces, and long text is cut with an ellipsis. */
|
|
19
|
+
export declare function boundMessage(text: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* The text a user may see for a failure: the platform's own wording for a `TradingError`, the broker's bounded
|
|
22
|
+
* message for a `BrokerRejection`, and `fallback` for anything else (raw provider errors never reach the UI).
|
|
23
|
+
*/
|
|
24
|
+
export declare function userMessage(cause: unknown, fallback: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Execution } from "../contracts/broker.js";
|
|
2
|
+
import type { TradingClock, Dispose } from "../contracts/ports.js";
|
|
3
|
+
import { EntityStore } from "./entity-store.js";
|
|
4
|
+
/** Execution snapshots are symbol-scoped; refreshing one symbol never replaces another. */
|
|
5
|
+
export declare function createExecutionDemand(target: EntityStore<Execution>, load: (symbol: string) => Promise<Execution[]>, clock: TradingClock, report: (cause: unknown) => void, deadline?: number): {
|
|
6
|
+
acquire(symbol: string): Dispose;
|
|
7
|
+
push(execution: Execution): void;
|
|
8
|
+
suspend(clear?: boolean): void;
|
|
9
|
+
resume(): void;
|
|
10
|
+
destroy(): void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TradingSoundPort } from "../contracts/ports.js";
|
|
2
|
+
type AudioContextConstructor = new () => AudioContext;
|
|
3
|
+
/**
|
|
4
|
+
* Default execution sound: one short tone through Web Audio. Nothing is created until the first sound, and an
|
|
5
|
+
* environment without Web Audio (or one that refuses it) stays silent rather than failing a trading update.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createDefaultExecutionSound(audio?: AudioContextConstructor | undefined): TradingSoundPort & {
|
|
8
|
+
close(): void;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Brackets, ExitLevel, QuantityMetainfo } from "../contracts/broker.js";
|
|
2
|
+
/** A UI identity is retained until the broker supplies an authoritative exit-level identity. */
|
|
3
|
+
export declare function legacyExitLevel(brackets: Readonly<Brackets>, quantity: number, id: string): ExitLevel;
|
|
4
|
+
/** The broker minimum need not itself be aligned to its quantity step. */
|
|
5
|
+
export declare function minimumExitQuantity(rules: QuantityMetainfo): number;
|
|
6
|
+
/** Adding a level can reclaim allocation from the last levels, preserving their minimum sizes. */
|
|
7
|
+
export declare function appendExitLevel(current: readonly Readonly<ExitLevel>[], candidate: Readonly<ExitLevel>, parentQuantity: number, rules: QuantityMetainfo, maximum?: number): ExitLevel[];
|
|
8
|
+
/** Removing a level does not expand another level's allocation or mutate broker-owned data. */
|
|
9
|
+
export declare function removeExitLevel(current: readonly Readonly<ExitLevel>[], id: string): ExitLevel[];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ExitLevel, InstrumentInfo, Side } from "../contracts/broker.js";
|
|
2
|
+
/** A dimensionless ratio: every level shares the same instrument and side value per price unit. */
|
|
3
|
+
export declare function exitLevelRewardRisk(levels: readonly Readonly<ExitLevel>[], entry: number | undefined, side: Side, instrument: Pick<InstrumentInfo, "pipSize" | "minTick">): number | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ExitLevel, ExitLevelTemplate, InstrumentInfo, Side } from "../contracts/broker.js";
|
|
2
|
+
export interface ExitTemplateContext {
|
|
3
|
+
readonly entry?: number;
|
|
4
|
+
readonly side: Side;
|
|
5
|
+
readonly instrument: InstrumentInfo;
|
|
6
|
+
readonly equity?: number;
|
|
7
|
+
/** Account-currency value of one pip per quantity unit, for the order side. */
|
|
8
|
+
readonly pipValue?: number;
|
|
9
|
+
readonly accountCurrency?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resolve template exit levels expressed as pips, parent-price percentage, money or equity percentage into prices.
|
|
13
|
+
* An explicit price wins. A value that cannot be resolved (no entry, equity or pip value) becomes NaN so the
|
|
14
|
+
* ticket shows it as invalid instead of inventing a price. Template-only fields are not forwarded to the broker.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveExitLevelTemplates(levels: readonly Readonly<ExitLevelTemplate>[], context: ExitTemplateContext): ExitLevel[];
|