@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.
- package/CHANGELOG.md +31 -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,21 @@
|
|
|
1
|
+
import { Side } from "../contracts/broker.js";
|
|
2
|
+
import type { Brackets, IndividualPosition, InstrumentInfo, Position, TradingQuotes } from "../contracts/broker.js";
|
|
3
|
+
import type { CapabilityPolicy } from "./capabilities.js";
|
|
4
|
+
/**
|
|
5
|
+
* TP/SL must sit on the profitable/protective side of `reference`: the entry for orders, the current
|
|
6
|
+
* price for positions (see `positionProtectionReference`), named in the message as `referenceName`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function protectionDirectionError(brackets: Readonly<Brackets>, side: Side, reference: number | undefined, referenceName?: string): string | undefined;
|
|
9
|
+
/** Validates broker protection inputs; never creates, activates or cancels broker children locally. */
|
|
10
|
+
export declare function normalizeProtection(input: Brackets, quantity: number, instrument: InstrumentInfo, policy: CapabilityPolicy, maxLevels?: number, target?: "position" | "order"): Brackets;
|
|
11
|
+
/** The protection fields of an order or position, in one place. */
|
|
12
|
+
export declare const PROTECTION_FIELDS: readonly ["takeProfit", "stopLoss", "guaranteedStop", "trailingStopPips", "exitLevels"];
|
|
13
|
+
export type ProtectionFieldName = (typeof PROTECTION_FIELDS)[number];
|
|
14
|
+
/** Whether a request leaves every protection field it names at its current value. */
|
|
15
|
+
export declare function protectionUnchanged(current: Readonly<Brackets>, requested: Readonly<Brackets>): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The one validation for protection on a position or individual position: normalise to the instrument and policy,
|
|
18
|
+
* check TP/SL sit on the right side of the price the position would close at, and check edit permissions.
|
|
19
|
+
* Returns the normalised brackets.
|
|
20
|
+
*/
|
|
21
|
+
export declare function validatePositionProtection(position: Readonly<Position | IndividualPosition>, brackets: Brackets, instrument: InstrumentInfo, policy: CapabilityPolicy, quotes: TradingQuotes | undefined, maxLevels: number | undefined, individual: boolean): Brackets;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { InstrumentInfo, PipValues, Side } from "../contracts/broker.js";
|
|
2
|
+
export type QuantityInputMode = "units" | "currency" | "percentage" | "riskMoney" | "riskPercentage";
|
|
3
|
+
export interface QuantityInputContext {
|
|
4
|
+
readonly instrument: InstrumentInfo;
|
|
5
|
+
readonly price?: number;
|
|
6
|
+
readonly equity?: number;
|
|
7
|
+
readonly accountCurrency?: string;
|
|
8
|
+
readonly side?: Side;
|
|
9
|
+
readonly stop?: number;
|
|
10
|
+
readonly pipValues?: PipValues;
|
|
11
|
+
readonly riskAllowed?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function isQuantityInputMode(value: string): value is QuantityInputMode;
|
|
14
|
+
export declare function isRiskQuantityMode(mode: QuantityInputMode): boolean;
|
|
15
|
+
export declare function needsQuantityEquity(mode: QuantityInputMode): boolean;
|
|
16
|
+
export declare function quantityModeAvailable(mode: QuantityInputMode, context: QuantityInputContext): boolean;
|
|
17
|
+
/** Selection can start a missing equity subscription while preserving the current units. */
|
|
18
|
+
export declare function quantityModeSelectable(mode: QuantityInputMode, context: QuantityInputContext): boolean;
|
|
19
|
+
export declare function quantityInputValue(qty: number, mode: QuantityInputMode, context: QuantityInputContext): number | undefined;
|
|
20
|
+
/** Converted sizes floor to the broker step. No account/instrument FX rate is inferred. */
|
|
21
|
+
export declare function quantityFromInput(value: number, mode: QuantityInputMode, context: QuantityInputContext): number | undefined;
|
|
22
|
+
export interface SizedQuantityInput {
|
|
23
|
+
readonly mode: QuantityInputMode;
|
|
24
|
+
readonly fallbackMode?: QuantityInputMode;
|
|
25
|
+
readonly disabled: boolean;
|
|
26
|
+
/** The amount typed in a non-unit mode. */
|
|
27
|
+
readonly entered?: number;
|
|
28
|
+
/** A units quantity waiting to be shown in `mode` once its inputs (price, equity) are known. */
|
|
29
|
+
readonly pending?: {
|
|
30
|
+
readonly mode: QuantityInputMode;
|
|
31
|
+
readonly qty: number;
|
|
32
|
+
};
|
|
33
|
+
/** The draft's canonical quantity in units. */
|
|
34
|
+
readonly qty: number;
|
|
35
|
+
/** The last positive units quantity, restored when returning to units. */
|
|
36
|
+
readonly lastUnits: number;
|
|
37
|
+
readonly context: QuantityInputContext;
|
|
38
|
+
}
|
|
39
|
+
/** What the quantity field applies; absent fields mean no change. `sizing` may be NaN (not yet sizeable). */
|
|
40
|
+
export interface SizedQuantityResult {
|
|
41
|
+
/** A units quantity to write as the user's own quantity. */
|
|
42
|
+
readonly units?: number;
|
|
43
|
+
/** A quantity derived from a cash or percentage amount. */
|
|
44
|
+
readonly sizing?: number;
|
|
45
|
+
readonly entered?: number;
|
|
46
|
+
readonly clearPending: boolean;
|
|
47
|
+
readonly lastUnits?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Keeps a cash or percentage amount sized as entry price and equity change; units stay canonical. Returning to
|
|
51
|
+
* units from a risk fallback restores the last positive quantity, writing it only when it differs.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveSizedQuantity(input: SizedQuantityInput): SizedQuantityResult;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TradingClock } from "../contracts/ports.js";
|
|
2
|
+
/** Owns account-scoped reads, including providers that never settle. */
|
|
3
|
+
export declare class ReadCoordinator {
|
|
4
|
+
private readonly clock;
|
|
5
|
+
private readonly generation;
|
|
6
|
+
private readonly deadline;
|
|
7
|
+
private alive;
|
|
8
|
+
private readonly pending;
|
|
9
|
+
constructor(clock: TradingClock, generation: () => number, deadline?: number);
|
|
10
|
+
read<T>(load: () => T | Promise<T>, epoch?: number): Promise<T>;
|
|
11
|
+
invalidate(): void;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
private stale;
|
|
14
|
+
private closed;
|
|
15
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReadonlyValue } from "../contracts/ports.js";
|
|
2
|
+
import type { EntityReader, EntityStore } from "./entity-store.js";
|
|
3
|
+
export declare function entityReader<T extends {
|
|
4
|
+
id: string;
|
|
5
|
+
}>(store: EntityStore<T>): EntityReader<T>;
|
|
6
|
+
export declare function valueReader<T>(store: ReadonlyValue<T>): ReadonlyValue<T>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InstrumentInfo } from "../contracts/broker.js";
|
|
2
|
+
export declare function relativePriceTicks(price: number | undefined, anchor: number | undefined, instrument: InstrumentInfo): number | undefined;
|
|
3
|
+
/** A tick offset is a generated price. Directly typed prices still pass through unchanged. */
|
|
4
|
+
export declare function priceFromTicks(ticks: number, anchor: number | undefined, instrument: InstrumentInfo, kind: "limit" | "stop"): number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TradingSession } from "./session.js";
|
|
2
|
+
type ReviewSession = Pick<TradingSession, "host" | "confirmationRequired" | "hasCustomOrderDialog" | "hasCustomPositionDialog" | "ticketSettings" | "symbolPolicy">;
|
|
3
|
+
/**
|
|
4
|
+
* Chart Buy/Sell and price moves place orders directly only when the user chose silent placement
|
|
5
|
+
* and nothing forces a dialog.
|
|
6
|
+
*/
|
|
7
|
+
export declare function placesOrdersWithoutTicket(session: ReviewSession): boolean;
|
|
8
|
+
/** Chart TP/SL edits on positions skip the protection dialog under the same rule, with the broker's position dialog. */
|
|
9
|
+
export declare function editsPositionsWithoutDialog(session: ReviewSession): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The broker previews this ticket: it supports previews for placing (or modifying) on the symbol and the
|
|
12
|
+
* user kept "Show order preview" on. Without broker support the preference has no effect, as in the reference.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ticketShowsPreview(session: ReviewSession, symbol: string, modifying: boolean): boolean;
|
|
15
|
+
/** The ticket sends without a review step unless confirmation is forced or the broker previews the order. */
|
|
16
|
+
export declare function ticketSkipsReview(session: ReviewSession, symbol: string, modifying: boolean): boolean;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { TradingSessionOptions } from '../contracts/ports.js';
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { ActionMetaInfo, InstrumentInfo, Order, OrderTicketSettings, PreOrder, TradeContext } from "../contracts/broker.js";
|
|
2
|
+
import type { TradingChartBinding } from "../contracts/ports.js";
|
|
3
|
+
import type { LeverageRequest } from "./leverage-commands.js";
|
|
4
|
+
import { type Tradability } from "./tradability.js";
|
|
5
|
+
import type { AccountManagerInfo, AccountMetainfo } from "../contracts/broker.js";
|
|
6
|
+
import type { TradingSessionOptions } from "./session-types.js";
|
|
7
|
+
import { TradingCommands } from "./trading-commands.js";
|
|
8
|
+
/** One headless session owns exactly one broker, independent of chart count or UI mounts. */
|
|
9
|
+
export declare function createTradingSession(options: TradingSessionOptions): {
|
|
10
|
+
chartEdits: {
|
|
11
|
+
state: import("../contracts/ports.js").ReadonlyValue<Readonly<import("./chart-order-edit.js").ChartOrderEdit | undefined>>;
|
|
12
|
+
begin(id: string, kind: import("./chart-order-edit.js").ChartEditKind, binding: TradingChartBinding, options?: import("./chart-order-edit.js").ChartEditOptions): Readonly<import("./chart-order-edit.js").ChartOrderEdit>;
|
|
13
|
+
propose(price: number, levels?: {
|
|
14
|
+
entry: number;
|
|
15
|
+
instrument: InstrumentInfo;
|
|
16
|
+
maximum?: number;
|
|
17
|
+
}): Readonly<import("./chart-order-edit.js").ChartOrderEdit>;
|
|
18
|
+
sync(order: Readonly<PreOrder | Order>, phase: "reviewing" | "sending" | undefined): void;
|
|
19
|
+
syncPosition(brackets: import("../contracts/broker.js").Brackets): void;
|
|
20
|
+
clear: () => void;
|
|
21
|
+
clearIf: (editToken: number | undefined) => void;
|
|
22
|
+
assertCurrent: (edit: Readonly<import("./chart-order-edit.js").ChartOrderEdit>) => void;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
};
|
|
25
|
+
hasCustomPositionDialog: boolean;
|
|
26
|
+
hasCustomOrderDialog: boolean;
|
|
27
|
+
confirmationRequired: boolean;
|
|
28
|
+
ticketSettings: import("../contracts/ports.js").ReadonlyValue<Readonly<OrderTicketSettings>>;
|
|
29
|
+
displaySettings: import("../contracts/ports.js").ReadonlyValue<Readonly<import("../contracts/ports.js").TradingDisplaySettings>>;
|
|
30
|
+
displaySettingsError: import("../contracts/ports.js").ReadonlyValue<Readonly<string | undefined>>;
|
|
31
|
+
/** A mounted UI routes `showTradingProperties` to its host's settings page; the latest registration wins. */
|
|
32
|
+
setSettingsOpener(open: () => boolean): () => void;
|
|
33
|
+
updateDisplaySettings: (input: Partial<import("../contracts/ports.js").TradingDisplaySettings>) => void;
|
|
34
|
+
preferences: Readonly<{
|
|
35
|
+
get(name: string): string | undefined;
|
|
36
|
+
set(name: string, value: string): void;
|
|
37
|
+
remove(name: string): void;
|
|
38
|
+
}>;
|
|
39
|
+
features: Readonly<Record<"chart_crosshair_menu" | "open_account_manager" | "trading_notifications" | "show_trading_notifications_history" | "always_pass_called_order_to_modify" | "always_require_order_confirmation" | "trading_account_manager" | "right_toolbar" | "order_panel" | "order_info" | "buy_sell_buttons" | "broker_button" | "show_order_panel_on_start" | "order_panel_close_button" | "order_panel_undock" | "chart_hide_close_position_button" | "chart_hide_close_order_button" | "dom_widget" | "dom_raw_volume_values" | "hide_right_toolbar" | "hide_right_toolbar_tabs" | "show_symbol_logo_in_account_manager" | "show_symbol_logo_in_close_position_dialog" | "show_symbol_logo_in_cancel_order_dialog" | "prefer_symbol_name_over_fullname" | "static_dom" | "show_buy_sell_buttons_on_unsupported_resolution", boolean>>;
|
|
40
|
+
host: import("../contracts/broker.js").IBrokerConnectionAdapterHost;
|
|
41
|
+
ready: Promise<void>;
|
|
42
|
+
clock: Readonly<{
|
|
43
|
+
now: () => number;
|
|
44
|
+
setTimeout: (callback: () => void, milliseconds: number) => unknown;
|
|
45
|
+
clearTimeout: (handle: unknown) => void;
|
|
46
|
+
}>;
|
|
47
|
+
state: Readonly<{
|
|
48
|
+
orders: import("./entity-store.js").EntityReader<Order>;
|
|
49
|
+
history: import("./entity-store.js").EntityReader<Order>;
|
|
50
|
+
positions: import("./entity-store.js").EntityReader<import("../contracts/broker.js").Position>;
|
|
51
|
+
individualPositions: import("./entity-store.js").EntityReader<import("../contracts/broker.js").IndividualPosition>;
|
|
52
|
+
executions: import("./entity-store.js").EntityReader<import("../contracts/broker.js").Execution>;
|
|
53
|
+
tablePL: import("./entity-store.js").EntityReader<import("./trading-state.js").FinancialValue>;
|
|
54
|
+
individualTablePL: import("./entity-store.js").EntityReader<import("./trading-state.js").FinancialValue>;
|
|
55
|
+
balances: import("./entity-store.js").EntityReader<import("../contracts/broker.js").CryptoBalance & {
|
|
56
|
+
id: string;
|
|
57
|
+
}>;
|
|
58
|
+
quotes: import("./entity-store.js").EntityReader<import("../contracts/broker.js").TradingQuotes & {
|
|
59
|
+
id: string;
|
|
60
|
+
}>;
|
|
61
|
+
pipValues: import("./entity-store.js").EntityReader<import("../contracts/broker.js").PipValues & {
|
|
62
|
+
id: string;
|
|
63
|
+
}>;
|
|
64
|
+
connection: import("../contracts/ports.js").ReadonlyValue<Readonly<import("./trading-state.js").ConnectionState>>;
|
|
65
|
+
equity: import("../contracts/ports.js").ReadonlyValue<Readonly<number | undefined>>;
|
|
66
|
+
marginAvailable: import("../contracts/ports.js").ReadonlyValue<Readonly<number | undefined>>;
|
|
67
|
+
}>;
|
|
68
|
+
policy: import("../contracts/ports.js").ReadonlyValue<Readonly<import("./capabilities.js").CapabilityPolicy>>;
|
|
69
|
+
accounts: import("../contracts/ports.js").ReadonlyValue<readonly AccountMetainfo[]>;
|
|
70
|
+
notifications: import("../contracts/ports.js").ReadonlyValue<readonly import("./notification-log.js").TradingNotification[]>;
|
|
71
|
+
dialogs: {
|
|
72
|
+
current: import("../contracts/ports.js").ReadonlyValue<Readonly<{
|
|
73
|
+
readonly id: number;
|
|
74
|
+
readonly request: import("./dialog-coordinator.js").TradingDialogRequest;
|
|
75
|
+
} | undefined>>;
|
|
76
|
+
respond: (id: number, approved: boolean) => void;
|
|
77
|
+
respondAmount: (id: number, amount: number) => void;
|
|
78
|
+
};
|
|
79
|
+
readonly commands: TradingCommands;
|
|
80
|
+
readonly accountManagerInfo: AccountManagerInfo | undefined;
|
|
81
|
+
pending: import("./entity-store.js").EntityReader<import("./command-coordinator.js").PendingOperation>;
|
|
82
|
+
datasets: {
|
|
83
|
+
orders: import("../contracts/ports.js").ReadonlyValue<Readonly<import("./snapshot-dataset.js").DatasetStatus>>;
|
|
84
|
+
history: import("../contracts/ports.js").ReadonlyValue<Readonly<import("./snapshot-dataset.js").DatasetStatus>>;
|
|
85
|
+
positions: import("../contracts/ports.js").ReadonlyValue<Readonly<import("./snapshot-dataset.js").DatasetStatus>>;
|
|
86
|
+
individualPositions: import("../contracts/ports.js").ReadonlyValue<Readonly<import("./snapshot-dataset.js").DatasetStatus>>;
|
|
87
|
+
};
|
|
88
|
+
symbolInfo: (symbol: string) => Promise<InstrumentInfo>;
|
|
89
|
+
isTradable(symbol: string): Promise<boolean>;
|
|
90
|
+
tradability: (symbol: string) => Promise<Tradability>;
|
|
91
|
+
/** Broker `chartContextMenuActions` for a chart price; the host default is `defaultContextMenuActions`. */
|
|
92
|
+
chartContextMenuActions(context: TradeContext): Promise<readonly ActionMetaInfo[]>;
|
|
93
|
+
symbolPolicy: (symbol?: string) => import("./capabilities.js").CapabilityPolicy;
|
|
94
|
+
symbolOptionsRevision: import("../contracts/ports.js").ReadonlyValue<number>;
|
|
95
|
+
/** tradedGroupConfig.supportAdaptiveLayout (default true): line TP/SL buttons and P&L hide on narrow screens. */
|
|
96
|
+
adaptiveTradingLines: boolean;
|
|
97
|
+
/** Editability for an existing order, using the same parent and permission rules as dispatch. */
|
|
98
|
+
orderEditability(order: Readonly<Order>): import("./order-modification.js").OrderEditability;
|
|
99
|
+
refresh: () => Promise<void>;
|
|
100
|
+
destroy: () => void;
|
|
101
|
+
showOrderTicket(binding: TradingChartBinding, order: PreOrder): Promise<boolean>;
|
|
102
|
+
requestLeverage(request: LeverageRequest, signal?: AbortSignal): Promise<boolean>;
|
|
103
|
+
requestClose: (request: import("./position-commands.js").CloseRequest) => Promise<import("./command-coordinator.js").TradingCommandResult | undefined>;
|
|
104
|
+
formatters: (symbol: string) => Promise<Readonly<Pick<import("../compat/formatters.js").TableFormatContext, "price" | "numeric" | "quantity" | "integer" | "variable"> & {
|
|
105
|
+
spread?: import("../compat/formatters.js").TableFormatContext["numeric"];
|
|
106
|
+
}>>;
|
|
107
|
+
orderDialogOptions: (symbol: string) => Promise<import("../contracts/broker.js").OrderDialogOptions | undefined>;
|
|
108
|
+
positionDialogOptions: (symbol: string) => Promise<import("../contracts/broker.js").PositionDialogOptions | undefined>;
|
|
109
|
+
acquireExecutions: (symbol: string) => import("../contracts/ports.js").Dispose;
|
|
110
|
+
acquireQuotes: (symbol: string, speed: "fast" | "normal", listener: (value: import("../contracts/ports.js").TradingQuoteSnapshot) => void) => import("../contracts/ports.js").Dispose;
|
|
111
|
+
acquireDepth: (symbol: string, listener: (data: Readonly<import("../contracts/broker.js").DOMData>) => void) => import("../contracts/ports.js").Dispose;
|
|
112
|
+
acquireFinancial: (kind: "equity" | "margin" | "pip", symbol?: string) => import("../contracts/ports.js").Dispose;
|
|
113
|
+
};
|
|
114
|
+
export type TradingSession = ReturnType<typeof createTradingSession>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { TradingClock } from '../contracts/ports.js';
|
|
2
|
+
import { EntityStore } from './entity-store.js';
|
|
3
|
+
import { ValueStore } from './value-store.js';
|
|
4
|
+
export type ReadStatus = 'idle' | 'loading' | 'ready' | 'stale' | 'error';
|
|
5
|
+
/** `warnings` counts snapshot rows quarantined by the last successful read (see `EntityStore.replace`). */
|
|
6
|
+
export interface DatasetStatus {
|
|
7
|
+
readonly status: ReadStatus;
|
|
8
|
+
readonly error?: string;
|
|
9
|
+
readonly warnings?: number;
|
|
10
|
+
}
|
|
11
|
+
/** One read per account scope, at most one trailing resync, and ordered push replay. */
|
|
12
|
+
export declare class SnapshotDataset<T extends {
|
|
13
|
+
id: string;
|
|
14
|
+
}> {
|
|
15
|
+
readonly store: EntityStore<T>;
|
|
16
|
+
private readonly load;
|
|
17
|
+
private readonly clock;
|
|
18
|
+
private readonly apply;
|
|
19
|
+
private readonly diagnostic;
|
|
20
|
+
/** Rows a snapshot read keeps; pushes use `apply` instead (for example, quantity-zero positions). */
|
|
21
|
+
private readonly accept?;
|
|
22
|
+
/** Account datasets set aside invalid rows (`warnings`); others reject the whole read. */
|
|
23
|
+
private readonly quarantine;
|
|
24
|
+
private readonly deadline;
|
|
25
|
+
readonly status: ValueStore<DatasetStatus>;
|
|
26
|
+
private epoch;
|
|
27
|
+
private active;
|
|
28
|
+
private timer;
|
|
29
|
+
private buffered;
|
|
30
|
+
/** IDs the last successful read quarantined. */
|
|
31
|
+
private quarantinedLast;
|
|
32
|
+
private queued;
|
|
33
|
+
private disposed;
|
|
34
|
+
constructor(store: EntityStore<T>, load: () => Promise<T[]>, clock: TradingClock, apply?: (entity: T) => void, diagnostic?: (message: string, entityId?: string) => void,
|
|
35
|
+
/** Rows a snapshot read keeps; pushes use `apply` instead (for example, quantity-zero positions). */
|
|
36
|
+
accept?: ((entity: T) => boolean) | undefined,
|
|
37
|
+
/** Account datasets set aside invalid rows (`warnings`); others reject the whole read. */
|
|
38
|
+
quarantine?: boolean, deadline?: number);
|
|
39
|
+
push(entity: T): void;
|
|
40
|
+
partial(id: string, patch: Partial<T>): void;
|
|
41
|
+
/** Apply dependent updates in arrival order after an in-flight snapshot and its buffered pushes. */
|
|
42
|
+
afterUpdates(id: string, apply: () => void): void;
|
|
43
|
+
private update;
|
|
44
|
+
refresh(): Promise<void>;
|
|
45
|
+
invalidate(clear?: boolean): void;
|
|
46
|
+
destroy(): void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IBrokerTerminal, InstrumentInfo, SymbolSpecificTradingOptions } from "../contracts/broker.js";
|
|
2
|
+
import type { TradingFormatterPort } from "../contracts/ports.js";
|
|
3
|
+
import type { TableFormatContext } from "../compat/formatters.js";
|
|
4
|
+
export type TradingFormatters = Readonly<Pick<TableFormatContext, "price" | "quantity" | "numeric" | "integer" | "variable"> & {
|
|
5
|
+
/** Broker spreadFormatter when provided; otherwise spreads use the price formatter. */
|
|
6
|
+
spread?: TableFormatContext["numeric"];
|
|
7
|
+
}>;
|
|
8
|
+
interface Services {
|
|
9
|
+
readonly ready: Promise<IBrokerTerminal>;
|
|
10
|
+
readonly fallbackFormatters: TradingFormatterPort;
|
|
11
|
+
alive(): boolean;
|
|
12
|
+
generation(): number;
|
|
13
|
+
broker(): IBrokerTerminal;
|
|
14
|
+
read<T>(load: () => T | Promise<T>, epoch?: number): Promise<T>;
|
|
15
|
+
/** Observes each instrument the broker returns; it cannot affect the lookup. */
|
|
16
|
+
loaded?(symbol: string, instrument: InstrumentInfo): void;
|
|
17
|
+
}
|
|
18
|
+
/** Symbol metadata/options and formatter caches share the session's generation fence. */
|
|
19
|
+
export declare class SymbolCatalog {
|
|
20
|
+
private readonly services;
|
|
21
|
+
private readonly symbolRequests;
|
|
22
|
+
/** Lookups still running are keyed apart from the bounded cache, so eviction can never fail a caller. */
|
|
23
|
+
private readonly inflight;
|
|
24
|
+
private readonly symbolOptions;
|
|
25
|
+
private readonly formatterRequests;
|
|
26
|
+
private readonly revisionState;
|
|
27
|
+
readonly revision: import("../contracts/ports.js").ReadonlyValue<number>;
|
|
28
|
+
constructor(services: Services);
|
|
29
|
+
private symbolOptionsChanged;
|
|
30
|
+
options(symbol: string): SymbolSpecificTradingOptions | undefined;
|
|
31
|
+
invalidate(): void;
|
|
32
|
+
refresh(symbol: string): Promise<InstrumentInfo>;
|
|
33
|
+
destroy(): void;
|
|
34
|
+
readonly info: (symbol: string) => Promise<InstrumentInfo>;
|
|
35
|
+
readonly formatters: (symbol: string) => Promise<TradingFormatters>;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** A broker's suggested way to make a symbol tradable. */
|
|
2
|
+
export type TradabilitySolution = {
|
|
3
|
+
readonly kind: "account";
|
|
4
|
+
readonly accountId: string;
|
|
5
|
+
} | {
|
|
6
|
+
readonly kind: "symbol";
|
|
7
|
+
readonly symbol: string;
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: "url";
|
|
10
|
+
readonly url: string;
|
|
11
|
+
readonly text: string;
|
|
12
|
+
};
|
|
13
|
+
/** Normalized `isTradable` result: broker text is bounded plain text, URLs are http(s) only. */
|
|
14
|
+
export interface Tradability {
|
|
15
|
+
readonly tradable: boolean;
|
|
16
|
+
readonly reason?: string;
|
|
17
|
+
readonly heading?: string;
|
|
18
|
+
readonly shortReason?: string;
|
|
19
|
+
/** Main action text when no solution is offered. */
|
|
20
|
+
readonly buttonText?: string;
|
|
21
|
+
readonly solution?: TradabilitySolution;
|
|
22
|
+
}
|
|
23
|
+
/** Validate provider data without invoking accessor properties; boolean and object forms are both accepted. */
|
|
24
|
+
export declare function normalizeTradability(value: unknown): Tradability;
|
|
25
|
+
/** Commands refuse a non-tradable symbol with the broker's reason when one is given. */
|
|
26
|
+
export declare function assertTradable(value: unknown): void;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { BrokerCustomUI, IBrokerTerminal, InstrumentInfo, Order, OrderDialogOptions, OrderPreviewResult, PreOrder, Side, TradingDialogOptions } from "../contracts/broker.js";
|
|
2
|
+
import type { LumenBrokerExtensions } from "../contracts/ports.js";
|
|
3
|
+
import type { CapabilityPolicy } from "./capabilities.js";
|
|
4
|
+
import type { CommandCoordinator, TradingCommandResult } from "./command-coordinator.js";
|
|
5
|
+
import { type LeverageChangeRequest, type LeverageRequest } from "./leverage-commands.js";
|
|
6
|
+
import { type ModificationParentContext } from "./modification-context.js";
|
|
7
|
+
import { type CloseRequest, type PositionCommandServices, type PositionRequest, type ProtectionRequest } from "./position-commands.js";
|
|
8
|
+
import type { TradingState } from "./trading-state.js";
|
|
9
|
+
export interface TradingCommandContext {
|
|
10
|
+
readonly accountId: string;
|
|
11
|
+
readonly generation: number;
|
|
12
|
+
readonly revision?: number;
|
|
13
|
+
readonly parent?: ModificationParentContext;
|
|
14
|
+
}
|
|
15
|
+
export interface PlaceRequest {
|
|
16
|
+
readonly context: TradingCommandContext;
|
|
17
|
+
readonly order: PreOrder;
|
|
18
|
+
readonly confirmId?: string;
|
|
19
|
+
readonly previewToken?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ModifyRequest {
|
|
22
|
+
readonly context: TradingCommandContext;
|
|
23
|
+
readonly order: Order;
|
|
24
|
+
readonly confirmId?: string;
|
|
25
|
+
readonly previewToken?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface EntityRequest {
|
|
28
|
+
readonly context: TradingCommandContext;
|
|
29
|
+
readonly id: string;
|
|
30
|
+
}
|
|
31
|
+
export interface TradingCommandServices {
|
|
32
|
+
readonly broker: IBrokerTerminal;
|
|
33
|
+
readonly alwaysPassCalledOrderToModify?: boolean;
|
|
34
|
+
readonly beginProtectionNotifications?: PositionCommandServices["beginProtectionNotifications"];
|
|
35
|
+
readonly state: TradingState;
|
|
36
|
+
readonly coordinator: CommandCoordinator;
|
|
37
|
+
readonly policy: (symbol?: string) => CapabilityPolicy;
|
|
38
|
+
readonly orderPreviewEnabled?: () => boolean;
|
|
39
|
+
readonly symbolInfo: (symbol: string) => Promise<InstrumentInfo>;
|
|
40
|
+
readonly now: () => number;
|
|
41
|
+
/** Expiry validation tolerance for a session clock ahead of the broker (default 60 s). */
|
|
42
|
+
readonly clockSkewToleranceSeconds?: number;
|
|
43
|
+
readonly read: <T>(load: () => T | Promise<T>) => Promise<T>;
|
|
44
|
+
readonly refreshLeverageDependencies: (symbol: string) => Promise<void>;
|
|
45
|
+
readonly refresh: () => void;
|
|
46
|
+
readonly refreshPositions?: () => Promise<void>;
|
|
47
|
+
readonly orderOptions?: (symbol: string) => Promise<OrderDialogOptions | undefined>;
|
|
48
|
+
readonly extensions?: LumenBrokerExtensions;
|
|
49
|
+
readonly closePreview?: NonNullable<LumenBrokerExtensions["previewClosePosition"]>;
|
|
50
|
+
readonly customClose?: NonNullable<BrokerCustomUI["showClosePositionDialog"]>;
|
|
51
|
+
readonly positionOptions?: (symbol: string) => Promise<TradingDialogOptions | undefined>;
|
|
52
|
+
readonly selectAccount: (accountId: string) => Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export interface LumenOrderPreview {
|
|
55
|
+
readonly token: string;
|
|
56
|
+
readonly preview: Readonly<OrderPreviewResult>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Facade over the command modules: orders (`order-commands.ts`), closing (`close-commands.ts`), positions
|
|
60
|
+
* (`position-commands.ts`) and leverage (`leverage-commands.ts`). The public surface is unchanged.
|
|
61
|
+
*/
|
|
62
|
+
export declare class TradingCommands {
|
|
63
|
+
private readonly services;
|
|
64
|
+
private previewSequence;
|
|
65
|
+
private readonly orders;
|
|
66
|
+
private readonly closes;
|
|
67
|
+
private readonly leverage;
|
|
68
|
+
constructor(services: TradingCommandServices);
|
|
69
|
+
invalidatePreviews(): void;
|
|
70
|
+
leverageInfo(request: LeverageRequest): Promise<Readonly<import("../contracts/broker.js").LeverageInfo>>;
|
|
71
|
+
previewLeverage(request: LeverageChangeRequest): Promise<import("./leverage-commands.js").LeverageReview>;
|
|
72
|
+
setLeverage(request: LeverageChangeRequest): Promise<TradingCommandResult>;
|
|
73
|
+
context(id?: string, kind?: "order" | "position" | "individualPosition"): TradingCommandContext;
|
|
74
|
+
place(request: PlaceRequest): Promise<TradingCommandResult>;
|
|
75
|
+
validate(request: PlaceRequest): Promise<void>;
|
|
76
|
+
preview(request: PlaceRequest): Promise<LumenOrderPreview>;
|
|
77
|
+
modify(request: ModifyRequest): Promise<TradingCommandResult>;
|
|
78
|
+
cancel(request: EntityRequest): Promise<TradingCommandResult>;
|
|
79
|
+
cancelMany(request: {
|
|
80
|
+
context: TradingCommandContext;
|
|
81
|
+
symbol: string;
|
|
82
|
+
side?: Side;
|
|
83
|
+
orders: readonly {
|
|
84
|
+
id: string;
|
|
85
|
+
revision: number;
|
|
86
|
+
}[];
|
|
87
|
+
}): Promise<readonly {
|
|
88
|
+
id: string;
|
|
89
|
+
result?: TradingCommandResult;
|
|
90
|
+
error?: unknown;
|
|
91
|
+
}[]>;
|
|
92
|
+
previewClose(request: CloseRequest): Promise<{
|
|
93
|
+
token: string;
|
|
94
|
+
preview: Readonly<import("../contracts/broker.js").ClosePositionPreviewResult>;
|
|
95
|
+
}>;
|
|
96
|
+
confirmCustomClose(request: CloseRequest): Promise<{
|
|
97
|
+
approved: boolean;
|
|
98
|
+
token?: string;
|
|
99
|
+
} | undefined>;
|
|
100
|
+
close(request: CloseRequest): Promise<TradingCommandResult>;
|
|
101
|
+
reverse(request: PositionRequest): Promise<TradingCommandResult>;
|
|
102
|
+
editProtection(request: ProtectionRequest): Promise<TradingCommandResult>;
|
|
103
|
+
selectAccount(accountId: string): Promise<void>;
|
|
104
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Side } from "../contracts/broker.js";
|
|
2
|
+
import type { InstrumentInfo, PreOrder, QuantityMetainfo, TradingQuotes } from "../contracts/broker.js";
|
|
3
|
+
import type { CapabilityPolicy } from "./capabilities.js";
|
|
4
|
+
export declare function sumExceeds(values: readonly number[], maximum: number): boolean;
|
|
5
|
+
export declare function aligned(value: number, step: number): boolean;
|
|
6
|
+
export declare function alignedFrom(value: number, origin: number, step: number): boolean;
|
|
7
|
+
export declare function floorToStep(value: number, step: number): number;
|
|
8
|
+
export declare function snapToStep(value: number, step: number): number;
|
|
9
|
+
export declare function effectiveTick(price: number, instrument: Pick<InstrumentInfo, "minTick" | "variableMinTick">): number;
|
|
10
|
+
export declare function validateQuantity(quantity: number, rules: QuantityMetainfo): void;
|
|
11
|
+
export declare function executablePrice(side: Side, quotes?: TradingQuotes): number | undefined;
|
|
12
|
+
export declare function validatePreOrder(order: PreOrder, instrument: InstrumentInfo, policy: CapabilityPolicy, quotes: TradingQuotes | undefined, now: number,
|
|
13
|
+
/** The session clock may run ahead of the broker's; an expiry this close to now is left to the broker. */
|
|
14
|
+
clockSkewToleranceSeconds?: number): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { NotificationType } from "../contracts/broker.js";
|
|
2
|
+
import type { IBrokerConnectionAdapterHost } from "../contracts/broker.js";
|
|
3
|
+
import type { Dispose, ReadonlyValue, TradingDisplaySettings, TradingProfitDisplayMode, TradingSettingsPageSnapshot, TradingSettingsValue } from "../contracts/ports.js";
|
|
4
|
+
import type { CapabilityFlags } from "./capabilities.js";
|
|
5
|
+
/** The settings page id hosts register and open. */
|
|
6
|
+
export declare const TRADING_SETTINGS_PAGE_ID = "trading";
|
|
7
|
+
export declare const TRADING_SETTINGS_PAGE_LABEL = "Trading";
|
|
8
|
+
/** Every display setting with its reference default filled in. */
|
|
9
|
+
export type EffectiveDisplaySettings = Required<TradingDisplaySettings>;
|
|
10
|
+
export declare function effectiveDisplay(display: Readonly<TradingDisplaySettings>): EffectiveDisplaySettings;
|
|
11
|
+
/** Position P&L shows only while both the parent P&L switch and its own switch are on. */
|
|
12
|
+
export declare function positionProfitVisible(display: Readonly<TradingDisplaySettings>): boolean;
|
|
13
|
+
export declare function bracketProfitVisible(display: Readonly<TradingDisplaySettings>): boolean;
|
|
14
|
+
export declare function bracketProfitMode(display: Readonly<TradingDisplaySettings>): TradingProfitDisplayMode;
|
|
15
|
+
/** Bracket money text needs pip values unless amounts stay in instrument currency. */
|
|
16
|
+
export declare function bracketProfitInMoney(display: Readonly<TradingDisplaySettings>): boolean;
|
|
17
|
+
/** Toasts honour "Show only rejection notifications"; the notification log keeps every entry. */
|
|
18
|
+
export declare function showsToast(type: NotificationType, display: Readonly<TradingDisplaySettings>): boolean;
|
|
19
|
+
/** What the settings page reads and writes; a trading session satisfies it. */
|
|
20
|
+
export interface TradingSettingsSource {
|
|
21
|
+
readonly displaySettings: ReadonlyValue<TradingDisplaySettings>;
|
|
22
|
+
updateDisplaySettings(patch: Partial<TradingDisplaySettings>): void;
|
|
23
|
+
readonly policy: ReadonlyValue<{
|
|
24
|
+
readonly flags: Pick<CapabilityFlags, "supportMultipleExitLevels">;
|
|
25
|
+
}>;
|
|
26
|
+
readonly confirmationRequired: boolean;
|
|
27
|
+
readonly features: {
|
|
28
|
+
readonly buy_sell_buttons: boolean;
|
|
29
|
+
};
|
|
30
|
+
readonly host: Pick<IBrokerConnectionAdapterHost, "sellBuyButtonsVisibility" | "silentOrdersPlacement">;
|
|
31
|
+
}
|
|
32
|
+
export declare function tradingSettingsSnapshot(source: TradingSettingsSource): TradingSettingsPageSnapshot;
|
|
33
|
+
/**
|
|
34
|
+
* Writes changed page fields to their owners: display preferences, or the host's buy/sell button and
|
|
35
|
+
* one-click values. Every field is validated before anything is written.
|
|
36
|
+
*/
|
|
37
|
+
export declare function applyTradingSettings(source: TradingSettingsSource, patch: Readonly<Record<string, TradingSettingsValue>>): void;
|
|
38
|
+
/** Notifies when the page's fields or values may have changed outside the dialog. */
|
|
39
|
+
export declare function subscribeTradingSettings(source: TradingSettingsSource, listener: () => void): Dispose;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CryptoBalance, DisconnectType, Execution, IndividualPosition, Order, PipValues, Position, TradingQuotes } from "../contracts/broker.js";
|
|
2
|
+
import { ConnectionStatus } from "../contracts/broker.js";
|
|
3
|
+
import { EntityStore } from "./entity-store.js";
|
|
4
|
+
import { ValueStore } from "./value-store.js";
|
|
5
|
+
export interface FinancialValue {
|
|
6
|
+
id: string;
|
|
7
|
+
value: number;
|
|
8
|
+
}
|
|
9
|
+
export type ConnectionPhase = "initializing" | "hydrating" | "ready" | "switching" | "disconnected" | "error" | "disposed";
|
|
10
|
+
/** Broker-supplied disconnection details, reduced to bounded display text. `reason` is analytics-only and not kept. */
|
|
11
|
+
export interface ConnectionNotice {
|
|
12
|
+
heading?: string;
|
|
13
|
+
message?: string;
|
|
14
|
+
additionalInfo?: string;
|
|
15
|
+
disconnectType?: DisconnectType;
|
|
16
|
+
}
|
|
17
|
+
export interface ConnectionState {
|
|
18
|
+
status: ConnectionStatus;
|
|
19
|
+
phase: ConnectionPhase;
|
|
20
|
+
generation: number;
|
|
21
|
+
accountId?: string;
|
|
22
|
+
error?: string;
|
|
23
|
+
notice?: ConnectionNotice;
|
|
24
|
+
}
|
|
25
|
+
export declare function connectionNotice(info: unknown): ConnectionNotice | undefined;
|
|
26
|
+
/** Stores only broker-confirmed data; table-only PL has its own keyed channel. */
|
|
27
|
+
export declare function createTradingState(): {
|
|
28
|
+
orders: EntityStore<Order>;
|
|
29
|
+
history: EntityStore<Order>;
|
|
30
|
+
positions: EntityStore<Position>;
|
|
31
|
+
individualPositions: EntityStore<IndividualPosition>;
|
|
32
|
+
executions: EntityStore<Execution>;
|
|
33
|
+
tablePL: EntityStore<FinancialValue>;
|
|
34
|
+
individualTablePL: EntityStore<FinancialValue>;
|
|
35
|
+
equity: ValueStore<number | undefined>;
|
|
36
|
+
marginAvailable: ValueStore<number | undefined>;
|
|
37
|
+
balances: EntityStore<CryptoBalance & {
|
|
38
|
+
id: string;
|
|
39
|
+
}>;
|
|
40
|
+
quotes: EntityStore<TradingQuotes & {
|
|
41
|
+
id: string;
|
|
42
|
+
}>;
|
|
43
|
+
pipValues: EntityStore<PipValues & {
|
|
44
|
+
id: string;
|
|
45
|
+
}>;
|
|
46
|
+
connection: ValueStore<ConnectionState>;
|
|
47
|
+
clearAccount: () => void;
|
|
48
|
+
positionUpdate(position: Position): void;
|
|
49
|
+
individualPositionUpdate(position: IndividualPosition): void;
|
|
50
|
+
destroy(): void;
|
|
51
|
+
};
|
|
52
|
+
export type TradingState = ReturnType<typeof createTradingState>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Dispose, ReadonlyValue } from '../contracts/ports.js';
|
|
2
|
+
export declare class ValueStore<T> implements ReadonlyValue<Readonly<T>> {
|
|
3
|
+
private current;
|
|
4
|
+
private disposed;
|
|
5
|
+
private readonly listeners;
|
|
6
|
+
constructor(value: T);
|
|
7
|
+
get(): Readonly<T>;
|
|
8
|
+
set(value: T): void;
|
|
9
|
+
subscribe(listener: (value: Readonly<T>) => void): Dispose;
|
|
10
|
+
destroy(): void;
|
|
11
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { resolveCapabilities, normalizeBrokerConfig, durationsForType, defaultFlags } from './core/capabilities.js';
|
|
2
|
+
export type { CapabilityPolicy, CapabilityFlags, CapabilityContext, CapabilityDiagnostic } from './core/capabilities.js';
|
|
3
|
+
export { createTradingSession } from './core/session.js';
|
|
4
|
+
export type { TradingSession } from './core/session.js';
|
|
5
|
+
export type { TradingSessionOptions } from './core/session-types.js';
|
|
6
|
+
export type { TradingCommandContext, PlaceRequest, ModifyRequest, EntityRequest } from './core/trading-commands.js';
|
|
7
|
+
export type { TradingCommandResult } from './core/command-coordinator.js';
|
|
8
|
+
export { TradingError } from './core/errors.js';
|
|
9
|
+
export type { TradingErrorCode } from './core/errors.js';
|
|
10
|
+
export { resolveTradingFeatures, tradingFeatureDefaults } from './core/features.js';
|
|
11
|
+
export type { TradingFeature, TradingFeatures } from './core/features.js';
|
|
12
|
+
export { createDefaultTradingFormatters, createNumericFormatter, createPriceFormatter } from './compat/default-formatters.js';
|
|
13
|
+
export { positionProfit, riskBudget, quantityForRisk, executablePrice, liquidationPrice, orderEntryPrice, cryptoBaseQuantity, cryptoQuoteAmount, orderNotional, marginRequired } from './core/financial-rules.js';
|
|
14
|
+
export type { ProfitDisplayMode } from './core/financial-rules.js';
|
|
15
|
+
export type { LeverageRequest, LeverageChangeRequest, LeverageReview } from './core/leverage-commands.js';
|