@dsh-ft/dsh-fft-paper-trading 0.7.3 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/README.zh.md +3 -2
- package/lib/agent/account-tools.d.ts +18 -0
- package/lib/agent/account-tools.d.ts.map +1 -0
- package/lib/agent/account-tools.js +127 -0
- package/lib/agent/account-tools.js.map +1 -0
- package/lib/agent/futures-tools.d.ts.map +1 -1
- package/lib/agent/futures-tools.js +1 -6
- package/lib/agent/futures-tools.js.map +1 -1
- package/lib/agent/ledger-tools.d.ts +15 -3
- package/lib/agent/ledger-tools.d.ts.map +1 -1
- package/lib/agent/ledger-tools.js +11 -15
- package/lib/agent/ledger-tools.js.map +1 -1
- package/lib/agent/tool-result.d.ts +19 -0
- package/lib/agent/tool-result.d.ts.map +1 -0
- package/lib/agent/tool-result.js +22 -0
- package/lib/agent/tool-result.js.map +1 -0
- package/lib/agent/tools.d.ts +10 -2
- package/lib/agent/tools.d.ts.map +1 -1
- package/lib/agent/tools.js +26 -11
- package/lib/agent/tools.js.map +1 -1
- package/lib/client.js +1448 -282
- package/lib/contract/accounts.d.ts +76 -0
- package/lib/contract/accounts.d.ts.map +1 -0
- package/lib/contract/accounts.js +6 -0
- package/lib/contract/accounts.js.map +1 -0
- package/lib/contract/common.d.ts +144 -0
- package/lib/contract/common.d.ts.map +1 -0
- package/lib/contract/common.js +33 -0
- package/lib/contract/common.js.map +1 -0
- package/lib/contract/domain.d.ts +196 -0
- package/lib/contract/domain.d.ts.map +1 -0
- package/lib/contract/domain.js +14 -0
- package/lib/contract/domain.js.map +1 -0
- package/lib/contract/errors.d.ts +6 -0
- package/lib/contract/errors.d.ts.map +1 -0
- package/lib/contract/errors.js +6 -0
- package/lib/contract/errors.js.map +1 -0
- package/lib/contract/index.d.ts +15 -0
- package/lib/contract/index.d.ts.map +1 -0
- package/lib/contract/index.js +15 -0
- package/lib/contract/index.js.map +1 -0
- package/lib/contract/ledger.d.ts +40 -0
- package/lib/contract/ledger.d.ts.map +1 -0
- package/lib/contract/ledger.js +6 -0
- package/lib/contract/ledger.js.map +1 -0
- package/lib/contract/market.d.ts +30 -0
- package/lib/contract/market.d.ts.map +1 -0
- package/lib/contract/market.js +6 -0
- package/lib/contract/market.js.map +1 -0
- package/lib/contract/rpc.d.ts +24 -0
- package/lib/contract/rpc.d.ts.map +1 -0
- package/lib/contract/rpc.js +6 -0
- package/lib/contract/rpc.js.map +1 -0
- package/lib/contract.d.ts +6 -403
- package/lib/contract.d.ts.map +1 -1
- package/lib/contract.js +6 -24
- package/lib/contract.js.map +1 -1
- package/lib/core/session.d.ts +1 -1
- package/lib/core/session.d.ts.map +1 -1
- package/lib/core/session.js +1 -2
- package/lib/core/session.js.map +1 -1
- package/lib/data/cached-market-data.d.ts +61 -0
- package/lib/data/cached-market-data.d.ts.map +1 -0
- package/lib/data/cached-market-data.js +174 -0
- package/lib/data/cached-market-data.js.map +1 -0
- package/lib/data/futures-market-data.d.ts.map +1 -1
- package/lib/data/futures-market-data.js +9 -10
- package/lib/data/futures-market-data.js.map +1 -1
- package/lib/index.d.ts +25 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +156 -18
- package/lib/index.js.map +1 -1
- package/lib/service/account-moves.d.ts +64 -0
- package/lib/service/account-moves.d.ts.map +1 -0
- package/lib/service/account-moves.js +49 -0
- package/lib/service/account-moves.js.map +1 -0
- package/lib/service/accounts-rpc.d.ts +17 -0
- package/lib/service/accounts-rpc.d.ts.map +1 -0
- package/lib/service/accounts-rpc.js +77 -0
- package/lib/service/accounts-rpc.js.map +1 -0
- package/lib/service/compare-rpc.d.ts +22 -0
- package/lib/service/compare-rpc.d.ts.map +1 -0
- package/lib/service/compare-rpc.js +70 -0
- package/lib/service/compare-rpc.js.map +1 -0
- package/lib/service/errors.d.ts +20 -4
- package/lib/service/errors.d.ts.map +1 -1
- package/lib/service/errors.js +12 -5
- package/lib/service/errors.js.map +1 -1
- package/lib/service/futures-rpc.d.ts.map +1 -1
- package/lib/service/futures-rpc.js +7 -25
- package/lib/service/futures-rpc.js.map +1 -1
- package/lib/service/futures-service.d.ts +28 -8
- package/lib/service/futures-service.d.ts.map +1 -1
- package/lib/service/futures-service.js +144 -146
- package/lib/service/futures-service.js.map +1 -1
- package/lib/service/ledger-admin.d.ts +67 -0
- package/lib/service/ledger-admin.d.ts.map +1 -0
- package/lib/service/ledger-admin.js +102 -0
- package/lib/service/ledger-admin.js.map +1 -0
- package/lib/service/paper-service.d.ts +39 -12
- package/lib/service/paper-service.d.ts.map +1 -1
- package/lib/service/paper-service.js +177 -156
- package/lib/service/paper-service.js.map +1 -1
- package/lib/service/route.d.ts.map +1 -1
- package/lib/service/route.js +5 -2
- package/lib/service/route.js.map +1 -1
- package/lib/service/rpc-support.d.ts +34 -0
- package/lib/service/rpc-support.d.ts.map +1 -0
- package/lib/service/rpc-support.js +57 -0
- package/lib/service/rpc-support.js.map +1 -0
- package/lib/service/rpc.d.ts +20 -3
- package/lib/service/rpc.d.ts.map +1 -1
- package/lib/service/rpc.js +44 -25
- package/lib/service/rpc.js.map +1 -1
- package/lib/store/accounts.d.ts +110 -0
- package/lib/store/accounts.d.ts.map +1 -0
- package/lib/store/accounts.js +352 -0
- package/lib/store/accounts.js.map +1 -0
- package/lib/store/atomic-file.d.ts +16 -0
- package/lib/store/atomic-file.d.ts.map +1 -0
- package/lib/store/atomic-file.js +34 -0
- package/lib/store/atomic-file.js.map +1 -0
- package/lib/store/futures-repo.d.ts +8 -49
- package/lib/store/futures-repo.d.ts.map +1 -1
- package/lib/store/futures-repo.js +34 -246
- package/lib/store/futures-repo.js.map +1 -1
- package/lib/store/ledger-repo-base.d.ts +120 -0
- package/lib/store/ledger-repo-base.d.ts.map +1 -0
- package/lib/store/ledger-repo-base.js +275 -0
- package/lib/store/ledger-repo-base.js.map +1 -0
- package/lib/store/notes.d.ts +29 -0
- package/lib/store/notes.d.ts.map +1 -0
- package/lib/store/notes.js +78 -0
- package/lib/store/notes.js.map +1 -0
- package/lib/store/paths.d.ts +2 -0
- package/lib/store/paths.d.ts.map +1 -1
- package/lib/store/paths.js +4 -0
- package/lib/store/paths.js.map +1 -1
- package/lib/store/repo.d.ts +15 -55
- package/lib/store/repo.d.ts.map +1 -1
- package/lib/store/repo.js +41 -206
- package/lib/store/repo.js.map +1 -1
- package/lib/store/shortlist.d.ts.map +1 -1
- package/lib/store/shortlist.js +4 -6
- package/lib/store/shortlist.js.map +1 -1
- package/lib/store/snapshots.d.ts +0 -3
- package/lib/store/snapshots.d.ts.map +1 -1
- package/lib/store/snapshots.js +0 -3
- package/lib/store/snapshots.js.map +1 -1
- package/package.json +1 -1
- package/src/agent/account-tools.ts +136 -0
- package/src/agent/futures-tools.ts +1 -6
- package/src/agent/ledger-tools.ts +29 -16
- package/src/agent/tool-result.ts +27 -0
- package/src/agent/tools.ts +30 -10
- package/src/client/entry.js +14 -0
- package/src/client/parts/10-core.js +535 -0
- package/src/client/parts/20-styles.js +336 -0
- package/src/client/parts/30-atoms.js +769 -0
- package/src/client/parts/35-hooks.js +447 -0
- package/src/client/parts/40-stock-tabs.js +641 -0
- package/src/client/parts/50-futures.js +911 -0
- package/src/client/parts/60-shell.js +706 -0
- package/src/client/parts/70-plugin.js +67 -0
- package/src/contract/accounts.ts +82 -0
- package/src/contract/common.ts +173 -0
- package/src/contract/domain.ts +217 -0
- package/src/contract/errors.ts +34 -0
- package/src/contract/index.ts +15 -0
- package/src/contract/ledger.ts +42 -0
- package/src/contract/market.ts +39 -0
- package/src/contract/rpc.ts +15 -0
- package/src/contract.ts +6 -472
- package/src/core/session.ts +1 -2
- package/src/data/cached-market-data.ts +193 -0
- package/src/data/futures-market-data.ts +9 -10
- package/src/index.ts +168 -20
- package/src/service/account-moves.ts +72 -0
- package/src/service/accounts-rpc.ts +80 -0
- package/src/service/compare-rpc.ts +77 -0
- package/src/service/errors.ts +23 -4
- package/src/service/futures-rpc.ts +7 -24
- package/src/service/futures-service.ts +161 -159
- package/src/service/ledger-admin.ts +140 -0
- package/src/service/paper-service.ts +183 -153
- package/src/service/route.ts +5 -2
- package/src/service/rpc-support.ts +61 -0
- package/src/service/rpc.ts +59 -23
- package/src/store/accounts.ts +373 -0
- package/src/store/atomic-file.ts +37 -0
- package/src/store/futures-repo.ts +35 -260
- package/src/store/ledger-repo-base.ts +337 -0
- package/src/store/notes.ts +86 -0
- package/src/store/paths.ts +5 -0
- package/src/store/repo.ts +47 -229
- package/src/store/shortlist.ts +3 -5
- package/src/store/snapshots.ts +0 -3
- package/src/client/index.js +0 -3275
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account registry and comparison shapes (multi-account).
|
|
3
|
+
* @module @dsh-ft/dsh-fft-paper-trading/contract/accounts
|
|
4
|
+
*/
|
|
5
|
+
import type { EquityPoint } from './domain.js';
|
|
6
|
+
/** Asset families that own their own ledger. v1 only grows `stock`. */
|
|
7
|
+
export type AccountKind = 'stock' | 'futures';
|
|
8
|
+
/**
|
|
9
|
+
* One account's free-form notes.
|
|
10
|
+
*
|
|
11
|
+
* A single large text block the human rewrites however they like — not a log,
|
|
12
|
+
* no timestamps, never written by the model. Stored beside the ledger so the
|
|
13
|
+
* registry file stays small.
|
|
14
|
+
*/
|
|
15
|
+
export interface NoteView {
|
|
16
|
+
text: string;
|
|
17
|
+
/** ISO time of the last write, absent when the account has no note yet. */
|
|
18
|
+
updatedAt?: string;
|
|
19
|
+
bytes: number;
|
|
20
|
+
maxBytes: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Registry entry for one ledger directory.
|
|
24
|
+
*
|
|
25
|
+
* `id` is the on-disk directory name and never changes; `name` is the
|
|
26
|
+
* user-editable display name and may repeat — `id` is the only reliable handle.
|
|
27
|
+
* `initialCashCents` is a creation intent kept until the account's first
|
|
28
|
+
* `account.opened` event has recorded it in the ledger.
|
|
29
|
+
*
|
|
30
|
+
* There is deliberately no session, model or owner field: this plugin knows
|
|
31
|
+
* nothing about sessions, and any caller may address any account.
|
|
32
|
+
*/
|
|
33
|
+
export interface AccountMeta {
|
|
34
|
+
id: string;
|
|
35
|
+
kind: AccountKind;
|
|
36
|
+
name: string;
|
|
37
|
+
createdAt: string;
|
|
38
|
+
/**
|
|
39
|
+
* Archived: hidden from the picker and the comparison page, and frozen like a
|
|
40
|
+
* locked account. The ledger and registry entry stay; archiving is reversible.
|
|
41
|
+
*/
|
|
42
|
+
archived: boolean;
|
|
43
|
+
/** Locked accounts refuse state changes (orders, reset, cash, ledger restore). */
|
|
44
|
+
locked: boolean;
|
|
45
|
+
initialCashCents?: number;
|
|
46
|
+
/** The ledger directory vanished while the registry still lists the entry. */
|
|
47
|
+
missing?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** One row of the comparison page: enough to draw a curve and rank by return. */
|
|
50
|
+
export interface CompareRow {
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
locked: boolean;
|
|
54
|
+
missing?: boolean;
|
|
55
|
+
initialCash: number;
|
|
56
|
+
equity: number;
|
|
57
|
+
pnl: number;
|
|
58
|
+
pnlPct: number;
|
|
59
|
+
todayPnl: number;
|
|
60
|
+
maxDrawdownPct: number;
|
|
61
|
+
tradeCount: number;
|
|
62
|
+
/** Daily equity snapshots, oldest first; the client normalises before plotting. */
|
|
63
|
+
points: EquityPoint[];
|
|
64
|
+
}
|
|
65
|
+
/** `compare/get` payload: one row per visible account, unsorted. */
|
|
66
|
+
export interface CompareView {
|
|
67
|
+
accounts: CompareRow[];
|
|
68
|
+
}
|
|
69
|
+
/** `accounts/list` payload: the registry plus the defaults the panel needs. */
|
|
70
|
+
export interface AccountsView {
|
|
71
|
+
accounts: AccountMeta[];
|
|
72
|
+
/** Default account id per kind, e.g. `{ stock: 'default', futures: 'futures' }`. */
|
|
73
|
+
defaultIds: Record<AccountKind, string>;
|
|
74
|
+
tickMs: number;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=accounts.d.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pE,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,UAAU,EAAE,CAAA;CACvB;AAED,+EAA+E;AAC/E,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,WAAW,EAAE,CAAA;IACvB,oFAAoF;IACpF,UAAU,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;IACvC,MAAM,EAAE,MAAM,CAAA;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.js","sourceRoot":"","sources":["../../src/contract/accounts.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-plane contract, common stock-domain shapes.
|
|
3
|
+
* @module @dsh-ft/dsh-fft-paper-trading/contract/common
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Cross-plane contract for the paper-trading plugin.
|
|
7
|
+
*
|
|
8
|
+
* Browser half and host half compile against these shapes; this module must stay
|
|
9
|
+
* free of runtime dependencies so both sides can import it as types.
|
|
10
|
+
* @module @dsh-ft/dsh-fft-paper-trading/contract
|
|
11
|
+
*/
|
|
12
|
+
/** Exact Fetch route used by the browser half. */
|
|
13
|
+
export declare const PAPER_ROUTE: "/api/ft-paper-trading";
|
|
14
|
+
/** Request body cap; the route rejects anything larger before parsing. */
|
|
15
|
+
export declare const PAPER_MAX_BODY_BYTES: number;
|
|
16
|
+
/**
|
|
17
|
+
* Ledger schema version. v4 stores every security as its canonical
|
|
18
|
+
* `code.exchange` id; older ledgers used the raw input and are incompatible.
|
|
19
|
+
*/
|
|
20
|
+
export declare const PAPER_LEDGER_VERSION = 4;
|
|
21
|
+
export type Side = 'buy' | 'sell';
|
|
22
|
+
export type OrderType = 'market' | 'limit';
|
|
23
|
+
export type OrderStatus = 'queued' | 'pending' | 'partially_filled' | 'filled' | 'canceled' | 'rejected' | 'expired';
|
|
24
|
+
export type DataState = 'ok' | 'stale' | 'denied' | 'failed';
|
|
25
|
+
export type Period = '7d' | '30d' | 'all';
|
|
26
|
+
/** Trading phase in Asia/Shanghai; the session table lives in core/session.ts. */
|
|
27
|
+
export type SessionPhase = 'pre_open' | 'continuous_am' | 'lunch' | 'continuous_pm' | 'auction_close' | 'closed';
|
|
28
|
+
export interface PaperSettings {
|
|
29
|
+
/** Starting cash in cents. */
|
|
30
|
+
initialCashCents: number;
|
|
31
|
+
commissionRate: number;
|
|
32
|
+
minCommissionCents: number;
|
|
33
|
+
stampDutyRate: number;
|
|
34
|
+
transferFeeRate: number;
|
|
35
|
+
enableT1: boolean;
|
|
36
|
+
maxOrderNotionalCents: number;
|
|
37
|
+
}
|
|
38
|
+
export declare const DEFAULT_SETTINGS: PaperSettings;
|
|
39
|
+
export interface Quote {
|
|
40
|
+
/** Canonical id, e.g. `000001.SZ`. */
|
|
41
|
+
symbol: string;
|
|
42
|
+
name?: string;
|
|
43
|
+
last: number;
|
|
44
|
+
prevClose?: number;
|
|
45
|
+
/** Market time of the quote/bar; null means it cannot fill. */
|
|
46
|
+
marketTs?: string | null;
|
|
47
|
+
/** Fetch time, for latency display only. */
|
|
48
|
+
fetchedAt?: string;
|
|
49
|
+
st?: boolean;
|
|
50
|
+
status?: string;
|
|
51
|
+
source?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface Bar {
|
|
54
|
+
time: string;
|
|
55
|
+
open: number;
|
|
56
|
+
high: number;
|
|
57
|
+
low: number;
|
|
58
|
+
close: number;
|
|
59
|
+
volume?: number;
|
|
60
|
+
}
|
|
61
|
+
export interface OrderDraft {
|
|
62
|
+
/** Canonical id, e.g. `000001.SZ`. */
|
|
63
|
+
symbol: string;
|
|
64
|
+
side: Side;
|
|
65
|
+
type: OrderType;
|
|
66
|
+
qty: number;
|
|
67
|
+
limitPrice?: number;
|
|
68
|
+
/** Manual fallback when no quote is available (market orders only). */
|
|
69
|
+
price?: number;
|
|
70
|
+
/** Optional journal note shown in the review view. */
|
|
71
|
+
note?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface OrderView {
|
|
74
|
+
id: string;
|
|
75
|
+
requestId: string;
|
|
76
|
+
/** Canonical id, e.g. `000001.SZ`. */
|
|
77
|
+
symbol: string;
|
|
78
|
+
name?: string;
|
|
79
|
+
side: Side;
|
|
80
|
+
type: OrderType;
|
|
81
|
+
qty: number;
|
|
82
|
+
limitPrice?: number;
|
|
83
|
+
status: OrderStatus;
|
|
84
|
+
reason?: string;
|
|
85
|
+
note?: string;
|
|
86
|
+
createdAt: string;
|
|
87
|
+
updatedAt: string;
|
|
88
|
+
filledAt?: string;
|
|
89
|
+
fillPrice?: number;
|
|
90
|
+
filledQty?: number;
|
|
91
|
+
remainingQty?: number;
|
|
92
|
+
avgFillPrice?: number;
|
|
93
|
+
amountCents?: number;
|
|
94
|
+
feesCents?: number;
|
|
95
|
+
}
|
|
96
|
+
export interface FillView {
|
|
97
|
+
id: string;
|
|
98
|
+
orderId: string;
|
|
99
|
+
/** Canonical id, e.g. `000001.SZ`. */
|
|
100
|
+
symbol: string;
|
|
101
|
+
name?: string;
|
|
102
|
+
side: Side;
|
|
103
|
+
price: number;
|
|
104
|
+
qty: number;
|
|
105
|
+
amountCents: number;
|
|
106
|
+
feesCents: number;
|
|
107
|
+
ts: string;
|
|
108
|
+
tradeDate: string;
|
|
109
|
+
}
|
|
110
|
+
export interface PositionView {
|
|
111
|
+
/** Canonical id, e.g. `000001.SZ`. */
|
|
112
|
+
symbol: string;
|
|
113
|
+
name?: string;
|
|
114
|
+
qty: number;
|
|
115
|
+
available: number;
|
|
116
|
+
avgCost: number;
|
|
117
|
+
lastPrice?: number;
|
|
118
|
+
marketValueCents?: number;
|
|
119
|
+
unrealizedPnlCents?: number;
|
|
120
|
+
unrealizedPnlPct?: number;
|
|
121
|
+
}
|
|
122
|
+
export interface AccountView {
|
|
123
|
+
accountId: string;
|
|
124
|
+
currency: 'CNY';
|
|
125
|
+
initialCash: number;
|
|
126
|
+
cash: number;
|
|
127
|
+
marketValue: number;
|
|
128
|
+
equity: number;
|
|
129
|
+
pnl: number;
|
|
130
|
+
pnlPct: number;
|
|
131
|
+
todayPnl: number;
|
|
132
|
+
/** Deposits minus withdrawals after the account opened, in yuan. */
|
|
133
|
+
netCashFlow: number;
|
|
134
|
+
tradeDate: string;
|
|
135
|
+
blocked: boolean;
|
|
136
|
+
/** Why the account is locked, copied from the last `ledger.violation`. */
|
|
137
|
+
blockedReason?: string;
|
|
138
|
+
/** Absolute path of `events.jsonl`, so a locked account can be repaired. */
|
|
139
|
+
ledgerPath?: string;
|
|
140
|
+
positions: PositionView[];
|
|
141
|
+
settings: PaperSettings;
|
|
142
|
+
}
|
|
143
|
+
export declare const DEFAULT_ACCOUNT_ID = "default";
|
|
144
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/contract/common.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AAEH,kDAAkD;AAClD,eAAO,MAAM,WAAW,EAAG,uBAAgC,CAAA;AAC3D,0EAA0E;AAC1E,eAAO,MAAM,oBAAoB,QAAa,CAAA;AAC9C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAA;AAErC,MAAM,MAAM,IAAI,GAAG,KAAK,GAAG,MAAM,CAAA;AACjC,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAA;AAC1C,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,kBAAkB,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAA;AACpH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAC5D,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,CAAA;AAEzC,kFAAkF;AAClF,MAAM,MAAM,YAAY,GACpB,UAAU,GACV,eAAe,GACf,OAAO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;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,KAAK,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,oEAAoE;IACpE,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,0EAA0E;IAC1E,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,YAAY,EAAE,CAAA;IACzB,QAAQ,EAAE,aAAa,CAAA;CACxB;AAED,eAAO,MAAM,kBAAkB,YAAY,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-plane contract, common stock-domain shapes.
|
|
3
|
+
* @module @dsh-ft/dsh-fft-paper-trading/contract/common
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Cross-plane contract for the paper-trading plugin.
|
|
7
|
+
*
|
|
8
|
+
* Browser half and host half compile against these shapes; this module must stay
|
|
9
|
+
* free of runtime dependencies so both sides can import it as types.
|
|
10
|
+
* @module @dsh-ft/dsh-fft-paper-trading/contract
|
|
11
|
+
*/
|
|
12
|
+
/** Exact Fetch route used by the browser half. */
|
|
13
|
+
export const PAPER_ROUTE = '/api/ft-paper-trading';
|
|
14
|
+
/** Request body cap; the route rejects anything larger before parsing. */
|
|
15
|
+
export const PAPER_MAX_BODY_BYTES = 256 * 1024;
|
|
16
|
+
/**
|
|
17
|
+
* Ledger schema version. v4 stores every security as its canonical
|
|
18
|
+
* `code.exchange` id; older ledgers used the raw input and are incompatible.
|
|
19
|
+
*/
|
|
20
|
+
export const PAPER_LEDGER_VERSION = 4;
|
|
21
|
+
export const DEFAULT_SETTINGS = {
|
|
22
|
+
// 100 万,A 股模拟盘的常规默认值:1 手贵州茅台(约 14.5 万)也能买,
|
|
23
|
+
// 10 万会让新账户连一手高价股都下不了单。
|
|
24
|
+
initialCashCents: 100_000_000,
|
|
25
|
+
commissionRate: 0.00025,
|
|
26
|
+
minCommissionCents: 500,
|
|
27
|
+
stampDutyRate: 0.0005,
|
|
28
|
+
transferFeeRate: 0.00001,
|
|
29
|
+
enableT1: true,
|
|
30
|
+
maxOrderNotionalCents: 0,
|
|
31
|
+
};
|
|
32
|
+
export const DEFAULT_ACCOUNT_ID = 'default';
|
|
33
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/contract/common.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AAEH,kDAAkD;AAClD,MAAM,CAAC,MAAM,WAAW,GAAG,uBAAgC,CAAA;AAC3D,0EAA0E;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,GAAG,IAAI,CAAA;AAC9C;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA;AA4BrC,MAAM,CAAC,MAAM,gBAAgB,GAAkB;IAC7C,2CAA2C;IAC3C,wBAAwB;IACxB,gBAAgB,EAAE,WAAW;IAC7B,cAAc,EAAE,OAAO;IACvB,kBAAkB,EAAE,GAAG;IACvB,aAAa,EAAE,MAAM;IACrB,eAAe,EAAE,OAAO;IACxB,QAAQ,EAAE,IAAI;IACd,qBAAqB,EAAE,CAAC;CACzB,CAAA;AAiHD,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAA"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stock trading views: ticket, orders, positions, review, market, symbols.
|
|
3
|
+
* @module @dsh-ft/dsh-fft-paper-trading/contract/domain
|
|
4
|
+
*/
|
|
5
|
+
import type { DataState, OrderType, OrderView, PositionView, Quote, SessionPhase, Side } from './common.js';
|
|
6
|
+
export interface PreviewView {
|
|
7
|
+
symbol: string;
|
|
8
|
+
side: Side;
|
|
9
|
+
type: OrderType;
|
|
10
|
+
qty: number;
|
|
11
|
+
price: number;
|
|
12
|
+
amountCents: number;
|
|
13
|
+
commissionCents: number;
|
|
14
|
+
stampCents: number;
|
|
15
|
+
transferCents: number;
|
|
16
|
+
totalFeesCents: number;
|
|
17
|
+
cashAfterCents: number;
|
|
18
|
+
availableQty: number;
|
|
19
|
+
maxBuyQty: number;
|
|
20
|
+
quote?: Quote;
|
|
21
|
+
priceLimit?: PriceLimit;
|
|
22
|
+
session?: MarketStatus;
|
|
23
|
+
warnings: string[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* One-row outcome of a basket allocation.
|
|
27
|
+
*
|
|
28
|
+
* `ok` means the row can be bought with the computed `qty > 0`; every other
|
|
29
|
+
* status explains why nothing was allocated, so the client can show the row
|
|
30
|
+
* without inventing text of its own.
|
|
31
|
+
*/
|
|
32
|
+
export type BasketRowStatus = 'ok' | 'zero_lot' | 'no_quote' | 'suspended';
|
|
33
|
+
/** A CSV problem; `line` is 1-based, 0 means the whole file. */
|
|
34
|
+
export interface BasketIssue {
|
|
35
|
+
line: number;
|
|
36
|
+
message: string;
|
|
37
|
+
}
|
|
38
|
+
/** One allocated row of `basket/preview`; the client renders this verbatim. */
|
|
39
|
+
export interface BasketPlanRow {
|
|
40
|
+
/** Canonical id, e.g. `000001.SZ`. */
|
|
41
|
+
symbol: string;
|
|
42
|
+
name?: string;
|
|
43
|
+
/** Normalised weight, 0..1. */
|
|
44
|
+
weight: number;
|
|
45
|
+
/** `floor(budgetCents * weight)`, before the fee buy-back. */
|
|
46
|
+
targetCents: number;
|
|
47
|
+
price?: number;
|
|
48
|
+
qty: number;
|
|
49
|
+
amountCents: number;
|
|
50
|
+
feesCents: number;
|
|
51
|
+
/** `amountCents / budgetCents`; rows without allocation report 0. */
|
|
52
|
+
actualWeight: number;
|
|
53
|
+
status: BasketRowStatus;
|
|
54
|
+
warning?: string;
|
|
55
|
+
}
|
|
56
|
+
/** `basket/preview`: parse + allocation, read-only. */
|
|
57
|
+
export interface BasketPreview {
|
|
58
|
+
/** Effective budget: min(user input, available cash). */
|
|
59
|
+
budgetCents: number;
|
|
60
|
+
/** Available cash before the basket. */
|
|
61
|
+
cashCents: number;
|
|
62
|
+
rows: BasketPlanRow[];
|
|
63
|
+
issues: BasketIssue[];
|
|
64
|
+
warnings: string[];
|
|
65
|
+
totalAmountCents: number;
|
|
66
|
+
totalFeesCents: number;
|
|
67
|
+
/** `budgetCents - totalAmountCents - totalFeesCents`. */
|
|
68
|
+
residualCents: number;
|
|
69
|
+
/** `cashCents - totalAmountCents - totalFeesCents`. */
|
|
70
|
+
cashAfterCents: number;
|
|
71
|
+
session: MarketStatus;
|
|
72
|
+
}
|
|
73
|
+
/** One confirmed row of a basket order; the caller sends back preview quantities. */
|
|
74
|
+
export interface BasketOrderInput {
|
|
75
|
+
/** Canonical id, e.g. `000001.SZ`. */
|
|
76
|
+
symbol: string;
|
|
77
|
+
/** 100-share multiple, > 0. */
|
|
78
|
+
qty: number;
|
|
79
|
+
}
|
|
80
|
+
export interface BasketOrderRowResult {
|
|
81
|
+
symbol: string;
|
|
82
|
+
order?: OrderView;
|
|
83
|
+
/** Present when the row was rejected; the readable reason, not just a code. */
|
|
84
|
+
error?: string;
|
|
85
|
+
}
|
|
86
|
+
/** `basket/place`: per-row outcome plus the cash left after the whole batch. */
|
|
87
|
+
export interface BasketOrderResult {
|
|
88
|
+
batchId: string;
|
|
89
|
+
rows: BasketOrderRowResult[];
|
|
90
|
+
cashAfterCents: number;
|
|
91
|
+
}
|
|
92
|
+
export interface EquityPoint {
|
|
93
|
+
date: string;
|
|
94
|
+
equity: number;
|
|
95
|
+
cash: number;
|
|
96
|
+
}
|
|
97
|
+
export interface ReviewView {
|
|
98
|
+
equityCurve: EquityPoint[];
|
|
99
|
+
maxDrawdownPct: number;
|
|
100
|
+
tradeCount: number;
|
|
101
|
+
buyCount: number;
|
|
102
|
+
sellCount: number;
|
|
103
|
+
totalFees: number;
|
|
104
|
+
realizedPnl: number;
|
|
105
|
+
days: number;
|
|
106
|
+
}
|
|
107
|
+
export interface TickView {
|
|
108
|
+
tradeDate: string;
|
|
109
|
+
filled: OrderView[];
|
|
110
|
+
expired: OrderView[];
|
|
111
|
+
quotes: Quote[];
|
|
112
|
+
notices: string[];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Which trading-day source answered, and why it degraded.
|
|
116
|
+
*
|
|
117
|
+
* `fallback` means Monday–Friday is being used instead of the exchange
|
|
118
|
+
* calendar, so holidays are treated as trading days until the source recovers.
|
|
119
|
+
*/
|
|
120
|
+
export interface CalendarStatus {
|
|
121
|
+
source: 'ftshare' | 'fallback';
|
|
122
|
+
/** Why the fallback is in use; present only while degraded. */
|
|
123
|
+
reason?: string;
|
|
124
|
+
/** ISO-8601 of the last check against the source. */
|
|
125
|
+
checkedAt?: string;
|
|
126
|
+
}
|
|
127
|
+
export interface MarketStatus {
|
|
128
|
+
phase: SessionPhase;
|
|
129
|
+
tradeDate: string;
|
|
130
|
+
canSubmit: boolean;
|
|
131
|
+
canMatch: boolean;
|
|
132
|
+
/** ISO-8601 of the next phase boundary. */
|
|
133
|
+
nextBoundary?: string;
|
|
134
|
+
reason?: string;
|
|
135
|
+
/** Trading-day source; `fallback` means the session table is a weekday estimate. */
|
|
136
|
+
calendar?: CalendarStatus;
|
|
137
|
+
}
|
|
138
|
+
export interface PriceLimit {
|
|
139
|
+
upper: number;
|
|
140
|
+
lower: number;
|
|
141
|
+
ratio: number;
|
|
142
|
+
source: 'prev-close' | 'limit-list' | 'unknown';
|
|
143
|
+
}
|
|
144
|
+
export interface SymbolHit {
|
|
145
|
+
/** Canonical id, e.g. `000001.SZ`. */
|
|
146
|
+
symbol: string;
|
|
147
|
+
name: string;
|
|
148
|
+
}
|
|
149
|
+
export interface MarketListResult {
|
|
150
|
+
state: DataState;
|
|
151
|
+
quotes: Quote[];
|
|
152
|
+
page: number;
|
|
153
|
+
total?: number;
|
|
154
|
+
notice?: string;
|
|
155
|
+
/** Upstream error code (e.g. `route_not_allowed`), for the banner reason. */
|
|
156
|
+
noticeCode?: string;
|
|
157
|
+
}
|
|
158
|
+
export interface DayReport {
|
|
159
|
+
date: string;
|
|
160
|
+
equity: number;
|
|
161
|
+
cash: number;
|
|
162
|
+
dayPnl: number;
|
|
163
|
+
fees: number;
|
|
164
|
+
available: number;
|
|
165
|
+
positions: PositionView[];
|
|
166
|
+
gaps: Record<string, number>;
|
|
167
|
+
closeSource: 'daily' | 'last' | 'missing';
|
|
168
|
+
}
|
|
169
|
+
export interface CashFlowEntry {
|
|
170
|
+
ts: string;
|
|
171
|
+
type: 'open' | 'reset' | 'buy' | 'sell' | 'deposit' | 'withdraw';
|
|
172
|
+
amount: number;
|
|
173
|
+
balance: number;
|
|
174
|
+
ref?: string;
|
|
175
|
+
}
|
|
176
|
+
export interface ShortlistView {
|
|
177
|
+
symbols: string[];
|
|
178
|
+
}
|
|
179
|
+
export interface RoundTrip {
|
|
180
|
+
symbol: string;
|
|
181
|
+
name?: string;
|
|
182
|
+
qty: number;
|
|
183
|
+
cost: number;
|
|
184
|
+
proceeds: number;
|
|
185
|
+
pnl: number;
|
|
186
|
+
holdingDays: number;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Which data source the panel is pricing against.
|
|
190
|
+
*
|
|
191
|
+
* `configured` — an FTShare API key is configured and usable.
|
|
192
|
+
* `free` — no key: the anonymous free tier (daily-close quotes, 500/day).
|
|
193
|
+
* `none` — the FTShare data service is not installed.
|
|
194
|
+
* `invalid` — a key exists but cannot be used (rejected or unreadable).
|
|
195
|
+
*/
|
|
196
|
+
//# sourceMappingURL=domain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../src/contract/domain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAE3G,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,SAAS,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,CAAA;AAE1E,gEAAgE;AAChE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,+EAA+E;AA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;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;;GAOG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stock trading views: ticket, orders, positions, review, market, symbols.
|
|
3
|
+
* @module @dsh-ft/dsh-fft-paper-trading/contract/domain
|
|
4
|
+
*/
|
|
5
|
+
export {};
|
|
6
|
+
/**
|
|
7
|
+
* Which data source the panel is pricing against.
|
|
8
|
+
*
|
|
9
|
+
* `configured` — an FTShare API key is configured and usable.
|
|
10
|
+
* `free` — no key: the anonymous free tier (daily-close quotes, 500/day).
|
|
11
|
+
* `none` — the FTShare data service is not installed.
|
|
12
|
+
* `invalid` — a key exists but cannot be used (rejected or unreadable).
|
|
13
|
+
*/
|
|
14
|
+
//# sourceMappingURL=domain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.js","sourceRoot":"","sources":["../../src/contract/domain.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AA8MH;;;;;;;GAOG"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes surfaced through RpcFailure and the agent tools.
|
|
3
|
+
* @module @dsh-ft/dsh-fft-paper-trading/contract/errors
|
|
4
|
+
*/
|
|
5
|
+
export type ErrorCode = 'ACCOUNT_BLOCKED' | 'INVALID_ARGUMENT' | 'INVALID_SYMBOL' | 'INVALID_QTY' | 'INVALID_LOT' | 'INSUFFICIENT_CASH' | 'INSUFFICIENT_POSITION' | 'T1_LOCKED' | 'MAX_NOTIONAL' | 'ORDER_NOT_FOUND' | 'ORDER_NOT_PENDING' | 'QUOTE_UNAVAILABLE' | 'SESSION_CLOSED' | 'AUCTION_ONLY' | 'PRICE_LIMIT' | 'SUSPENDED' | 'UNSUPPORTED_INSTRUMENT' | 'LEDGER_RESTORE_FAILED' | 'ACCOUNT_NOT_FOUND' | 'ACCOUNT_LIMIT' | 'ACCOUNT_LOCKED' | 'ACCOUNT_ARCHIVED' | 'INSUFFICIENT_MARGIN' | 'CONTRACT_NOT_FOUND' | 'CONTRACT_EXPIRED' | 'NO_VOLUME' | 'LIMIT_UNAVAILABLE' | 'MARGIN_UNAVAILABLE';
|
|
6
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/contract/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,SAAS,GACjB,iBAAiB,GACjB,kBAAkB,GAClB,gBAAgB,GAChB,aAAa,GACb,aAAa,GACb,mBAAmB,GACnB,uBAAuB,GACvB,WAAW,GACX,cAAc,GACd,iBAAiB,GACjB,mBAAmB,GACnB,mBAAmB,GACnB,gBAAgB,GAChB,cAAc,GACd,aAAa,GACb,WAAW,GACX,wBAAwB,GACxB,uBAAuB,GACvB,mBAAmB,GACnB,eAAe,GACf,gBAAgB,GAChB,kBAAkB,GAClB,qBAAqB,GACrB,oBAAoB,GACpB,kBAAkB,GAClB,WAAW,GACX,mBAAmB,GACnB,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/contract/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The paper-trading contract, split by domain.
|
|
3
|
+
*
|
|
4
|
+
* Consumers keep importing `../contract.js` (a barrel); a module that only
|
|
5
|
+
* needs one area can import it directly from here.
|
|
6
|
+
* @module @dsh-ft/dsh-fft-paper-trading/contract
|
|
7
|
+
*/
|
|
8
|
+
export * from './common.js';
|
|
9
|
+
export * from './accounts.js';
|
|
10
|
+
export * from './domain.js';
|
|
11
|
+
export * from './ledger.js';
|
|
12
|
+
export * from './market.js';
|
|
13
|
+
export * from './rpc.js';
|
|
14
|
+
export * from './errors.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contract/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The paper-trading contract, split by domain.
|
|
3
|
+
*
|
|
4
|
+
* Consumers keep importing `../contract.js` (a barrel); a module that only
|
|
5
|
+
* needs one area can import it directly from here.
|
|
6
|
+
* @module @dsh-ft/dsh-fft-paper-trading/contract
|
|
7
|
+
*/
|
|
8
|
+
export * from './common.js';
|
|
9
|
+
export * from './accounts.js';
|
|
10
|
+
export * from './domain.js';
|
|
11
|
+
export * from './ledger.js';
|
|
12
|
+
export * from './market.js';
|
|
13
|
+
export * from './rpc.js';
|
|
14
|
+
export * from './errors.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contract/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ledger recovery views (export, snapshots).
|
|
3
|
+
* @module @dsh-ft/dsh-fft-paper-trading/contract/ledger
|
|
4
|
+
*/
|
|
5
|
+
/** `account/export`: the raw ledger file, so a locked account can be inspected. */
|
|
6
|
+
export interface LedgerExport {
|
|
7
|
+
/** Absolute path of `events.jsonl`. */
|
|
8
|
+
path: string;
|
|
9
|
+
/** False when no ledger file exists yet. */
|
|
10
|
+
exists: boolean;
|
|
11
|
+
/** Raw JSONL text; omitted when `exists` is false. */
|
|
12
|
+
content?: string;
|
|
13
|
+
notice?: string;
|
|
14
|
+
}
|
|
15
|
+
/** One ledger snapshot as listed to the panel, an agent, or a human. */
|
|
16
|
+
export interface LedgerSnapshotView {
|
|
17
|
+
name: string;
|
|
18
|
+
createdAt: string;
|
|
19
|
+
bytes: number;
|
|
20
|
+
/** Version stored in the snapshot, before any migration. */
|
|
21
|
+
ledgerVersion: number;
|
|
22
|
+
lastSeq: number;
|
|
23
|
+
tradeDate: string;
|
|
24
|
+
/** Free cash at that point, in yuan. */
|
|
25
|
+
cash: number;
|
|
26
|
+
/** Replays cleanly at the current ledger version (after migration). */
|
|
27
|
+
valid: boolean;
|
|
28
|
+
/** Needs the loader's migration step before restoring. */
|
|
29
|
+
migratable: boolean;
|
|
30
|
+
problem?: string;
|
|
31
|
+
}
|
|
32
|
+
/** `ledger/list`: everything needed to choose a recovery point. */
|
|
33
|
+
export interface LedgerSnapshotsView {
|
|
34
|
+
path: string;
|
|
35
|
+
blocked: boolean;
|
|
36
|
+
blockedReason?: string;
|
|
37
|
+
ledgerVersion?: number;
|
|
38
|
+
snapshots: LedgerSnapshotView[];
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../src/contract/ledger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mFAAmF;AACnF,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,4CAA4C;IAC5C,MAAM,EAAE,OAAO,CAAA;IACf,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,wEAAwE;AACxE,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,4DAA4D;IAC5D,aAAa,EAAE,MAAM,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAA;IACZ,uEAAuE;IACvE,KAAK,EAAE,OAAO,CAAA;IACd,0DAA0D;IAC1D,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,mEAAmE;AACnE,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,kBAAkB,EAAE,CAAA;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/contract/ledger.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Round trips and market-data-source state.
|
|
3
|
+
* @module @dsh-ft/dsh-fft-paper-trading/contract/market
|
|
4
|
+
*/
|
|
5
|
+
export type DataSourceState = 'configured' | 'free' | 'none' | 'invalid';
|
|
6
|
+
/**
|
|
7
|
+
* Why the last market-data call failed, as a code the UI can act on.
|
|
8
|
+
*
|
|
9
|
+
* The upstream classification (`state` + `notice.code`) decides this. Text is
|
|
10
|
+
* only read for one thing the codes cannot express: a spent quota shares its
|
|
11
|
+
* code with a real outage, so the exhausted wording is matched instead.
|
|
12
|
+
*/
|
|
13
|
+
export type DataProblemReason = 'no-key' | 'invalid-key' | 'plan-denied' | 'quota' | 'network' | 'upstream';
|
|
14
|
+
/** One observed data failure; the latest one drives the panel banner. */
|
|
15
|
+
export interface DataProblem {
|
|
16
|
+
reason: DataProblemReason;
|
|
17
|
+
/** Readable upstream cause, already trimmed for display. */
|
|
18
|
+
message: string;
|
|
19
|
+
/** ISO-8601 time of the observation. */
|
|
20
|
+
at: string;
|
|
21
|
+
}
|
|
22
|
+
/** Read-only data-source state for the panel header; never carries the key itself. */
|
|
23
|
+
export interface DataSourceStatus {
|
|
24
|
+
state: DataSourceState;
|
|
25
|
+
/** Short, user-facing cause for `invalid` or a degraded `configured`. */
|
|
26
|
+
message?: string;
|
|
27
|
+
/** Latest observed data failure, cleared by the next successful quote call. */
|
|
28
|
+
problem?: DataProblem;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=market.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"market.d.ts","sourceRoot":"","sources":["../../src/contract/market.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;AAExE;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,aAAa,GACb,aAAa,GACb,OAAO,GACP,SAAS,GACT,UAAU,CAAA;AAEd,yEAAyE;AACzE,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,iBAAiB,CAAA;IACzB,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAA;IACf,wCAAwC;IACxC,EAAE,EAAE,MAAM,CAAA;CACX;AAED,sFAAsF;AACtF,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,eAAe,CAAA;IACtB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,WAAW,CAAA;CACtB"}
|