@dsh-ft/dsh-fft-paper-trading 0.7.2 → 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 +4 -3
- package/README.zh.md +4 -3
- 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,706 @@
|
|
|
1
|
+
/* 60 · shell — top-level Dashboard and the stock dashboard (state + effects). */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Top-level shell: the account switch lives above both dashboards, so the
|
|
5
|
+
* stock half keeps its exact layout and the futures half mounts on demand.
|
|
6
|
+
*/
|
|
7
|
+
function Dashboard({ renderSlot } = {}) {
|
|
8
|
+
const [accountMode, setAccountMode] = useState('stock')
|
|
9
|
+
const accountSwitch = h(AccountSwitch, { mode: accountMode, onChange: setAccountMode })
|
|
10
|
+
return h('div', { className: 'pt-root' },
|
|
11
|
+
h('style', null, CSS),
|
|
12
|
+
accountMode === 'futures'
|
|
13
|
+
? h(FuturesDashboard, { accountSwitch })
|
|
14
|
+
: h(StockDashboard, { renderSlot, accountSwitch }),
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function StockDashboard({ renderSlot, accountSwitch }) {
|
|
19
|
+
const [account, setAccount] = useState(null)
|
|
20
|
+
const [orders, setOrders] = useState([])
|
|
21
|
+
const [trades, setTrades] = useState([])
|
|
22
|
+
const [review, setReview] = useState(null)
|
|
23
|
+
const [period, setPeriod] = useState('30d')
|
|
24
|
+
const periodRef = useRef(period)
|
|
25
|
+
useEffect(() => { periodRef.current = period }, [period])
|
|
26
|
+
const [tab, setTab] = useState('trade')
|
|
27
|
+
const [compareData, setCompareData] = useState(null)
|
|
28
|
+
const [compareError, setCompareError] = useState('')
|
|
29
|
+
const [error, setError] = useState(null)
|
|
30
|
+
const [notice, setNotice] = useState('')
|
|
31
|
+
const [busy, setBusy] = useState(false)
|
|
32
|
+
const [layout, applyLayout] = useRailLayout('stock')
|
|
33
|
+
const [resetNonce, setResetNonce] = useState(0)
|
|
34
|
+
// Inline cash panel (注资/提款), hidden until the header button is pressed.
|
|
35
|
+
const [cashOpen, setCashOpen] = useState(false)
|
|
36
|
+
const [cashSide, setCashSide] = useState('deposit')
|
|
37
|
+
const [cashAmount, setCashAmount] = useState('')
|
|
38
|
+
// Inline reset strip: picking the starting cash is part of the reset, so
|
|
39
|
+
// it replaces the browser confirm dialog instead of living in settings.
|
|
40
|
+
const [resetOpen, setResetOpen] = useState(false)
|
|
41
|
+
const [resetCash, setResetCash] = useState('')
|
|
42
|
+
const submitting = useRef(false)
|
|
43
|
+
const placeKey = useRef({ key: '', id: '' })
|
|
44
|
+
const [dataSource, setDataSource] = useState(null)
|
|
45
|
+
const [receipt, setReceipt] = useState(null)
|
|
46
|
+
const [session, setSession] = useState(null)
|
|
47
|
+
const [searchQuery, setSearchQuery] = useState('')
|
|
48
|
+
const [searchHits, setSearchHits] = useState([])
|
|
49
|
+
const [searchAttempted, setSearchAttempted] = useState(false)
|
|
50
|
+
const [marketList, setMarketList] = useState(null)
|
|
51
|
+
const [marketBoard, setMarketBoard] = useState('main')
|
|
52
|
+
const [bars, setBars] = useState([])
|
|
53
|
+
const [barError, setBarError] = useState('')
|
|
54
|
+
const barsSeq = useRef(0)
|
|
55
|
+
const [barInterval, setBarInterval] = useState('day')
|
|
56
|
+
const [daily, setDaily] = useState([])
|
|
57
|
+
const [cashFlow, setCashFlow] = useState([])
|
|
58
|
+
const [trips, setTrips] = useState([])
|
|
59
|
+
const [shortlist, setShortlist] = useState([])
|
|
60
|
+
// Read/write the shortlist through a ref so two clicks in one task see
|
|
61
|
+
// each other's optimistic change instead of both computing from stale
|
|
62
|
+
// state (which silently dropped the first symbol).
|
|
63
|
+
const shortlistRef = useRef([])
|
|
64
|
+
const shortlistSeq = useRef(0)
|
|
65
|
+
const searchSeq = useRef(0)
|
|
66
|
+
const marketSeq = useRef(0)
|
|
67
|
+
useEffect(() => { shortlistRef.current = shortlist }, [shortlist])
|
|
68
|
+
const [shortlistOnly, setShortlistOnly] = useState(false)
|
|
69
|
+
const [form, setForm] = useState({
|
|
70
|
+
symbol: '600519.SH',
|
|
71
|
+
side: 'buy',
|
|
72
|
+
type: 'market',
|
|
73
|
+
qty: '',
|
|
74
|
+
limitPrice: '',
|
|
75
|
+
price: '',
|
|
76
|
+
note: '',
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const accountScope = useRef(null)
|
|
80
|
+
/** This mount's account-scoped request; an explicit account wins (notes). */
|
|
81
|
+
const request = useCallback((endpoint, payload, account) =>
|
|
82
|
+
rpc(endpoint, payload, account === undefined ? accountScope.current : account), [])
|
|
83
|
+
|
|
84
|
+
const ticket = useTicketPreview(request, form)
|
|
85
|
+
const {
|
|
86
|
+
preview, previewState, previewError, symbolQuote, quote, quoteError, quoteNotice,
|
|
87
|
+
previewDraft, draft, maybeRefreshQuote, forceQuoteRefresh, invalidate: invalidateTicket, bump: bumpTicket,
|
|
88
|
+
} = ticket
|
|
89
|
+
|
|
90
|
+
const alive = useRef(true)
|
|
91
|
+
const loadAllSeq = useRef(0)
|
|
92
|
+
const detailSeq = useRef(0)
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
alive.current = true
|
|
95
|
+
return () => { alive.current = false }
|
|
96
|
+
}, [])
|
|
97
|
+
|
|
98
|
+
const formSymbol = useRef(form.symbol)
|
|
99
|
+
useEffect(() => { formSymbol.current = form.symbol }, [form.symbol])
|
|
100
|
+
|
|
101
|
+
const loadAll = useCallback(async (quiet = false, reviewPeriod = periodRef.current) => {
|
|
102
|
+
const seq = ++loadAllSeq.current
|
|
103
|
+
const requestedPeriod = reviewPeriod
|
|
104
|
+
try {
|
|
105
|
+
const [nextAccount, nextOrders, nextTrades, nextReview, nextSession, nextDataSource] = await Promise.all([
|
|
106
|
+
request('account/get'),
|
|
107
|
+
request('list/orders'),
|
|
108
|
+
request('list/trades'),
|
|
109
|
+
request('review/get', { period: reviewPeriod }),
|
|
110
|
+
request('market/status'),
|
|
111
|
+
request('market/data-source'),
|
|
112
|
+
])
|
|
113
|
+
if (!alive.current) return null
|
|
114
|
+
// A poll started before a period switch carries the old review;
|
|
115
|
+
// newer requests own the page state, but callers still get their own
|
|
116
|
+
// snapshot (order receipts need the fresh cash).
|
|
117
|
+
if (seq === loadAllSeq.current && requestedPeriod === periodRef.current) {
|
|
118
|
+
setAccount(nextAccount)
|
|
119
|
+
setOrders(nextOrders)
|
|
120
|
+
setTrades(nextTrades)
|
|
121
|
+
setReview(nextReview)
|
|
122
|
+
setSession(nextSession)
|
|
123
|
+
setDataSource(nextDataSource)
|
|
124
|
+
if (!quiet) setError(null)
|
|
125
|
+
}
|
|
126
|
+
return { account: nextAccount, orders: nextOrders, trades: nextTrades }
|
|
127
|
+
} catch (cause) {
|
|
128
|
+
if (alive.current && seq === loadAllSeq.current) setError(errorOf(cause))
|
|
129
|
+
return null
|
|
130
|
+
}
|
|
131
|
+
}, [])
|
|
132
|
+
|
|
133
|
+
const loadReviewDetail = useCallback(async () => {
|
|
134
|
+
const seq = ++detailSeq.current
|
|
135
|
+
try {
|
|
136
|
+
const [nextDaily, nextCash, nextTrips] = await Promise.all([
|
|
137
|
+
request('review/daily'),
|
|
138
|
+
request('cash/flow'),
|
|
139
|
+
request('review/roundtrips'),
|
|
140
|
+
])
|
|
141
|
+
if (!alive.current || seq !== detailSeq.current) return
|
|
142
|
+
setDaily(nextDaily)
|
|
143
|
+
setCashFlow(nextCash)
|
|
144
|
+
setTrips(nextTrips)
|
|
145
|
+
} catch (cause) {
|
|
146
|
+
if (alive.current && seq === detailSeq.current) setError(errorOf(cause))
|
|
147
|
+
}
|
|
148
|
+
}, [])
|
|
149
|
+
|
|
150
|
+
const loadCompare = useCallback(async () => {
|
|
151
|
+
try {
|
|
152
|
+
const view = await request('compare/get')
|
|
153
|
+
if (!alive.current) return
|
|
154
|
+
setCompareData(view)
|
|
155
|
+
setCompareError('')
|
|
156
|
+
} catch (cause) {
|
|
157
|
+
if (alive.current) setCompareError(errorOf(cause).text)
|
|
158
|
+
}
|
|
159
|
+
}, [])
|
|
160
|
+
|
|
161
|
+
// A period switch only re-queries the review bundle. It must not re-run
|
|
162
|
+
// the account-switch effect (which clears the open ticket's preview and
|
|
163
|
+
// receipt); `tab` is read but not a dependency for the same reason.
|
|
164
|
+
const periodMounted = useRef(false)
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (!periodMounted.current) {
|
|
167
|
+
periodMounted.current = true
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
void loadAll(false)
|
|
171
|
+
if (tab === 'review') void loadReviewDetail()
|
|
172
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
173
|
+
}, [period, loadAll, loadReviewDetail])
|
|
174
|
+
|
|
175
|
+
/** Per-account view state cleared on every account switch. */
|
|
176
|
+
const clearAccountView = useCallback(() => {
|
|
177
|
+
setNotice('')
|
|
178
|
+
setReceipt(null)
|
|
179
|
+
ticket.clear()
|
|
180
|
+
}, [ticket.clear])
|
|
181
|
+
|
|
182
|
+
const registry = useAccountRegistry({
|
|
183
|
+
scope: accountScope, request,
|
|
184
|
+
tab,
|
|
185
|
+
loadAll,
|
|
186
|
+
loadReviewDetail,
|
|
187
|
+
loadCompare,
|
|
188
|
+
clearView: clearAccountView,
|
|
189
|
+
setBusy,
|
|
190
|
+
setError,
|
|
191
|
+
setNotice,
|
|
192
|
+
onNotes: () => setTab('notes'),
|
|
193
|
+
})
|
|
194
|
+
const {
|
|
195
|
+
tickMs, stockAccounts, archived, currentAccountId, setCurrentAccountId, currentAccount,
|
|
196
|
+
restoreArchived, accountEditor, setAccountEditor, submitAccountEditor, runAccountAction,
|
|
197
|
+
} = registry
|
|
198
|
+
|
|
199
|
+
const notes = useAccountNotes(request, currentAccountId, tab)
|
|
200
|
+
|
|
201
|
+
const tick = useCallback(async () => {
|
|
202
|
+
try {
|
|
203
|
+
const result = await request('tick')
|
|
204
|
+
if (!alive.current) return
|
|
205
|
+
if (result.filled.length > 0) setNotice(`成交 ${result.filled.length} 笔`)
|
|
206
|
+
if (result.notices.length > 0) setNotice(result.notices.join(';'))
|
|
207
|
+
await loadAll(true, periodRef.current)
|
|
208
|
+
if (alive.current && tab === 'review') await loadReviewDetail()
|
|
209
|
+
if (alive.current && tab === 'compare') await loadCompare()
|
|
210
|
+
// Re-price the open ticket: the quote strip and preview otherwise
|
|
211
|
+
// froze at the moment the symbol was entered.
|
|
212
|
+
if (alive.current) maybeRefreshQuote()
|
|
213
|
+
} catch {
|
|
214
|
+
// Polling failures stay silent; the manual refresh shows the error.
|
|
215
|
+
}
|
|
216
|
+
}, [loadAll, loadReviewDetail, loadCompare, tab, maybeRefreshQuote])
|
|
217
|
+
|
|
218
|
+
// The host scheduler is the primary matcher; this stays as a live extra
|
|
219
|
+
// trigger while the panel is visible.
|
|
220
|
+
useVisiblePolling(tick, tickMs)
|
|
221
|
+
|
|
222
|
+
const loadBars = useCallback(async (symbol = form.symbol) => {
|
|
223
|
+
const seq = ++barsSeq.current
|
|
224
|
+
if (symbol.trim().length < 6) {
|
|
225
|
+
// Do not leave the previous symbol's candles under a new title.
|
|
226
|
+
if (alive.current) { setBars([]); setBarError('') }
|
|
227
|
+
return
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
const result = await request('market/bars', { symbol: symbol.trim(), interval: barInterval, limit: 80 })
|
|
231
|
+
if (!alive.current || seq !== barsSeq.current) return
|
|
232
|
+
if (result.state === 'ok') {
|
|
233
|
+
setBars(result.bars ?? [])
|
|
234
|
+
setBarError('')
|
|
235
|
+
} else {
|
|
236
|
+
setBars([])
|
|
237
|
+
setBarError(result.notice ?? 'K 线数据暂不可用')
|
|
238
|
+
}
|
|
239
|
+
} catch (cause) {
|
|
240
|
+
if (!alive.current || seq !== barsSeq.current) return
|
|
241
|
+
setBars([])
|
|
242
|
+
setBarError('K 线数据暂不可用')
|
|
243
|
+
setError(errorOf(cause))
|
|
244
|
+
}
|
|
245
|
+
}, [form.symbol, barInterval])
|
|
246
|
+
|
|
247
|
+
const runSearch = useCallback(async () => {
|
|
248
|
+
if (!searchQuery.trim()) { setSearchAttempted(false); return }
|
|
249
|
+
setSearchAttempted(true)
|
|
250
|
+
const seq = ++searchSeq.current
|
|
251
|
+
try {
|
|
252
|
+
const hits = await request('market/search', { query: searchQuery.trim(), limit: 12 })
|
|
253
|
+
if (alive.current && seq === searchSeq.current) setSearchHits(hits)
|
|
254
|
+
} catch (cause) {
|
|
255
|
+
if (alive.current && seq === searchSeq.current) setError(errorOf(cause))
|
|
256
|
+
}
|
|
257
|
+
}, [searchQuery])
|
|
258
|
+
|
|
259
|
+
const loadMarket = useCallback(async (page = 1) => {
|
|
260
|
+
const seq = ++marketSeq.current
|
|
261
|
+
try {
|
|
262
|
+
const next = await request('market/list', { board: marketBoard, page, pageSize: 50 })
|
|
263
|
+
if (alive.current && seq === marketSeq.current) setMarketList(next)
|
|
264
|
+
} catch (cause) {
|
|
265
|
+
if (alive.current && seq === marketSeq.current) setError(errorOf(cause))
|
|
266
|
+
}
|
|
267
|
+
}, [marketBoard])
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Only a real K-line selection may rewrite the ticket. dsh_kline calls
|
|
271
|
+
* `onIdentity` on its own during mount/route changes, so an unchanged
|
|
272
|
+
* symbol must not pop "已从 K 线选择 …" over the user's real feedback.
|
|
273
|
+
*/
|
|
274
|
+
const klineIdentity = useCallback((symbol, name) => {
|
|
275
|
+
const next = foldHostSymbol(symbol)
|
|
276
|
+
if (!next || next === String(formSymbol.current).trim().toUpperCase()) return
|
|
277
|
+
formSymbol.current = next
|
|
278
|
+
setForm(prev => ({ ...prev, symbol: next }))
|
|
279
|
+
setNotice(name ? `已从 K 线选择 ${name}` : '')
|
|
280
|
+
}, [])
|
|
281
|
+
|
|
282
|
+
useEffect(() => { void loadBars() }, [loadBars])
|
|
283
|
+
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
if (tab === 'review') void loadReviewDetail()
|
|
286
|
+
if (tab === 'compare') void loadCompare()
|
|
287
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
288
|
+
}, [tab, loadReviewDetail, loadCompare])
|
|
289
|
+
|
|
290
|
+
useEffect(() => {
|
|
291
|
+
if (tab === 'market') {
|
|
292
|
+
void loadMarket(1)
|
|
293
|
+
request('shortlist/get').then(result => { if (alive.current) setShortlist(result.symbols ?? []) }).catch(() => {})
|
|
294
|
+
}
|
|
295
|
+
}, [tab, marketBoard, loadMarket])
|
|
296
|
+
|
|
297
|
+
const isShortlisted = useCallback(symbol => shortlisted(shortlist, symbol), [shortlist])
|
|
298
|
+
|
|
299
|
+
const toggleShortlist = useCallback(async (symbol) => {
|
|
300
|
+
const code = symbol
|
|
301
|
+
// The server only ever sends canonical ids, and the same id is what the
|
|
302
|
+
// shortlist keeps, so one favourite cannot split across markets.
|
|
303
|
+
const current = shortlistRef.current
|
|
304
|
+
const next = current.some(item => item === code)
|
|
305
|
+
? current.filter(item => item !== code)
|
|
306
|
+
: [...current, code]
|
|
307
|
+
shortlistRef.current = next
|
|
308
|
+
setShortlist(next)
|
|
309
|
+
const seq = ++shortlistSeq.current
|
|
310
|
+
try {
|
|
311
|
+
const result = await request('shortlist/set', { symbols: next })
|
|
312
|
+
if (!alive.current || seq !== shortlistSeq.current) return
|
|
313
|
+
shortlistRef.current = result.symbols ?? next
|
|
314
|
+
setShortlist(result.symbols ?? next)
|
|
315
|
+
} catch (cause) {
|
|
316
|
+
if (!alive.current) return
|
|
317
|
+
setError(errorOf(cause))
|
|
318
|
+
// The server is the source of truth after a failed write.
|
|
319
|
+
try {
|
|
320
|
+
const fresh = await request('shortlist/get')
|
|
321
|
+
if (alive.current && seq === shortlistSeq.current) {
|
|
322
|
+
shortlistRef.current = fresh.symbols ?? []
|
|
323
|
+
setShortlist(fresh.symbols ?? [])
|
|
324
|
+
}
|
|
325
|
+
} catch { /* keep the optimistic state */ }
|
|
326
|
+
}
|
|
327
|
+
}, [])
|
|
328
|
+
|
|
329
|
+
const adoptQuote = useCallback(symbol => {
|
|
330
|
+
const next = symbol
|
|
331
|
+
formSymbol.current = next
|
|
332
|
+
setForm(prev => ({ ...prev, symbol: next }))
|
|
333
|
+
setTab('trade')
|
|
334
|
+
}, [])
|
|
335
|
+
|
|
336
|
+
const doSubmit = useCallback(async () => {
|
|
337
|
+
if (submitting.current) return
|
|
338
|
+
submitting.current = true
|
|
339
|
+
setBusy(true)
|
|
340
|
+
setReceipt(null)
|
|
341
|
+
try {
|
|
342
|
+
const current = draft()
|
|
343
|
+
const key = JSON.stringify(current)
|
|
344
|
+
if (placeKey.current.key !== key) {
|
|
345
|
+
placeKey.current = {
|
|
346
|
+
key,
|
|
347
|
+
id: typeof crypto !== 'undefined' && crypto.randomUUID ? crypto.randomUUID() : `req-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const order = await request('order/place', { draft: current, requestId: placeKey.current.id })
|
|
351
|
+
const snapshot = await loadAll(true)
|
|
352
|
+
const fill = snapshot === null ? undefined : snapshot.trades.find(item => item.orderId === order.id)
|
|
353
|
+
setReceipt({ order, fill, cash: snapshot === null ? undefined : snapshot.account.cash })
|
|
354
|
+
placeKey.current = { key: '', id: '' }
|
|
355
|
+
// Keep the card's numbers; recompute them against the new cash.
|
|
356
|
+
bumpTicket()
|
|
357
|
+
} catch (cause) {
|
|
358
|
+
setReceipt({ failure: errorOf(cause) })
|
|
359
|
+
} finally {
|
|
360
|
+
submitting.current = false
|
|
361
|
+
setBusy(false)
|
|
362
|
+
}
|
|
363
|
+
}, [draft, loadAll])
|
|
364
|
+
|
|
365
|
+
const cancel = useCallback(async orderId => {
|
|
366
|
+
setBusy(true)
|
|
367
|
+
try {
|
|
368
|
+
await request('order/cancel', { orderId })
|
|
369
|
+
await loadAll(true)
|
|
370
|
+
} catch (cause) {
|
|
371
|
+
// A lost response can make the retry see an already-finished order;
|
|
372
|
+
// resync instead of claiming the cancel failed.
|
|
373
|
+
if (cause && (cause.code === 'ORDER_NOT_PENDING' || cause.code === 'ORDER_NOT_FOUND')) {
|
|
374
|
+
setNotice('订单已结束,列表已刷新')
|
|
375
|
+
await loadAll(true)
|
|
376
|
+
} else {
|
|
377
|
+
setError(errorOf(cause))
|
|
378
|
+
}
|
|
379
|
+
} finally {
|
|
380
|
+
setBusy(false)
|
|
381
|
+
}
|
|
382
|
+
}, [loadAll])
|
|
383
|
+
|
|
384
|
+
const copyLedgerPath = useCallback(async () => {
|
|
385
|
+
const path = account !== null ? account.ledgerPath : undefined
|
|
386
|
+
if (path === undefined) return
|
|
387
|
+
const copied = typeof navigator !== 'undefined' && navigator.clipboard && navigator.clipboard.writeText
|
|
388
|
+
? await navigator.clipboard.writeText(path).then(() => true, () => false)
|
|
389
|
+
: false
|
|
390
|
+
setNotice(copied ? `已复制账本路径:${path}` : `账本路径:${path}`)
|
|
391
|
+
}, [account])
|
|
392
|
+
|
|
393
|
+
const exportLedger = useCallback(async () => {
|
|
394
|
+
try {
|
|
395
|
+
const result = await request('account/export')
|
|
396
|
+
if (!result.exists || !result.content) {
|
|
397
|
+
setNotice(result.notice ?? '账本文件尚未创建')
|
|
398
|
+
return
|
|
399
|
+
}
|
|
400
|
+
if (typeof document !== 'undefined' && typeof URL !== 'undefined' && typeof Blob !== 'undefined') {
|
|
401
|
+
const blob = new Blob([result.content], { type: 'application/x-ndjson' })
|
|
402
|
+
const url = URL.createObjectURL(blob)
|
|
403
|
+
const link = document.createElement('a')
|
|
404
|
+
link.href = url
|
|
405
|
+
link.download = 'paper-trading-events.jsonl'
|
|
406
|
+
link.click()
|
|
407
|
+
URL.revokeObjectURL(url)
|
|
408
|
+
}
|
|
409
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard && navigator.clipboard.writeText) {
|
|
410
|
+
await navigator.clipboard.writeText(result.path).catch(() => {})
|
|
411
|
+
}
|
|
412
|
+
setNotice(`已导出账本:${result.path}`)
|
|
413
|
+
} catch (cause) {
|
|
414
|
+
setError(errorOf(cause))
|
|
415
|
+
}
|
|
416
|
+
}, [])
|
|
417
|
+
|
|
418
|
+
const reset = useCallback(async () => {
|
|
419
|
+
const cents = cashAmountCents(resetCash)
|
|
420
|
+
if (cents === null) return
|
|
421
|
+
setBusy(true)
|
|
422
|
+
try {
|
|
423
|
+
setAccount(await request('account/reset', { confirm: true, initialCash: cents / 100 }))
|
|
424
|
+
invalidateTicket()
|
|
425
|
+
setReceipt(null)
|
|
426
|
+
await loadAll(true)
|
|
427
|
+
await loadReviewDetail()
|
|
428
|
+
bumpTicket()
|
|
429
|
+
setResetNonce(value => value + 1)
|
|
430
|
+
setResetOpen(false)
|
|
431
|
+
setResetCash('')
|
|
432
|
+
setNotice(`账户已重置,初始资金 ${money(cents / 100)}`)
|
|
433
|
+
} catch (cause) {
|
|
434
|
+
setError(errorOf(cause))
|
|
435
|
+
} finally {
|
|
436
|
+
setBusy(false)
|
|
437
|
+
}
|
|
438
|
+
}, [resetCash, loadAll, loadReviewDetail])
|
|
439
|
+
|
|
440
|
+
/** 注资/提款:写一条账本事件,现金与总资产随之更新,盈亏剔除净入金。 */
|
|
441
|
+
const moveCash = useCallback(async () => {
|
|
442
|
+
const cents = cashAmountCents(cashAmount)
|
|
443
|
+
if (cents === null) return
|
|
444
|
+
const amount = cents / 100
|
|
445
|
+
const depositing = cashSide === 'deposit'
|
|
446
|
+
setBusy(true)
|
|
447
|
+
try {
|
|
448
|
+
setAccount(await request(depositing ? 'account/deposit' : 'account/withdraw', { amount }))
|
|
449
|
+
await loadAll(true)
|
|
450
|
+
await loadReviewDetail()
|
|
451
|
+
bumpTicket()
|
|
452
|
+
setCashAmount('')
|
|
453
|
+
setCashOpen(false)
|
|
454
|
+
setError(null)
|
|
455
|
+
setNotice(depositing ? `已注资 ${money(amount)}` : `已提款 ${money(amount)}`)
|
|
456
|
+
} catch (cause) {
|
|
457
|
+
setError(errorOf(cause))
|
|
458
|
+
} finally {
|
|
459
|
+
setBusy(false)
|
|
460
|
+
}
|
|
461
|
+
}, [cashAmount, cashSide, loadAll, loadReviewDetail])
|
|
462
|
+
|
|
463
|
+
/** Header refresh: account/orders/trades/review plus one fresh preview. */
|
|
464
|
+
const refreshAll = useCallback(async () => {
|
|
465
|
+
setBusy(true)
|
|
466
|
+
try {
|
|
467
|
+
await loadAll()
|
|
468
|
+
if (tab === 'review') await loadReviewDetail()
|
|
469
|
+
if (tab === 'compare') await loadCompare()
|
|
470
|
+
// 刷新 must also retry the current tab's own fetch, not just the
|
|
471
|
+
// account bundle: a failed market list otherwise stays broken.
|
|
472
|
+
if (tab === 'market') await loadMarket(marketList?.page ?? 1)
|
|
473
|
+
// Force the incomplete-draft quote branch to fetch again even when
|
|
474
|
+
// the symbol did not change (a transient quote failure is retryable).
|
|
475
|
+
forceQuoteRefresh()
|
|
476
|
+
} finally {
|
|
477
|
+
setBusy(false)
|
|
478
|
+
}
|
|
479
|
+
}, [loadAll, loadReviewDetail, tab, loadMarket, marketList?.page, forceQuoteRefresh])
|
|
480
|
+
|
|
481
|
+
/** Only real blockers disable submit; a failed preview never does. */
|
|
482
|
+
/** Read the flag outside the deps array: `account` is null on the first render. */
|
|
483
|
+
const blocked = account?.blocked === true
|
|
484
|
+
const submitReason = useMemo(() => {
|
|
485
|
+
if (account === null) return '加载账户中'
|
|
486
|
+
if (currentAccount !== null && currentAccount.locked) return '账户已锁定,先在账户菜单解锁'
|
|
487
|
+
if (blocked) return '账本异常,需恢复或重置'
|
|
488
|
+
const symbol = form.symbol.trim()
|
|
489
|
+
if (symbol.length < 6) return '输入代码'
|
|
490
|
+
if (String(form.qty).trim() === '') return '填写数量'
|
|
491
|
+
const qty = Number(form.qty)
|
|
492
|
+
if (!Number.isInteger(qty) || qty <= 0) return '数量需为正整数'
|
|
493
|
+
if (form.side === 'buy' && qty % 100 !== 0) return '买入需 100 股整数倍'
|
|
494
|
+
if (form.type === 'limit' && !(Number(form.limitPrice) > 0)) return '填写限价'
|
|
495
|
+
if (session !== null && session.phase === 'auction_close') return '收盘竞价暂不支持模拟撮合'
|
|
496
|
+
if (form.type === 'market' && quote === null && !(Number(form.price) > 0)) return '无行情,请填参考价'
|
|
497
|
+
if (preview !== null && preview.quote?.status === 'suspended') return '停牌'
|
|
498
|
+
if (preview !== null && form.type === 'limit' && preview.priceLimit !== undefined) {
|
|
499
|
+
const price = Number(form.limitPrice)
|
|
500
|
+
if (price < preview.priceLimit.lower || price > preview.priceLimit.upper) return '价格超出涨跌停'
|
|
501
|
+
}
|
|
502
|
+
if (form.side === 'buy' && preview !== null && preview.cashAfterCents < 0) {
|
|
503
|
+
return `资金不足(还差 ${cents(-preview.cashAfterCents)})`
|
|
504
|
+
}
|
|
505
|
+
if (form.side === 'sell' && preview !== null && qty > preview.availableQty) return '可卖不足'
|
|
506
|
+
return ''
|
|
507
|
+
}, [blocked, form, session, quote, preview])
|
|
508
|
+
const pending = useMemo(() => orders.filter(order => order.status === 'pending' || order.status === 'queued' || order.status === 'partially_filled'), [orders])
|
|
509
|
+
const history = useMemo(() => orders.filter(order => order.status !== 'pending' && order.status !== 'queued' && order.status !== 'partially_filled'), [orders])
|
|
510
|
+
const positions = account?.positions ?? []
|
|
511
|
+
|
|
512
|
+
/** Selling from a book only fills the ticket; the user still confirms. */
|
|
513
|
+
const sellPosition = useCallback(position => {
|
|
514
|
+
formSymbol.current = position.symbol
|
|
515
|
+
setForm(prev => ({ ...prev, symbol: position.symbol, side: 'sell', type: 'market', qty: String(Math.min(position.available, position.qty)) }))
|
|
516
|
+
setTab('trade')
|
|
517
|
+
}, [])
|
|
518
|
+
|
|
519
|
+
if (account === null) {
|
|
520
|
+
return h('div', { className: 'pt-inner' },
|
|
521
|
+
h('div', { className: 'pt-head' },
|
|
522
|
+
h('div', null, h('h3', { className: 'pt-title' }, '模拟交易')),
|
|
523
|
+
h('div', { className: 'pt-row' }, accountSwitch,
|
|
524
|
+
h('button', { className: 'pt-btn', onClick: () => { setError(null); void loadAll() } }, '重试'),
|
|
525
|
+
),
|
|
526
|
+
),
|
|
527
|
+
error
|
|
528
|
+
? h('div', { className: 'pt-error', title: error.detail || undefined }, error.text)
|
|
529
|
+
: h('div', { className: 'pt-empty' }, '加载模拟交易…'),
|
|
530
|
+
)
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
return h('div', { className: 'pt-inner' },
|
|
534
|
+
h('div', { className: 'pt-head' },
|
|
535
|
+
h('div', null,
|
|
536
|
+
h('h3', { className: 'pt-title' }, '模拟交易'),
|
|
537
|
+
h('div', { className: 'pt-sub' },
|
|
538
|
+
`${tradeDateText(account.tradeDate, session?.calendar?.source === 'fallback')} · ${session ? PHASE_TEXT[session.phase] : '时段未知'} · 初始 ${money(account.initialCash)}${isFiniteNumber(account.netCashFlow) && account.netCashFlow !== 0 ? ` · 净入金 ${signed(account.netCashFlow)}` : ''} · ${account.blocked ? '已锁定' : '运行中'}`,
|
|
539
|
+
sessionNote(session) !== '' ? h('span', { className: 'pt-note' }, sessionNote(session)) : null,
|
|
540
|
+
session !== null && session !== undefined ? calendarNote(session.calendar) : null,
|
|
541
|
+
),
|
|
542
|
+
),
|
|
543
|
+
h('div', { className: 'pt-row' },
|
|
544
|
+
accountSwitch,
|
|
545
|
+
h(AccountPicker, {
|
|
546
|
+
accounts: stockAccounts,
|
|
547
|
+
archived,
|
|
548
|
+
current: currentAccount,
|
|
549
|
+
onRestoreArchived: restoreArchived,
|
|
550
|
+
busy,
|
|
551
|
+
onSelect: id => setCurrentAccountId(id),
|
|
552
|
+
onCreate: () => setAccountEditor('create'),
|
|
553
|
+
onAction: runAccountAction,
|
|
554
|
+
}),
|
|
555
|
+
h(DataSourceBadge, { status: dataSource }),
|
|
556
|
+
h('button', { className: 'pt-btn', onClick: refreshAll, disabled: busy }, '刷新'),
|
|
557
|
+
h('button', {
|
|
558
|
+
className: 'pt-btn', 'data-active': cashOpen, disabled: busy,
|
|
559
|
+
onClick: () => {
|
|
560
|
+
setError(null)
|
|
561
|
+
setCashOpen(value => !value)
|
|
562
|
+
setResetOpen(false)
|
|
563
|
+
},
|
|
564
|
+
}, '资金'),
|
|
565
|
+
h('button', {
|
|
566
|
+
className: 'pt-btn pt-btn-danger', 'data-active': resetOpen, disabled: busy,
|
|
567
|
+
onClick: () => {
|
|
568
|
+
setError(null)
|
|
569
|
+
setResetOpen(value => !value)
|
|
570
|
+
setResetCash(String(account.initialCash))
|
|
571
|
+
setCashOpen(false)
|
|
572
|
+
},
|
|
573
|
+
}, '重置'),
|
|
574
|
+
h(FeedbackLink),
|
|
575
|
+
),
|
|
576
|
+
),
|
|
577
|
+
h(DataBanner, { status: dataSource, onRetry: refreshAll }),
|
|
578
|
+
cashOpen ? h(CashMovePanel, {
|
|
579
|
+
available: account.cash,
|
|
580
|
+
side: cashSide,
|
|
581
|
+
onSide: setCashSide,
|
|
582
|
+
amount: cashAmount,
|
|
583
|
+
onAmount: setCashAmount,
|
|
584
|
+
busy,
|
|
585
|
+
onCancel: () => {
|
|
586
|
+
setCashOpen(false)
|
|
587
|
+
setCashAmount('')
|
|
588
|
+
},
|
|
589
|
+
onSubmit: moveCash,
|
|
590
|
+
}) : null,
|
|
591
|
+
resetOpen ? h(ResetPanel, {
|
|
592
|
+
initialCash: account.initialCash,
|
|
593
|
+
amount: resetCash,
|
|
594
|
+
onAmount: setResetCash,
|
|
595
|
+
busy,
|
|
596
|
+
onCancel: () => {
|
|
597
|
+
setResetOpen(false)
|
|
598
|
+
setResetCash('')
|
|
599
|
+
},
|
|
600
|
+
onSubmit: reset,
|
|
601
|
+
}) : null,
|
|
602
|
+
accountEditor === null ? null : h(AccountEditor, {
|
|
603
|
+
key: `${accountEditor}:${currentAccountId ?? ''}`,
|
|
604
|
+
mode: accountEditor,
|
|
605
|
+
current: currentAccount,
|
|
606
|
+
busy,
|
|
607
|
+
onCancel: () => setAccountEditor(null),
|
|
608
|
+
onSubmit: submitAccountEditor,
|
|
609
|
+
}),
|
|
610
|
+
account.blocked ? h('div', { className: 'pt-blocked' },
|
|
611
|
+
h('div', { className: 'pt-blocked-text' },
|
|
612
|
+
h('div', null, '账本校验失败,账户已冻结。'),
|
|
613
|
+
account.blockedReason ? h('div', { className: 'pt-blocked-detail', title: account.blockedReason }, `原因:${account.blockedReason}`) : null,
|
|
614
|
+
account.ledgerPath ? h('div', { className: 'pt-blocked-detail', title: account.ledgerPath }, `账本:${account.ledgerPath}`) : null,
|
|
615
|
+
h('div', { className: 'pt-blocked-hint' }, '可让 AI 助手用 paper_ledger 从备份恢复;重置会先备份。'),
|
|
616
|
+
),
|
|
617
|
+
h('div', { className: 'pt-row' },
|
|
618
|
+
h('button', { className: 'pt-btn', onClick: exportLedger, disabled: busy }, '导出账本'),
|
|
619
|
+
account.ledgerPath ? h('button', { className: 'pt-btn', onClick: copyLedgerPath, disabled: busy }, '复制路径') : null,
|
|
620
|
+
),
|
|
621
|
+
) : null,
|
|
622
|
+
h('div', { className: 'pt-stats' },
|
|
623
|
+
h('div', { className: 'pt-stat' }, h('div', { className: 'pt-stat-label' }, '总资产'), h('div', { className: 'pt-stat-value' }, money(account.equity))),
|
|
624
|
+
h('div', { className: 'pt-stat' }, h('div', { className: 'pt-stat-label' }, '可用现金'), h('div', { className: 'pt-stat-value' }, money(account.cash))),
|
|
625
|
+
h('div', { className: 'pt-stat' }, h('div', { className: 'pt-stat-label' }, '累计盈亏'), h('div', { className: `pt-stat-value ${tone(account.pnl)}` }, signed(account.pnl))),
|
|
626
|
+
h('div', { className: 'pt-stat' }, h('div', { className: 'pt-stat-label' }, '今日盈亏'), h('div', { className: `pt-stat-value ${tone(account.todayPnl)}` }, signed(account.todayPnl))),
|
|
627
|
+
),
|
|
628
|
+
error ? h('div', { className: 'pt-error', title: error.detail || undefined }, error.text) : null,
|
|
629
|
+
notice ? h('div', { className: 'pt-note' }, notice) : null,
|
|
630
|
+
h('div', {
|
|
631
|
+
className: 'pt-workspace',
|
|
632
|
+
'data-rail-width': layout.rail === null ? undefined : String(layout.rail),
|
|
633
|
+
'data-rail-collapsed': layout.collapsed ? 'true' : undefined,
|
|
634
|
+
'data-kline-height': layout.klineHeight === 'auto' ? undefined : layout.klineHeight,
|
|
635
|
+
style: layout.rail === null ? undefined : { '--pt-rail-width': `${layout.rail}px` },
|
|
636
|
+
},
|
|
637
|
+
h('div', { className: 'pt-main' },
|
|
638
|
+
h('div', { className: 'pt-tabs' },
|
|
639
|
+
[['trade', '交易'], ['basket', '批量'], ['market', '行情'], ['positions', `持仓 ${positions.length}`], ['orders', `订单 ${pending.length}`], ['review', '复盘'], ['compare', '对比'], ['notes', '笔记']].map(([key, label]) =>
|
|
640
|
+
h('button', { key, className: 'pt-tab', 'data-active': tab === key, onClick: () => setTab(key) }, label),
|
|
641
|
+
),
|
|
642
|
+
),
|
|
643
|
+
h('div', { className: 'pt-tab-body' },
|
|
644
|
+
tab === 'trade' ? h(TradeTab, {
|
|
645
|
+
account, form, setForm, quote, quoteError, quoteNotice, preview, previewState, previewError,
|
|
646
|
+
previewHint: previewBlockReason(previewDraft()),
|
|
647
|
+
busy,
|
|
648
|
+
onSubmit: doSubmit,
|
|
649
|
+
submitReason,
|
|
650
|
+
receipt,
|
|
651
|
+
positions, pending,
|
|
652
|
+
onCancel: cancel,
|
|
653
|
+
onSell: sellPosition,
|
|
654
|
+
}) : null,
|
|
655
|
+
tab === 'basket' ? h(BasketTab, { account, onDone: refreshAll, resetNonce }) : null,
|
|
656
|
+
tab === 'market' ? h(MarketTab, {
|
|
657
|
+
searchQuery,
|
|
658
|
+
setSearchQuery: value => { setSearchQuery(value); setSearchAttempted(false) },
|
|
659
|
+
runSearch, searchHits, searchAttempted, shortlist, isShortlisted, toggleShortlist,
|
|
660
|
+
marketList, marketBoard, setMarketBoard, shortlistOnly, setShortlistOnly, loadMarket, busy, adoptQuote, session,
|
|
661
|
+
}) : null,
|
|
662
|
+
tab === 'positions' ? h(PositionsTab, {
|
|
663
|
+
positions,
|
|
664
|
+
onSell: sellPosition,
|
|
665
|
+
}) : null,
|
|
666
|
+
tab === 'orders' ? h(OrdersTab, { pending, history, busy, onCancel: cancel }) : null,
|
|
667
|
+
tab === 'review' ? h(ReviewTab, {
|
|
668
|
+
review, period,
|
|
669
|
+
setPeriod: key => setPeriod(key),
|
|
670
|
+
trades, daily, cashFlow, trips,
|
|
671
|
+
}) : null,
|
|
672
|
+
tab === 'compare' ? h(CompareTab, { data: compareData, error: compareError }) : null,
|
|
673
|
+
tab === 'notes' ? h(NotesTab, {
|
|
674
|
+
text: notes.text,
|
|
675
|
+
status: notes.status,
|
|
676
|
+
updatedAt: notes.meta === null ? undefined : notes.meta.updatedAt,
|
|
677
|
+
error: notes.error,
|
|
678
|
+
onChange: notes.change,
|
|
679
|
+
onSave: () => { void notes.flush() },
|
|
680
|
+
onReload: () => { void notes.reload() },
|
|
681
|
+
maxBytes: notes.meta === null || notes.meta.maxBytes === undefined ? 100000 : notes.meta.maxBytes,
|
|
682
|
+
}) : null,
|
|
683
|
+
),
|
|
684
|
+
),
|
|
685
|
+
h(KlinePane, {
|
|
686
|
+
renderSlot,
|
|
687
|
+
symbol: quote && quote.symbol ? quote.symbol : form.symbol,
|
|
688
|
+
quote,
|
|
689
|
+
bars,
|
|
690
|
+
error: barError,
|
|
691
|
+
interval: barInterval,
|
|
692
|
+
onInterval: setBarInterval,
|
|
693
|
+
onRefresh: () => loadBars(),
|
|
694
|
+
onIdentity: klineIdentity,
|
|
695
|
+
collapsed: layout.collapsed,
|
|
696
|
+
onCollapse: () => applyLayout({ collapsed: true }),
|
|
697
|
+
onExpand: () => applyLayout({ collapsed: false }),
|
|
698
|
+
onRail: value => applyLayout({ rail: value }, false),
|
|
699
|
+
onRailCommit: value => applyLayout({ rail: value }),
|
|
700
|
+
onRailReset: () => applyLayout({ rail: null }),
|
|
701
|
+
height: layout.klineHeight,
|
|
702
|
+
onHeight: value => { if (KLINE_HEIGHTS.includes(value)) applyLayout({ klineHeight: value }) },
|
|
703
|
+
}),
|
|
704
|
+
),
|
|
705
|
+
)
|
|
706
|
+
}
|