@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
package/lib/client.js
CHANGED
|
@@ -7,9 +7,12 @@ window.__ModuleLoader__.load({
|
|
|
7
7
|
const { useCallback, useEffect, useMemo, useRef, useState } = React
|
|
8
8
|
const h = React.createElement
|
|
9
9
|
|
|
10
|
+
/* ---- 10-core.js ---- */
|
|
11
|
+
/* 10 · runtime — endpoint, formatting, vocabularies, storage keys, banner model. */
|
|
12
|
+
|
|
10
13
|
const ROUTE = '/api/ft-paper-trading'
|
|
11
14
|
/** Release number stamped into the Feedback link title at build time. */
|
|
12
|
-
const PAPER_VERSION = '0.
|
|
15
|
+
const PAPER_VERSION = '0.8.0'
|
|
13
16
|
/** Public repository; the panel links out and collects nothing itself. */
|
|
14
17
|
const ISSUE_NEW = 'https://github.com/gigaflw/dsh-fft-paper-trading/issues/new'
|
|
15
18
|
/**
|
|
@@ -278,6 +281,89 @@ window.__ModuleLoader__.load({
|
|
|
278
281
|
return ''
|
|
279
282
|
}
|
|
280
283
|
}
|
|
284
|
+
|
|
285
|
+
/* ------------------------------------------------------ rail layout --
|
|
286
|
+
The rail's size is a user preference, never the layout authority: a drag
|
|
287
|
+
stores a px hint, CSS clamps it against the workspace (the trading column
|
|
288
|
+
keeps room for its ticket before the rail takes space), and the narrow
|
|
289
|
+
container query drops to one column no matter what was stored. The hint
|
|
290
|
+
is written on release only — a drag reports dozens of widths a second,
|
|
291
|
+
and every write is synchronous local storage. */
|
|
292
|
+
|
|
293
|
+
const LAYOUT_KEY = 'ft-paper-trading.layout.v1'
|
|
294
|
+
const RAIL_LIMITS = {
|
|
295
|
+
stock: { min: 320, max: 760 },
|
|
296
|
+
futures: { min: 240, max: 400 },
|
|
297
|
+
}
|
|
298
|
+
// `pad`: how much of the workspace the trading column must keep for its
|
|
299
|
+
// ticket before the rail may grow (560px form+preview + the 10px gap).
|
|
300
|
+
const RAIL_MAIN_RESERVE = 570
|
|
301
|
+
const KLINE_HEIGHTS = ['auto', 'tall', 'full']
|
|
302
|
+
|
|
303
|
+
/** Defaults for both accounts; a missing or malformed entry falls back here. */
|
|
304
|
+
function emptyLayout() {
|
|
305
|
+
return {
|
|
306
|
+
stock: { rail: null, collapsed: false, klineHeight: 'auto' },
|
|
307
|
+
futures: { rail: null, collapsed: false },
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Clamp a rail width into its account's contract range. */
|
|
312
|
+
function clampRail(value, mode) {
|
|
313
|
+
const limits = RAIL_LIMITS[mode] ?? RAIL_LIMITS.stock
|
|
314
|
+
return Math.min(limits.max, Math.max(limits.min, Math.round(value)))
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Read the persisted layout; anything unreadable or malformed is ignored. */
|
|
318
|
+
function readLayout() {
|
|
319
|
+
const layout = emptyLayout()
|
|
320
|
+
try {
|
|
321
|
+
const raw = window.localStorage.getItem(LAYOUT_KEY)
|
|
322
|
+
if (raw === null) return layout
|
|
323
|
+
const saved = JSON.parse(raw)
|
|
324
|
+
for (const mode of ['stock', 'futures']) {
|
|
325
|
+
const slice = saved === null || typeof saved !== 'object' ? undefined : saved[mode]
|
|
326
|
+
if (slice === null || slice === undefined || typeof slice !== 'object') continue
|
|
327
|
+
if (typeof slice.rail === 'number' && Number.isFinite(slice.rail)) layout[mode].rail = clampRail(slice.rail, mode)
|
|
328
|
+
layout[mode].collapsed = slice.collapsed === true
|
|
329
|
+
if (mode === 'stock' && KLINE_HEIGHTS.includes(slice.klineHeight)) layout.stock.klineHeight = slice.klineHeight
|
|
330
|
+
}
|
|
331
|
+
} catch {
|
|
332
|
+
// A private window or a truncated write: the panel starts at its defaults.
|
|
333
|
+
}
|
|
334
|
+
return layout
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** Persist one account's preference without clobbering the other's. */
|
|
338
|
+
function writeLayout(mode, patch) {
|
|
339
|
+
try {
|
|
340
|
+
const next = readLayout()
|
|
341
|
+
next[mode] = { ...next[mode], ...patch }
|
|
342
|
+
window.localStorage.setItem(LAYOUT_KEY, JSON.stringify(next))
|
|
343
|
+
} catch {
|
|
344
|
+
// Losing a size preference is acceptable; losing the panel is not.
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** Remember the account the human looked at last; the panel re-selects it. */
|
|
349
|
+
const CURRENT_ACCOUNT_KEY = 'ft-paper-trading.current-account.v1'
|
|
350
|
+
|
|
351
|
+
function readCurrentAccount() {
|
|
352
|
+
try {
|
|
353
|
+
return window.localStorage.getItem(CURRENT_ACCOUNT_KEY) ?? ''
|
|
354
|
+
} catch {
|
|
355
|
+
return ''
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function writeCurrentAccount(id) {
|
|
360
|
+
try {
|
|
361
|
+
window.localStorage.setItem(CURRENT_ACCOUNT_KEY, id)
|
|
362
|
+
} catch {
|
|
363
|
+
// A private window loses the preference, not the panel.
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
281
367
|
/** Both sides are canonical ids (`000001.SZ`), so compare them verbatim. */
|
|
282
368
|
const shortlisted = (shortlist, symbol) => shortlist.some(item => item === symbol)
|
|
283
369
|
|
|
@@ -376,7 +462,9 @@ window.__ModuleLoader__.load({
|
|
|
376
462
|
const directionText = (side, offset) => FUTURES_DIRECTION_TEXT[`${side}_${offset}`] ?? '—'
|
|
377
463
|
const orderTypeText = type => type === 'limit' ? '限价' : '市价'
|
|
378
464
|
const ERROR_TEXT = {
|
|
379
|
-
ACCOUNT_BLOCKED: '
|
|
465
|
+
ACCOUNT_BLOCKED: '账本校验失败,账户已冻结:可让 AI 助手从备份恢复,或重置/导出账本',
|
|
466
|
+
ACCOUNT_LOCKED: '账户已被人工锁定:在账户菜单里解锁后才能下单',
|
|
467
|
+
ACCOUNT_ARCHIVED: '账户已归档:在账户菜单里恢复归档后才能交易',
|
|
380
468
|
INVALID_ARGUMENT: '参数不合法',
|
|
381
469
|
INVALID_SYMBOL: '证券代码不合法',
|
|
382
470
|
INVALID_QTY: '数量不合法',
|
|
@@ -394,6 +482,9 @@ window.__ModuleLoader__.load({
|
|
|
394
482
|
SUSPENDED: '标的停牌',
|
|
395
483
|
UNSUPPORTED_INSTRUMENT: '该标的不支持交易',
|
|
396
484
|
INSUFFICIENT_MARGIN: '保证金不足',
|
|
485
|
+
ACCOUNT_NOT_FOUND: '账户不存在',
|
|
486
|
+
ACCOUNT_LIMIT: '账户数量已达上限',
|
|
487
|
+
LEDGER_RESTORE_FAILED: '账本恢复失败',
|
|
397
488
|
CONTRACT_NOT_FOUND: '合约不存在',
|
|
398
489
|
CONTRACT_EXPIRED: '合约临近交割或已到期',
|
|
399
490
|
NO_VOLUME: '当日无成交',
|
|
@@ -420,11 +511,22 @@ window.__ModuleLoader__.load({
|
|
|
420
511
|
detail: cause && cause.detail ? cause.detail : '',
|
|
421
512
|
})
|
|
422
513
|
|
|
423
|
-
|
|
514
|
+
/**
|
|
515
|
+
* Send one RPC. `account` names the stock ledger for account-scoped
|
|
516
|
+
* endpoints; the caller decides it (the stock dashboard keeps the selection
|
|
517
|
+
* in a ref owned by its mount), so nothing here depends on module state.
|
|
518
|
+
* Futures ledgers and the account registry have no account dimension of
|
|
519
|
+
* their own and never receive the field.
|
|
520
|
+
*/
|
|
521
|
+
async function rpc(endpoint, payload, account) {
|
|
522
|
+
const requestBody = { endpoint, payload: payload ?? {} }
|
|
523
|
+
if (account !== null && account !== undefined && !endpoint.startsWith('futures/') && !endpoint.startsWith('accounts/')) {
|
|
524
|
+
requestBody.account = account
|
|
525
|
+
}
|
|
424
526
|
const response = await fetch(ROUTE, {
|
|
425
527
|
method: 'POST',
|
|
426
528
|
headers: { 'content-type': 'application/json' },
|
|
427
|
-
body: JSON.stringify(
|
|
529
|
+
body: JSON.stringify(requestBody),
|
|
428
530
|
})
|
|
429
531
|
let body = null
|
|
430
532
|
try {
|
|
@@ -442,14 +544,22 @@ window.__ModuleLoader__.load({
|
|
|
442
544
|
return body.value
|
|
443
545
|
}
|
|
444
546
|
|
|
547
|
+
/* ---- 20-styles.js ---- */
|
|
548
|
+
/* 20 · styles — the one CSS block injected into the host shadow root. */
|
|
549
|
+
|
|
445
550
|
const CSS = `
|
|
446
551
|
/* Accent comes from the shared FT brand layer; the local aliases keep the
|
|
447
552
|
fallback in one place, so the panel still matches when fft-settings is
|
|
448
|
-
absent. The
|
|
553
|
+
absent. The accent trio follows the brand palette. The soft tint spells
|
|
554
|
+
both values here instead of reading the brand token: the brand layer is
|
|
555
|
+
resolved from the theme's declared colorScheme, while light-dark()
|
|
556
|
+
follows the color-scheme the panel is actually painted with, so a
|
|
557
|
+
custom theme that declares light but paints dark still gets the dark
|
|
558
|
+
tint under its light label text. */
|
|
449
559
|
.pt-root { --pt-accent:var(--ft-accent-warm,light-dark(#cf5623, #ff8352));
|
|
450
560
|
--pt-accent-hover:var(--ft-accent-warm-hover,light-dark(#b8481b, #ff9a72));
|
|
451
561
|
--pt-accent-ink:var(--ft-accent-warm-ink,light-dark(#ffffff, #1a120e));
|
|
452
|
-
--pt-accent-soft:
|
|
562
|
+
--pt-accent-soft:light-dark(#fbeee8, #2b1d16);
|
|
453
563
|
/* The page surface and its content use the whole centre column; the
|
|
454
564
|
K-line rail takes a fixed share on wide screens instead of a
|
|
455
565
|
centred reader column. */
|
|
@@ -557,19 +667,53 @@ window.__ModuleLoader__.load({
|
|
|
557
667
|
.pt-card-title { font-size:11px; font-weight:500; letter-spacing:.04em;
|
|
558
668
|
color:var(--dsw-alias-label-secondary, #49525f); margin-bottom:8px; }
|
|
559
669
|
/* Main workspace: the K-line rail sets the row height, so the left column
|
|
560
|
-
stretches to the same bottom edge instead of ending mid-air.
|
|
561
|
-
|
|
670
|
+
stretches to the same bottom edge instead of ending mid-air. The rail
|
|
671
|
+
track is a variable so a drag can pin a px width while the container's
|
|
672
|
+
own clamps stay in charge; the divider rides in the 10px gap. */
|
|
673
|
+
.pt-workspace { --pt-rail: clamp(380px, 38%, 760px);
|
|
674
|
+
display:grid; grid-template-columns:minmax(0, 1fr) var(--pt-rail);
|
|
562
675
|
gap:10px; align-items:stretch; min-width:0; }
|
|
676
|
+
/* 100% is the workspace, so the trading column is guaranteed its 570px
|
|
677
|
+
reserve before the stored rail width is honoured. */
|
|
678
|
+
.pt-workspace[data-rail-width] { --pt-rail: clamp(320px, var(--pt-rail-width), min(760px, calc(100% - 570px))); }
|
|
563
679
|
.pt-main { display:flex; flex-direction:column; gap:10px; min-width:0; min-height:0;
|
|
564
680
|
container:paper-main / inline-size; }
|
|
565
681
|
.pt-tab-body { display:flex; flex-direction:column; gap:10px; flex:1 1 auto; min-height:0; }
|
|
566
682
|
.pt-kline-rail { position:sticky; top:calc(12px + var(--dsh-frame-top-clearance, 0px)); align-self:start; min-width:0; }
|
|
683
|
+
/* The divider sits in the grid gap, so it costs no layout width. The rail
|
|
684
|
+
is positioned (sticky), which anchors the absolutely placed handle. */
|
|
685
|
+
.pt-rail-handle { position:absolute; z-index:3; top:0; bottom:0; left:-10px; width:10px;
|
|
686
|
+
cursor:col-resize; touch-action:none; }
|
|
687
|
+
.pt-rail-handle::before { content:""; position:absolute; left:4px; top:0; bottom:0; width:1px;
|
|
688
|
+
background:transparent; transition:background .12s; }
|
|
689
|
+
.pt-rail-handle:hover::before, .pt-rail-handle[data-dragging="true"]::before { background:var(--pt-accent); }
|
|
690
|
+
.pt-rail-handle:focus-visible { outline:2px solid var(--pt-accent); outline-offset:2px; }
|
|
691
|
+
.pt-resizing, .pt-resizing * { cursor:col-resize !important; user-select:none !important; }
|
|
692
|
+
.pt-rail-actions { display:flex; align-items:center; justify-content:flex-end; gap:6px; flex-wrap:wrap; }
|
|
693
|
+
.pt-icon-btn { display:inline-flex; align-items:center; justify-content:center; width:26px; height:26px;
|
|
694
|
+
padding:0; border:0.5px solid var(--dsw-alias-border-l2, rgba(45,49,66,.18));
|
|
695
|
+
border-radius:var(--dsw-radius-xs, 4px); background:var(--dsw-alias-bg-layer-1, #fff);
|
|
696
|
+
color:inherit; cursor:pointer; }
|
|
697
|
+
.pt-icon-btn:hover { border-color:var(--pt-accent); color:var(--pt-accent); }
|
|
698
|
+
/* Collapsed rail: a slim strip in wide layouts, a short bar once the panel
|
|
699
|
+
stacks them; either way the rail stays one click away. */
|
|
700
|
+
.pt-rail-collapsed { display:flex; align-items:flex-start; justify-content:center;
|
|
701
|
+
min-height:32px; padding-top:8px; }
|
|
702
|
+
.pt-rail-expand { display:flex; flex-direction:column; align-items:center; gap:6px; padding:4px 0;
|
|
703
|
+
border:0; background:transparent; color:var(--dsw-alias-label-secondary, #49525f); cursor:pointer; }
|
|
704
|
+
.pt-rail-expand:hover { color:var(--pt-accent); }
|
|
705
|
+
.pt-rail-expand-text { writing-mode:vertical-rl; font-size:11px; letter-spacing:.08em; }
|
|
567
706
|
.pt-kline-card { display:flex; flex-direction:column; min-width:0; }
|
|
568
707
|
.pt-kline-head { display:flex; align-items:flex-start; justify-content:space-between; gap:8px; flex-wrap:wrap; margin-bottom:8px; }
|
|
569
708
|
.pt-kline-title { min-width:0; }
|
|
570
709
|
.pt-kline-body { height:clamp(420px, calc(100vh - 250px), 720px); min-height:0; overflow:hidden;
|
|
571
710
|
border:0.5px solid var(--dsw-alias-border-l4, rgba(45,49,66,.08)); border-radius:var(--dsw-radius-sm, 8px);
|
|
572
711
|
background:var(--dsw-alias-bg-layer-2, #f7f8fa); }
|
|
712
|
+
/* Height presets: the rail body is the only vertical knob that also sizes
|
|
713
|
+
the holdings book (the left column stretches to the rail), so it gets
|
|
714
|
+
two explicit sizes next to the viewport-following default. */
|
|
715
|
+
.pt-workspace[data-kline-height="tall"] .pt-kline-body { height:clamp(520px, calc(100vh - 170px), 820px); }
|
|
716
|
+
.pt-workspace[data-kline-height="full"] .pt-kline-body { height:clamp(420px, calc(100vh - 120px), 1200px); }
|
|
573
717
|
.pt-kline-slot, .pt-kline-body > div { width:100%; height:100%; min-height:0; }
|
|
574
718
|
.pt-kline-body .pt-chart { height:100%; }
|
|
575
719
|
.pt-kline-hint { margin-top:6px; font-size:11px; }
|
|
@@ -626,8 +770,13 @@ window.__ModuleLoader__.load({
|
|
|
626
770
|
border-radius:var(--dsw-radius-sm, 8px); padding:8px; }
|
|
627
771
|
/* Futures: the element rail is narrower than the K-line rail, and the
|
|
628
772
|
risk figure turns amber before the account reaches the liquidation line. */
|
|
629
|
-
.pt-workspace-futures {
|
|
773
|
+
.pt-workspace-futures { --pt-rail: clamp(260px, 30%, 400px); }
|
|
774
|
+
.pt-workspace-futures[data-rail-width] { --pt-rail: clamp(240px, var(--pt-rail-width), min(400px, calc(100% - 570px))); }
|
|
775
|
+
/* A stored width survives a collapse (it comes back on expand), so the
|
|
776
|
+
collapsed track has to win the cascade regardless of the drag rule. */
|
|
777
|
+
.pt-workspace[data-rail-collapsed], .pt-workspace-futures[data-rail-collapsed] { --pt-rail: 32px; }
|
|
630
778
|
.pt-futures-rail { position:sticky; top:calc(12px + var(--dsh-frame-top-clearance, 0px)); align-self:start; min-width:0; }
|
|
779
|
+
.pt-card-head { display:flex; align-items:center; justify-content:space-between; gap:8px; margin-bottom:8px; }
|
|
631
780
|
.pt-risk-high { color:var(--dsw-alias-state-warn-primary, #8a6410); }
|
|
632
781
|
/* Breakpoints follow the panel's own width, not the window's: the centre
|
|
633
782
|
column also yields to the sidebar and the right pane, so a wide screen
|
|
@@ -642,7 +791,14 @@ window.__ModuleLoader__.load({
|
|
|
642
791
|
.pt-workspace, .pt-workspace-futures { grid-template-columns:minmax(0, 1fr); }
|
|
643
792
|
.pt-kline-rail { position:static; order:-1; }
|
|
644
793
|
.pt-futures-rail { position:static; order:-1; }
|
|
794
|
+
/* Stacked rows own the full width, so a width drag has nothing to do. */
|
|
795
|
+
.pt-rail-handle { display:none; }
|
|
796
|
+
.pt-rail-collapsed { align-items:center; padding:6px 10px; }
|
|
797
|
+
.pt-rail-expand { flex-direction:row; width:100%; justify-content:center; }
|
|
798
|
+
.pt-rail-expand-text { writing-mode:horizontal-tb; }
|
|
645
799
|
.pt-kline-body { height:360px; }
|
|
800
|
+
.pt-workspace[data-kline-height="tall"] .pt-kline-body { height:520px; }
|
|
801
|
+
.pt-workspace[data-kline-height="full"] .pt-kline-body { height:clamp(360px, calc(100vh - 160px), 900px); }
|
|
646
802
|
}
|
|
647
803
|
@container paper-panel (max-width: 760px) {
|
|
648
804
|
.pt-stats { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); }
|
|
@@ -656,11 +812,79 @@ window.__ModuleLoader__.load({
|
|
|
656
812
|
.pt-tabs { overflow-x:auto; }
|
|
657
813
|
.pt-tab { flex:0 0 auto; }
|
|
658
814
|
}
|
|
815
|
+
/* ---- multi-account picker ---- */
|
|
816
|
+
.pt-account { position:relative; display:inline-flex; }
|
|
817
|
+
.pt-account-btn { display:inline-flex; align-items:baseline; gap:6px; max-width:280px;
|
|
818
|
+
border:0.5px solid var(--dsw-alias-border-l2, rgba(45,49,66,.18));
|
|
819
|
+
background:var(--dsw-alias-bg-layer-1,#fff); color:inherit;
|
|
820
|
+
border-radius:var(--dsw-radius-xs,4px); padding:5px 9px; cursor:pointer;
|
|
821
|
+
font-size:12px; font-family:inherit; }
|
|
822
|
+
.pt-account-btn:hover:not([disabled]) { border-color:var(--pt-accent); }
|
|
823
|
+
.pt-account-btn[data-active="true"] { border-color:var(--pt-accent); background:var(--pt-accent-soft); }
|
|
824
|
+
.pt-account-name { font-weight:500; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
|
825
|
+
.pt-account-note { color:var(--dsw-alias-label-secondary,#49525f); font-size:11px;
|
|
826
|
+
white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:130px; }
|
|
827
|
+
.pt-account-caret { color:var(--dsw-alias-label-secondary,#49525f); font-size:10px; }
|
|
828
|
+
.pt-account-flag { font-size:10px; color:var(--dsw-alias-state-warn-primary,#8a6410); }
|
|
829
|
+
.pt-account-menu { position:absolute; z-index:40; top:calc(100% + 4px); left:0; min-width:232px;
|
|
830
|
+
padding:5px; border-radius:var(--dsw-radius-sm,8px);
|
|
831
|
+
border:0.5px solid var(--dsw-alias-border-l2, rgba(45,49,66,.18));
|
|
832
|
+
background:var(--dsw-alias-bg-layer-1,#fff);
|
|
833
|
+
box-shadow:0 10px 28px rgba(0,0,0,.14); }
|
|
834
|
+
.pt-account-list { max-height:280px; overflow:auto; }
|
|
835
|
+
.pt-account-item { display:flex; flex-direction:column; align-items:flex-start; gap:1px; width:100%;
|
|
836
|
+
border:0; background:none; color:inherit; font-family:inherit; text-align:left;
|
|
837
|
+
padding:5px 7px; border-radius:var(--dsw-radius-xs,4px); cursor:pointer; font-size:12px; }
|
|
838
|
+
.pt-account-item:hover { background:var(--dsw-alias-interactive-bg-hover,#eef1f5); }
|
|
839
|
+
.pt-account-item[data-active="true"] { background:var(--pt-accent-soft); }
|
|
840
|
+
.pt-account-item-note { font-size:11px; color:var(--dsw-alias-label-secondary,#49525f);
|
|
841
|
+
max-width:210px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
|
842
|
+
.pt-account-sep { height:0.5px; margin:5px 4px; background:var(--dsw-alias-border-l4, rgba(45,49,66,.12)); }
|
|
843
|
+
.pt-account-action { display:block; width:100%; text-align:left; border:0; background:none; color:inherit;
|
|
844
|
+
font-family:inherit; font-size:12px; padding:5px 7px; border-radius:var(--dsw-radius-xs,4px); cursor:pointer; }
|
|
845
|
+
.pt-account-action:hover { background:var(--dsw-alias-interactive-bg-hover,#eef1f5); }
|
|
846
|
+
/* ---- account notes ---- */
|
|
847
|
+
.pt-notes { display:flex; flex-direction:column; gap:8px; min-width:0; }
|
|
848
|
+
.pt-notes-head { display:flex; gap:10px; align-items:baseline; justify-content:space-between; flex-wrap:wrap; }
|
|
849
|
+
.pt-notes-title { font-size:12px; font-weight:500; }
|
|
850
|
+
.pt-notes-meta { font-size:11px; color:var(--dsw-alias-label-secondary,#49525f); }
|
|
851
|
+
.pt-notes-input { width:100%; min-height:440px; resize:vertical; box-sizing:border-box;
|
|
852
|
+
padding:10px 12px; font-family:inherit; font-size:13px; line-height:1.7; color:inherit;
|
|
853
|
+
background:var(--dsw-alias-bg-layer-2,#f7f8fa);
|
|
854
|
+
border:0.5px solid var(--dsw-alias-border-l2, rgba(45,49,66,.18));
|
|
855
|
+
border-radius:var(--dsw-radius-sm,8px); }
|
|
856
|
+
.pt-notes-input:focus { outline:none; border-color:var(--pt-accent); }
|
|
857
|
+
/* ---- comparison page ---- */
|
|
858
|
+
.pt-compare { display:flex; flex-direction:column; gap:10px; min-width:0; }
|
|
859
|
+
.pt-compare-scroll { overflow-x:auto; min-width:0; }
|
|
860
|
+
.pt-compare-legend { display:flex; flex-wrap:wrap; gap:10px; font-size:11px;
|
|
861
|
+
color:var(--dsw-alias-label-secondary,#49525f); }
|
|
862
|
+
.pt-compare-legend i { display:inline-block; width:8px; height:8px; border-radius:2px; margin-right:5px; }
|
|
863
|
+
.pt-compare-table { width:100%; border-collapse:collapse; font-variant-numeric:tabular-nums; }
|
|
864
|
+
.pt-compare-table th { font-size:11px; font-weight:400; color:var(--dsw-alias-label-secondary,#49525f);
|
|
865
|
+
text-align:right; padding:0 8px 6px; white-space:nowrap; }
|
|
866
|
+
.pt-compare-table th:first-child, .pt-compare-table td:first-child { text-align:left; }
|
|
867
|
+
.pt-compare-table td { padding:6px 8px; border-top:0.5px solid var(--dsw-alias-border-l4, rgba(45,49,66,.10));
|
|
868
|
+
text-align:right; white-space:nowrap; font-size:12px; }
|
|
869
|
+
.pt-compare-table tr[data-lead="true"] td { background:var(--pt-accent-soft); }
|
|
870
|
+
.pt-compare-table th.pt-sortable { cursor:pointer; user-select:none; }
|
|
871
|
+
.pt-compare-table th.pt-sortable:hover { color:var(--pt-accent); }
|
|
872
|
+
.pt-compare-table th[data-sorted="true"] { color:var(--pt-accent); }
|
|
873
|
+
.pt-compare .pt-chart { height:200px; }
|
|
874
|
+
@container paper-panel (max-width: 760px) { .pt-compare .pt-chart { height:150px; } }
|
|
875
|
+
.pt-compare-name { display:flex; flex-direction:column; gap:1px; text-align:left; }
|
|
876
|
+
.pt-compare-note { font-size:11px; color:var(--dsw-alias-label-secondary,#49525f); }
|
|
877
|
+
@container paper-panel (max-width: 760px) {
|
|
878
|
+
.pt-compare-table th:nth-child(8), .pt-compare-table td:nth-child(8) { display:none; }
|
|
879
|
+
}
|
|
659
880
|
.pt-root button:focus-visible, .pt-root input:focus-visible,
|
|
660
881
|
.pt-root .pt-seg button:focus-visible, .pt-root .pt-tab:focus-visible {
|
|
661
882
|
outline:2px solid var(--pt-accent); outline-offset:2px; }
|
|
662
883
|
`
|
|
663
884
|
|
|
885
|
+
/* ---- 30-atoms.js ---- */
|
|
886
|
+
/* 30 · atoms — small components, account picker, comparison, charts, K-line rail. */
|
|
887
|
+
|
|
664
888
|
/* ------------------------------------------------------------ atoms --- */
|
|
665
889
|
|
|
666
890
|
function Field({ label, children, span = false }) {
|
|
@@ -853,6 +1077,258 @@ window.__ModuleLoader__.load({
|
|
|
853
1077
|
)
|
|
854
1078
|
}
|
|
855
1079
|
|
|
1080
|
+
/* ------------------------------------------------------ multi-account --
|
|
1081
|
+
Accounts are a flat registry: a display name, a free text note and two
|
|
1082
|
+
flags. Nothing here knows about sessions or models — the panel picks one
|
|
1083
|
+
account for the human, and every request names that account explicitly. */
|
|
1084
|
+
|
|
1085
|
+
/**
|
|
1086
|
+
* Header picker: current account, the visible account list, then actions.
|
|
1087
|
+
* Notes are deliberately absent: they are long-form content, not a label.
|
|
1088
|
+
*/
|
|
1089
|
+
function AccountPicker({ accounts, archived = [], current, busy, onSelect, onCreate, onAction, onRestoreArchived }) {
|
|
1090
|
+
const [open, setOpen] = useState(false)
|
|
1091
|
+
const rootRef = useRef(null)
|
|
1092
|
+
useEffect(() => {
|
|
1093
|
+
if (!open) return undefined
|
|
1094
|
+
const close = event => {
|
|
1095
|
+
if (rootRef.current !== null && !rootRef.current.contains(event.target)) setOpen(false)
|
|
1096
|
+
}
|
|
1097
|
+
document.addEventListener('mousedown', close, true)
|
|
1098
|
+
return () => document.removeEventListener('mousedown', close, true)
|
|
1099
|
+
}, [open])
|
|
1100
|
+
if (current === null) return null
|
|
1101
|
+
return h('div', { className: 'pt-account', ref: rootRef },
|
|
1102
|
+
h('button', {
|
|
1103
|
+
className: 'pt-account-btn', 'data-active': open ? 'true' : undefined,
|
|
1104
|
+
disabled: busy, title: current.name, 'aria-haspopup': 'menu', 'aria-expanded': open ? 'true' : 'false',
|
|
1105
|
+
onClick: () => setOpen(value => !value),
|
|
1106
|
+
},
|
|
1107
|
+
h('span', { className: 'pt-account-name' }, current.name),
|
|
1108
|
+
current.locked ? h('span', { className: 'pt-account-flag' }, '锁定') : null,
|
|
1109
|
+
h('span', { className: 'pt-account-caret' }, '▾'),
|
|
1110
|
+
),
|
|
1111
|
+
open ? h('div', { className: 'pt-account-menu', role: 'menu' },
|
|
1112
|
+
accounts.length > 1 ? h('div', { className: 'pt-account-list' }, accounts.map(meta =>
|
|
1113
|
+
h('button', {
|
|
1114
|
+
key: meta.id, role: 'menuitem', className: 'pt-account-item',
|
|
1115
|
+
'data-active': meta.id === current.id ? 'true' : undefined,
|
|
1116
|
+
onClick: () => { setOpen(false); if (meta.id !== current.id) onSelect(meta.id) },
|
|
1117
|
+
},
|
|
1118
|
+
h('span', null, meta.name),
|
|
1119
|
+
meta.locked ? h('span', { className: 'pt-account-flag' }, '锁定') : null,
|
|
1120
|
+
))) : null,
|
|
1121
|
+
accounts.length > 1 ? h('div', { className: 'pt-account-sep' }) : null,
|
|
1122
|
+
archived.length > 0 ? h('div', { className: 'pt-account-sep' }) : null,
|
|
1123
|
+
archived.length > 0 ? h('div', { className: 'pt-account-list' }, archived.map(meta =>
|
|
1124
|
+
h('button', {
|
|
1125
|
+
key: meta.id, role: 'menuitem', className: 'pt-account-item', 'data-archived': 'true', title: '点按恢复归档',
|
|
1126
|
+
style: { opacity: 0.7 },
|
|
1127
|
+
onClick: () => { setOpen(false); onRestoreArchived(meta.id) },
|
|
1128
|
+
},
|
|
1129
|
+
h('span', null, meta.name),
|
|
1130
|
+
h('span', { className: 'pt-account-item-note' }, '已归档 · 点按恢复'),
|
|
1131
|
+
))) : null,
|
|
1132
|
+
archived.length > 0 ? h('div', { className: 'pt-account-sep' }) : null,
|
|
1133
|
+
h('button', { className: 'pt-account-action', role: 'menuitem', onClick: () => { setOpen(false); onCreate() } }, '+ 新建账户'),
|
|
1134
|
+
h('button', { className: 'pt-account-action', role: 'menuitem', onClick: () => { setOpen(false); onAction('rename') } }, '重命名'),
|
|
1135
|
+
h('button', { className: 'pt-account-action', role: 'menuitem', onClick: () => { setOpen(false); onAction('notes') } }, '笔记'),
|
|
1136
|
+
current.id === 'default' ? null : h('button', { className: 'pt-account-action', role: 'menuitem', onClick: () => { setOpen(false); onAction('archive') } }, '归档账户'),
|
|
1137
|
+
h('button', { className: 'pt-account-action', role: 'menuitem', onClick: () => { setOpen(false); onAction('lock') } }, current.locked ? '解锁账户' : '锁定账户'),
|
|
1138
|
+
) : null,
|
|
1139
|
+
)
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
/** Inline create / rename form; the same shape as the cash panel. */
|
|
1143
|
+
function AccountEditor({ mode, current, busy, onCancel, onSubmit }) {
|
|
1144
|
+
const creating = mode === 'create'
|
|
1145
|
+
const [name, setName] = useState(creating || current === null ? '' : current.name)
|
|
1146
|
+
const [cash, setCash] = useState('')
|
|
1147
|
+
const valid = name.trim() !== ''
|
|
1148
|
+
const submit = () => { if (valid) onSubmit({ name, cash }) }
|
|
1149
|
+
return h('div', { className: 'pt-cash' },
|
|
1150
|
+
h('div', { className: 'pt-row' },
|
|
1151
|
+
h(Field, { label: creating ? '账户名' : '新账户名' },
|
|
1152
|
+
h('input', {
|
|
1153
|
+
className: 'pt-input', value: name, placeholder: '例如:价值组',
|
|
1154
|
+
onChange: event => setName(event.target.value),
|
|
1155
|
+
onKeyDown: event => { if (event.key === 'Enter') submit() },
|
|
1156
|
+
})),
|
|
1157
|
+
creating ? h(Field, { label: '初始资金(元,可选)' },
|
|
1158
|
+
h('input', {
|
|
1159
|
+
className: 'pt-input', type: 'number', min: '1', value: cash, placeholder: '默认 100 万',
|
|
1160
|
+
onChange: event => setCash(event.target.value),
|
|
1161
|
+
})) : null,
|
|
1162
|
+
),
|
|
1163
|
+
h('div', { className: 'pt-row' },
|
|
1164
|
+
h('button', { className: 'pt-btn pt-btn-primary', disabled: busy || !valid, onClick: submit }, creating ? '新建' : '保存'),
|
|
1165
|
+
h('button', { className: 'pt-btn', disabled: busy, onClick: onCancel }, '取消'),
|
|
1166
|
+
creating ? h('span', { className: 'pt-note' }, '新建后自动切换过去') : null,
|
|
1167
|
+
),
|
|
1168
|
+
)
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
/** Palette for comparison lines; the first entry matches the panel accent. */
|
|
1172
|
+
const COMPARE_COLORS = ['#cf5623', '#2e6fa8', '#2f6b47', '#8a6d3b', '#6b4fa8', '#8a3b3b', '#2f7f7f', '#a8552e']
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
* Align every account's daily equity on the union of dates, index each
|
|
1176
|
+
* series to 100 at its first day and keep the last known value for days an
|
|
1177
|
+
* account has no snapshot. Different starting cash and start dates then
|
|
1178
|
+
* still compare honestly.
|
|
1179
|
+
*/
|
|
1180
|
+
function comparisonSeries(rows) {
|
|
1181
|
+
const dates = [...new Set(rows.flatMap(row => row.points.map(point => point.date)))].sort()
|
|
1182
|
+
if (dates.length < 2) return null
|
|
1183
|
+
const series = rows.map(row => {
|
|
1184
|
+
const byDate = new Map(row.points.map(point => [point.date, point.equity]))
|
|
1185
|
+
let carried = row.points.length > 0 ? row.points[0].equity : 0
|
|
1186
|
+
const values = dates.map(date => {
|
|
1187
|
+
const value = byDate.get(date)
|
|
1188
|
+
if (value !== undefined && value > 0) carried = value
|
|
1189
|
+
return carried
|
|
1190
|
+
})
|
|
1191
|
+
const base = values[0] > 0 ? values[0] : 1
|
|
1192
|
+
return values.map(value => (value / base) * 100)
|
|
1193
|
+
})
|
|
1194
|
+
const flat = series.flat()
|
|
1195
|
+
return { dates, series, min: Math.min(...flat), max: Math.max(...flat) }
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
function CompareChart({ rows }) {
|
|
1199
|
+
// A ledger that never closed a day has no curve; plotting its zeros would
|
|
1200
|
+
// drag the shared y-axis down and flatten everybody else.
|
|
1201
|
+
const plotted = useMemo(() => rows.filter(row => Array.isArray(row.points) && row.points.length > 0), [rows])
|
|
1202
|
+
const aligned = useMemo(() => comparisonSeries(plotted), [plotted])
|
|
1203
|
+
if (aligned === null) return h('div', { className: 'pt-empty' }, '至少两个交易日后才有对比曲线')
|
|
1204
|
+
const W = 760
|
|
1205
|
+
const H = 200
|
|
1206
|
+
const PAD = 26
|
|
1207
|
+
const { dates, series, min, max } = aligned
|
|
1208
|
+
const span = max - min || 1
|
|
1209
|
+
const x = index => PAD + (index / (dates.length - 1)) * (W - PAD * 2)
|
|
1210
|
+
const y = value => H - PAD - ((value - min) / span) * (H - PAD * 2)
|
|
1211
|
+
return h('div', null,
|
|
1212
|
+
h('div', { className: 'pt-compare-legend' }, plotted.map((row, index) =>
|
|
1213
|
+
h('span', { key: row.id },
|
|
1214
|
+
h('i', { style: { background: COMPARE_COLORS[index % COMPARE_COLORS.length] } }),
|
|
1215
|
+
row.name))),
|
|
1216
|
+
h('svg', { className: 'pt-chart pt-compare-chart', viewBox: `0 0 ${W} ${H}`, role: 'img', 'aria-label': '账户净值对比' },
|
|
1217
|
+
[0, 0.5, 1].map(part => h('line', {
|
|
1218
|
+
key: `grid-${part}`, x1: PAD, x2: W - PAD,
|
|
1219
|
+
y1: PAD + part * (H - PAD * 2), y2: PAD + part * (H - PAD * 2),
|
|
1220
|
+
stroke: 'currentColor', strokeOpacity: 0.12, strokeDasharray: '3 4',
|
|
1221
|
+
})),
|
|
1222
|
+
series.map((values, index) => h('path', {
|
|
1223
|
+
key: `line-${plotted[index].id}`,
|
|
1224
|
+
d: values.map((value, at) => `${at === 0 ? 'M' : 'L'}${x(at).toFixed(1)},${y(value).toFixed(1)}`).join(' '),
|
|
1225
|
+
fill: 'none',
|
|
1226
|
+
stroke: COMPARE_COLORS[index % COMPARE_COLORS.length],
|
|
1227
|
+
strokeWidth: index === 0 ? 1.8 : 1.2,
|
|
1228
|
+
strokeOpacity: index === 0 ? 1 : 0.8,
|
|
1229
|
+
})),
|
|
1230
|
+
h('text', { x: PAD, y: PAD - 8, fontSize: 9, fill: 'currentColor', fillOpacity: 0.55 }, max.toFixed(1)),
|
|
1231
|
+
h('text', { x: PAD, y: H - 8, fontSize: 9, fill: 'currentColor', fillOpacity: 0.55 }, min.toFixed(1)),
|
|
1232
|
+
),
|
|
1233
|
+
h('div', { className: 'pt-note' }, `以各账户首个交易日净值为 100 归一化 · ${dates.length} 个交易日`),
|
|
1234
|
+
)
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* One account's notes: a single long text the human rewrites freely.
|
|
1239
|
+
* No history, no timestamps, and no tool — the model cannot reach it.
|
|
1240
|
+
*/
|
|
1241
|
+
function NotesTab({ text, status, updatedAt, maxBytes = 100000, error, onChange, onSave, onReload }) {
|
|
1242
|
+
const bytes = typeof text === 'string' ? new TextEncoder().encode(text).length : 0
|
|
1243
|
+
const overLimit = bytes > maxBytes
|
|
1244
|
+
const statusText = status === 'saving' ? '保存中…' : status === 'saved' ? '已保存' : status === 'error' ? '保存失败' : '自动保存'
|
|
1245
|
+
return h('div', { className: 'pt-notes' },
|
|
1246
|
+
h('div', { className: 'pt-notes-head' },
|
|
1247
|
+
h('span', { className: 'pt-notes-title' }, '账户笔记'),
|
|
1248
|
+
h('span', { className: 'pt-notes-meta' }, `${(bytes / 1000).toFixed(1)} / ${(maxBytes / 1000).toFixed(0)} KB · ${statusText}${overLimit ? ' · 超出上限' : ''}`),
|
|
1249
|
+
),
|
|
1250
|
+
h('textarea', {
|
|
1251
|
+
className: 'pt-notes-input',
|
|
1252
|
+
value: text,
|
|
1253
|
+
spellCheck: false,
|
|
1254
|
+
placeholder: '这个账户想写什么就写什么:策略思路、调仓理由、复盘…… 停止输入后自动保存。',
|
|
1255
|
+
onChange: event => onChange(event.target.value),
|
|
1256
|
+
}),
|
|
1257
|
+
error === '' ? null : h('div', { className: 'pt-error' }, error),
|
|
1258
|
+
h('div', { className: 'pt-row' },
|
|
1259
|
+
h('button', { className: 'pt-btn', disabled: overLimit, onClick: onSave }, '立即保存'),
|
|
1260
|
+
h('button', { className: 'pt-btn', onClick: onReload }, '重新加载'),
|
|
1261
|
+
h('span', { className: 'pt-notes-meta' }, updatedAt ? `上次保存 ${dateTime(updatedAt)}` : '还没有保存过'),
|
|
1262
|
+
),
|
|
1263
|
+
)
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
/** Comparison page: the chart plus the ranking table the human asked for. */
|
|
1267
|
+
const COMPARE_COLUMNS = [
|
|
1268
|
+
{ key: 'name', label: '账户', sortable: true },
|
|
1269
|
+
{ key: 'initialCash', label: '初始资金', sortable: true },
|
|
1270
|
+
{ key: 'equity', label: '当前权益', sortable: true },
|
|
1271
|
+
{ key: 'pnlPct', label: '累计收益', sortable: true },
|
|
1272
|
+
{ key: 'todayPnl', label: '今日盈亏', sortable: true },
|
|
1273
|
+
{ key: 'maxDrawdownPct', label: '最大回撤', sortable: true },
|
|
1274
|
+
{ key: 'tradeCount', label: '成交', sortable: true },
|
|
1275
|
+
{ key: 'status', label: '状态', sortable: false },
|
|
1276
|
+
]
|
|
1277
|
+
|
|
1278
|
+
function CompareTab({ data, error }) {
|
|
1279
|
+
const rows = data === null || data === undefined ? [] : data.accounts
|
|
1280
|
+
// Default: return descending. Clicking a header flips direction on the
|
|
1281
|
+
// same column and switches columns otherwise, like the review table.
|
|
1282
|
+
const [sort, setSort] = useState({ key: 'pnlPct', dir: -1 })
|
|
1283
|
+
const sorted = useMemo(() => {
|
|
1284
|
+
const value = row => (sort.key === 'name' ? row.name : row[sort.key])
|
|
1285
|
+
return [...rows].sort((left, right) => {
|
|
1286
|
+
const a = value(left)
|
|
1287
|
+
const b = value(right)
|
|
1288
|
+
if (typeof a === 'string' || typeof b === 'string') {
|
|
1289
|
+
return String(a).localeCompare(String(b), 'zh-CN') * sort.dir
|
|
1290
|
+
}
|
|
1291
|
+
return (Number(a) - Number(b)) * sort.dir
|
|
1292
|
+
})
|
|
1293
|
+
}, [rows, sort])
|
|
1294
|
+
if (error !== '') return h('div', { className: 'pt-error' }, error)
|
|
1295
|
+
if (data === null) return h('div', { className: 'pt-empty' }, '加载账户对比…')
|
|
1296
|
+
if (sorted.length < 2) {
|
|
1297
|
+
return h('div', { className: 'pt-empty' }, '至少两个账户才有对比。用顶部账户下拉里的「新建账户」添加一个。')
|
|
1298
|
+
}
|
|
1299
|
+
return h('div', { className: 'pt-compare' },
|
|
1300
|
+
h('div', { className: 'pt-compare-scroll' }, h(CompareChart, { rows: sorted })),
|
|
1301
|
+
h('div', { className: 'pt-compare-scroll' },
|
|
1302
|
+
h('table', { className: 'pt-compare-table' },
|
|
1303
|
+
h('thead', null, h('tr', null,
|
|
1304
|
+
h('th', { key: '#' }, '#'),
|
|
1305
|
+
COMPARE_COLUMNS.map(column => h('th', {
|
|
1306
|
+
key: column.key,
|
|
1307
|
+
className: column.sortable ? 'pt-sortable' : undefined,
|
|
1308
|
+
'data-sorted': sort.key === column.key ? 'true' : undefined,
|
|
1309
|
+
onClick: column.sortable
|
|
1310
|
+
? () => setSort(previous => previous.key === column.key
|
|
1311
|
+
? { key: column.key, dir: previous.dir === 1 ? -1 : 1 }
|
|
1312
|
+
: { key: column.key, dir: column.key === 'name' ? 1 : -1 })
|
|
1313
|
+
: undefined,
|
|
1314
|
+
}, sort.key === column.key ? `${column.label} ${sort.dir === 1 ? '↑' : '↓'}` : column.label)))),
|
|
1315
|
+
h('tbody', null, sorted.map((row, index) => h('tr', {
|
|
1316
|
+
key: row.id, 'data-lead': index === 0 ? 'true' : undefined,
|
|
1317
|
+
},
|
|
1318
|
+
h('td', null, String(index + 1)),
|
|
1319
|
+
h('td', null, h('div', { className: 'pt-compare-name' }, h('span', null, row.name))),
|
|
1320
|
+
h('td', null, money(row.initialCash)),
|
|
1321
|
+
h('td', null, money(row.equity)),
|
|
1322
|
+
h('td', { className: tone(row.pnlPct) }, pct(row.pnlPct)),
|
|
1323
|
+
h('td', { className: tone(row.todayPnl) }, signed(row.todayPnl)),
|
|
1324
|
+
h('td', { className: 'pt-down' }, row.maxDrawdownPct > 0 ? `-${(row.maxDrawdownPct * 100).toFixed(1)}%` : '—'),
|
|
1325
|
+
h('td', null, count(row.tradeCount)),
|
|
1326
|
+
h('td', null, row.missing ? '账本缺失' : row.locked ? '锁定' : '正常'),
|
|
1327
|
+
))),
|
|
1328
|
+
)),
|
|
1329
|
+
)
|
|
1330
|
+
}
|
|
1331
|
+
|
|
856
1332
|
function EquityChart({ points }) {
|
|
857
1333
|
// One snapshot cannot be a curve: show the value and say why it is flat.
|
|
858
1334
|
if (points.length < 2) {
|
|
@@ -904,100 +1380,730 @@ window.__ModuleLoader__.load({
|
|
|
904
1380
|
)
|
|
905
1381
|
}
|
|
906
1382
|
|
|
907
|
-
/* --------------------------------------------------------- K-line ----- */
|
|
1383
|
+
/* --------------------------------------------------------- K-line ----- */
|
|
1384
|
+
|
|
1385
|
+
/** Elements that prove a slot actually draws something (icons and loading
|
|
1386
|
+
text do not count). */
|
|
1387
|
+
const PAINTED = 'canvas, iframe, svg, table, video'
|
|
1388
|
+
|
|
1389
|
+
/**
|
|
1390
|
+
* Whether a subtree has real rendered content. Open shadow roots belong to
|
|
1391
|
+
* that subtree: dsh_kline mounts its whole chart inside
|
|
1392
|
+
* `host.attachShadow()`, so a light-DOM query alone reports a perfectly
|
|
1393
|
+
* healthy slot as empty.
|
|
1394
|
+
*/
|
|
1395
|
+
function paintsSomething(root) {
|
|
1396
|
+
if (root === null || root === undefined || typeof root.querySelector !== 'function') return false
|
|
1397
|
+
if (root.querySelector(PAINTED) !== null) return true
|
|
1398
|
+
const own = root.shadowRoot
|
|
1399
|
+
if (own !== null && own !== undefined && paintsSomething(own)) return true
|
|
1400
|
+
for (const node of root.querySelectorAll('*')) {
|
|
1401
|
+
const shadow = node.shadowRoot
|
|
1402
|
+
if (shadow !== null && shadow !== undefined && paintsSomething(shadow)) return true
|
|
1403
|
+
}
|
|
1404
|
+
return false
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
/** Grace period for a registered slot to paint before the fallback takes
|
|
1408
|
+
over. Wall clock, so background timer throttling cannot stretch it. */
|
|
1409
|
+
const SLOT_PAINT_TIMEOUT = 6000
|
|
1410
|
+
|
|
1411
|
+
/** Small chevron shared by the rail's collapse and expand controls. */
|
|
1412
|
+
function ChevronIcon({ direction }) {
|
|
1413
|
+
return h('svg', {
|
|
1414
|
+
width: 14, height: 14, viewBox: '0 0 16 16', 'aria-hidden': 'true',
|
|
1415
|
+
fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
1416
|
+
}, h('path', { d: direction === 'left' ? 'M10 3 5 8l5 5' : 'M6 3l5 5-5 5' }))
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
/** Collapse a rail to its slim strip (the strip carries the expand control). */
|
|
1420
|
+
function RailToggle({ label, onClick }) {
|
|
1421
|
+
return h('button', {
|
|
1422
|
+
type: 'button', className: 'pt-icon-btn',
|
|
1423
|
+
title: `收起${label}`, 'aria-label': `收起${label}`, 'aria-expanded': 'true',
|
|
1424
|
+
onClick,
|
|
1425
|
+
}, h(ChevronIcon, { direction: 'right' }))
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* The collapsed rail: a slim vertical strip, or a short full-width bar once
|
|
1430
|
+
* the panel stacks its columns. It keeps the rail one click away instead of
|
|
1431
|
+
* leaving an unreachable chart behind a hidden toggle.
|
|
1432
|
+
*/
|
|
1433
|
+
function CollapsedRail({ label, className, onExpand }) {
|
|
1434
|
+
return h('aside', { className: `pt-rail-collapsed ${className}`, 'aria-label': label },
|
|
1435
|
+
h('button', {
|
|
1436
|
+
type: 'button', className: 'pt-rail-expand',
|
|
1437
|
+
title: `展开${label}`, 'aria-label': `展开${label}`, 'aria-expanded': 'false',
|
|
1438
|
+
onClick: onExpand,
|
|
1439
|
+
},
|
|
1440
|
+
h(ChevronIcon, { direction: 'left' }),
|
|
1441
|
+
h('span', { className: 'pt-rail-expand-text' }, label),
|
|
1442
|
+
),
|
|
1443
|
+
)
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* K-line height presets. The rail body also sets how tall the holdings book
|
|
1448
|
+
* gets (the trading column stretches to it), so it is an explicit choice
|
|
1449
|
+
* instead of a second drag dimension.
|
|
1450
|
+
*/
|
|
1451
|
+
function HeightPreset({ value, onChange }) {
|
|
1452
|
+
return h('div', { className: 'pt-seg', role: 'group', 'aria-label': 'K 线高度' },
|
|
1453
|
+
[['auto', '自动'], ['tall', '高'], ['full', '满']].map(([key, text]) =>
|
|
1454
|
+
h('button', {
|
|
1455
|
+
key, type: 'button', 'data-active': value === key, 'aria-pressed': value === key,
|
|
1456
|
+
onClick: () => onChange(key),
|
|
1457
|
+
}, text),
|
|
1458
|
+
),
|
|
1459
|
+
)
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
/**
|
|
1463
|
+
* Divider between the trading column and a rail. The rail is the grid's
|
|
1464
|
+
* right-hand track, so leftward pointer movement widens it; the px hint is
|
|
1465
|
+
* previewed per animation frame and only committed on release. CSS owns the
|
|
1466
|
+
* real clamps — this component never decides the final track width.
|
|
1467
|
+
* Keyboard follows the host's separators: arrows move 16px, Home/End jump
|
|
1468
|
+
* to the limits, Escape and double-click restore the default width.
|
|
1469
|
+
*/
|
|
1470
|
+
function RailSplitHandle({ mode, label, onPreview, onCommit, onReset }) {
|
|
1471
|
+
const ref = useRef(null)
|
|
1472
|
+
const drag = useRef(null)
|
|
1473
|
+
const frame = useRef(0)
|
|
1474
|
+
const [dragging, setDragging] = useState(false)
|
|
1475
|
+
const limits = RAIL_LIMITS[mode] ?? RAIL_LIMITS.stock
|
|
1476
|
+
|
|
1477
|
+
/** Current rail width in px; the DOM is the source because CSS clamps it. */
|
|
1478
|
+
const railWidth = () => {
|
|
1479
|
+
const rail = ref.current === null ? null : ref.current.closest('aside')
|
|
1480
|
+
return rail === null ? 0 : Math.round(rail.getBoundingClientRect().width)
|
|
1481
|
+
}
|
|
1482
|
+
/** Keep the trading column its reserve; CSS repeats this clamp for safety. */
|
|
1483
|
+
const clampToWorkspace = value => {
|
|
1484
|
+
const workspace = ref.current === null ? null : ref.current.closest('.pt-workspace')
|
|
1485
|
+
const available = (workspace?.clientWidth ?? 0) - RAIL_MAIN_RESERVE
|
|
1486
|
+
const max = Math.min(limits.max, Math.max(limits.min, available))
|
|
1487
|
+
return Math.min(max, Math.max(limits.min, Math.round(value)))
|
|
1488
|
+
}
|
|
1489
|
+
/** End a gesture: a moved width is committed, a plain click is not. */
|
|
1490
|
+
const stop = commit => {
|
|
1491
|
+
const active = drag.current
|
|
1492
|
+
if (active === null) return
|
|
1493
|
+
drag.current = null
|
|
1494
|
+
if (frame.current !== 0) { window.cancelAnimationFrame(frame.current); frame.current = 0 }
|
|
1495
|
+
if (active.handle.hasPointerCapture(active.pointerId)) active.handle.releasePointerCapture(active.pointerId)
|
|
1496
|
+
ref.current?.closest('.pt-root')?.classList.remove('pt-resizing')
|
|
1497
|
+
setDragging(false)
|
|
1498
|
+
if (commit && active.moved) onCommit(clampToWorkspace(active.latest))
|
|
1499
|
+
}
|
|
1500
|
+
useEffect(() => () => {
|
|
1501
|
+
if (frame.current !== 0) window.cancelAnimationFrame(frame.current)
|
|
1502
|
+
ref.current?.closest('.pt-root')?.classList.remove('pt-resizing')
|
|
1503
|
+
}, [])
|
|
1504
|
+
const preview = width => {
|
|
1505
|
+
if (drag.current === null) return
|
|
1506
|
+
drag.current.latest = width
|
|
1507
|
+
frame.current = window.requestAnimationFrame(() => {
|
|
1508
|
+
frame.current = 0
|
|
1509
|
+
if (drag.current !== null) onPreview(drag.current.latest)
|
|
1510
|
+
})
|
|
1511
|
+
}
|
|
1512
|
+
const keyStep = step => {
|
|
1513
|
+
const next = clampToWorkspace(step(railWidth()))
|
|
1514
|
+
onPreview(next)
|
|
1515
|
+
onCommit(next)
|
|
1516
|
+
}
|
|
1517
|
+
return h('div', {
|
|
1518
|
+
ref,
|
|
1519
|
+
className: 'pt-rail-handle',
|
|
1520
|
+
role: 'separator',
|
|
1521
|
+
'aria-orientation': 'vertical',
|
|
1522
|
+
'aria-label': label,
|
|
1523
|
+
'data-dragging': dragging ? 'true' : undefined,
|
|
1524
|
+
tabIndex: 0,
|
|
1525
|
+
title: '拖动调整宽度,双击恢复默认',
|
|
1526
|
+
onPointerDown: event => {
|
|
1527
|
+
if (event.button !== 0 || drag.current !== null) return
|
|
1528
|
+
event.preventDefault()
|
|
1529
|
+
event.currentTarget.setPointerCapture(event.pointerId)
|
|
1530
|
+
drag.current = {
|
|
1531
|
+
handle: event.currentTarget,
|
|
1532
|
+
pointerId: event.pointerId,
|
|
1533
|
+
startX: event.clientX,
|
|
1534
|
+
startWidth: railWidth(),
|
|
1535
|
+
latest: railWidth(),
|
|
1536
|
+
moved: false,
|
|
1537
|
+
}
|
|
1538
|
+
ref.current?.closest('.pt-root')?.classList.add('pt-resizing')
|
|
1539
|
+
setDragging(true)
|
|
1540
|
+
},
|
|
1541
|
+
onPointerMove: event => {
|
|
1542
|
+
const active = drag.current
|
|
1543
|
+
if (active === null || active.pointerId !== event.pointerId) return
|
|
1544
|
+
// The rail grows when the divider moves left, hence the inverted delta.
|
|
1545
|
+
const delta = active.startX - event.clientX
|
|
1546
|
+
// A click is not a drag: without this, touching the divider would pin
|
|
1547
|
+
// the responsive percentage width as the current px value.
|
|
1548
|
+
if (!active.moved) {
|
|
1549
|
+
if (Math.abs(delta) < 3) return
|
|
1550
|
+
active.moved = true
|
|
1551
|
+
}
|
|
1552
|
+
preview(clampToWorkspace(active.startWidth + delta))
|
|
1553
|
+
},
|
|
1554
|
+
onPointerUp: event => {
|
|
1555
|
+
if (drag.current?.pointerId !== event.pointerId) return
|
|
1556
|
+
stop(true)
|
|
1557
|
+
},
|
|
1558
|
+
onPointerCancel: event => {
|
|
1559
|
+
if (drag.current?.pointerId === event.pointerId) stop(false)
|
|
1560
|
+
},
|
|
1561
|
+
onLostPointerCapture: () => stop(true),
|
|
1562
|
+
onDoubleClick: onReset,
|
|
1563
|
+
onKeyDown: event => {
|
|
1564
|
+
if (event.key === 'ArrowLeft') keyStep(width => width + 16)
|
|
1565
|
+
else if (event.key === 'ArrowRight') keyStep(width => width - 16)
|
|
1566
|
+
else if (event.key === 'Home') keyStep(() => limits.min)
|
|
1567
|
+
else if (event.key === 'End') keyStep(() => limits.max)
|
|
1568
|
+
else if (event.key === 'Escape') { onReset(); event.preventDefault(); return }
|
|
1569
|
+
else return
|
|
1570
|
+
event.preventDefault()
|
|
1571
|
+
},
|
|
1572
|
+
})
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
/**
|
|
1576
|
+
* Always-visible K-line rail; dsh_kline fills the slot when installed.
|
|
1577
|
+
* The slot owns its own interval switch, so the built-in day/minute
|
|
1578
|
+
* buttons only exist for the fallback SVG (no dead controls).
|
|
1579
|
+
*/
|
|
1580
|
+
function KlinePane({
|
|
1581
|
+
renderSlot, symbol, quote, bars, error, interval, onInterval, onRefresh, onIdentity,
|
|
1582
|
+
collapsed, onCollapse, onExpand, onRail, onRailCommit, onRailReset, height, onHeight,
|
|
1583
|
+
}) {
|
|
1584
|
+
const slot = typeof renderSlot === 'function'
|
|
1585
|
+
? renderSlot('paperTrading.kline', { symbol, onIdentity })
|
|
1586
|
+
: null
|
|
1587
|
+
const hasSlot = slot !== null && slot !== undefined && slot !== false
|
|
1588
|
+
&& !(Array.isArray(slot) && slot.length === 0)
|
|
1589
|
+
// A registered slot can still render an empty host (no data, failed
|
|
1590
|
+
// mount). Poll it briefly; if nothing shows up, fall back to the built-in
|
|
1591
|
+
// chart instead of leaving 35% of the panel blank. The timeout is wall
|
|
1592
|
+
// clock rather than a tick count: a hidden/occluded window throttles
|
|
1593
|
+
// timers to one per second (or per minute), which would otherwise keep
|
|
1594
|
+
// the rail on "加载中…" for minutes while a real chart is already drawn.
|
|
1595
|
+
const [slotFailed, setSlotFailed] = useState(false)
|
|
1596
|
+
const [slotChecking, setSlotChecking] = useState(hasSlot)
|
|
1597
|
+
const [slotNonce, setSlotNonce] = useState(0)
|
|
1598
|
+
const slotRef = useRef(null)
|
|
1599
|
+
useEffect(() => {
|
|
1600
|
+
// A collapsed rail unmounts the slot: polling it then would mark a live
|
|
1601
|
+
// chart as broken and greet the next expand with the fallback.
|
|
1602
|
+
if (!hasSlot || collapsed) return undefined
|
|
1603
|
+
setSlotFailed(false)
|
|
1604
|
+
setSlotChecking(true)
|
|
1605
|
+
const deadline = Date.now() + SLOT_PAINT_TIMEOUT
|
|
1606
|
+
const timer = setInterval(() => {
|
|
1607
|
+
if (paintsSomething(slotRef.current)) { setSlotChecking(false); clearInterval(timer) }
|
|
1608
|
+
else if (Date.now() >= deadline) { setSlotFailed(true); setSlotChecking(false); clearInterval(timer) }
|
|
1609
|
+
}, 300)
|
|
1610
|
+
return () => clearInterval(timer)
|
|
1611
|
+
}, [hasSlot, symbol, slotNonce, collapsed])
|
|
1612
|
+
const showFallback = !hasSlot || slotFailed
|
|
1613
|
+
if (collapsed) return h(CollapsedRail, { label: 'K 线栏', className: 'pt-kline-rail', onExpand })
|
|
1614
|
+
return h('aside', { className: 'pt-kline-rail', 'aria-label': 'K线' },
|
|
1615
|
+
h(RailSplitHandle, {
|
|
1616
|
+
mode: 'stock', label: '调整 K 线栏宽度',
|
|
1617
|
+
onPreview: onRail, onCommit: onRailCommit, onReset: onRailReset,
|
|
1618
|
+
}),
|
|
1619
|
+
h('div', { className: 'pt-card pt-kline-card' },
|
|
1620
|
+
h('div', { className: 'pt-kline-head' },
|
|
1621
|
+
h('div', { className: 'pt-kline-title' },
|
|
1622
|
+
h('div', { className: 'pt-card-title', style: { margin: 0 } }, `${symbol || '—'} K线`),
|
|
1623
|
+
h('div', { className: 'pt-note' }, quote ? `${symbolText(quote)} · ${quote.source === 'daily-bar' ? '收盘' : '现价'} ${money(quote.last)}` : '等待行情'),
|
|
1624
|
+
),
|
|
1625
|
+
h('div', { className: 'pt-rail-actions' },
|
|
1626
|
+
showFallback ? h('div', { className: 'pt-row', style: { flexWrap: 'nowrap', alignItems: 'center' } },
|
|
1627
|
+
h('div', { className: 'pt-seg' },
|
|
1628
|
+
[['day', '日K'], ['minute', '分时']].map(([key, label]) =>
|
|
1629
|
+
h('button', { key, 'data-active': interval === key, onClick: () => onInterval(key) }, label),
|
|
1630
|
+
),
|
|
1631
|
+
),
|
|
1632
|
+
h('button', { className: 'pt-btn', onClick: onRefresh }, '刷新'),
|
|
1633
|
+
) : null,
|
|
1634
|
+
h(HeightPreset, { value: height, onChange: onHeight }),
|
|
1635
|
+
h(RailToggle, { label: 'K 线栏', onClick: onCollapse }),
|
|
1636
|
+
),
|
|
1637
|
+
),
|
|
1638
|
+
h('div', { className: 'pt-kline-body' },
|
|
1639
|
+
showFallback
|
|
1640
|
+
? h(PriceChart, { bars, interval })
|
|
1641
|
+
: h('div', { className: 'pt-kline-slot', ref: slotRef, key: slotNonce }, slot),
|
|
1642
|
+
),
|
|
1643
|
+
showFallback ? h('div', { className: 'pt-note pt-kline-hint' },
|
|
1644
|
+
slotFailed
|
|
1645
|
+
? 'K 线视图未加载,当前为内置简图。'
|
|
1646
|
+
: error !== '' ? error : '安装或升级 dsh_kline 后显示完整 K 线;当前为内置简图。',
|
|
1647
|
+
slotFailed ? h('button', {
|
|
1648
|
+
className: 'pt-btn', style: { marginLeft: 8 },
|
|
1649
|
+
onClick: () => { setSlotFailed(false); setSlotNonce(value => value + 1) },
|
|
1650
|
+
}, '重试 K 线') : null,
|
|
1651
|
+
) : slotChecking ? h('div', { className: 'pt-note pt-kline-hint' }, 'K 线加载中…') : null,
|
|
1652
|
+
),
|
|
1653
|
+
)
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
/* ---- 35-hooks.js ---- */
|
|
1657
|
+
/* 35 · hooks — stateful behaviour shared by the stock and futures dashboards. */
|
|
1658
|
+
/**
|
|
1659
|
+
* Rail width/height preference for one plane.
|
|
1660
|
+
*
|
|
1661
|
+
* A drag previews in memory and only writes local storage on release, so
|
|
1662
|
+
* `applyLayout(patch, false)` stays cheap during a drag.
|
|
1663
|
+
*/
|
|
1664
|
+
function useRailLayout(mode) {
|
|
1665
|
+
const [layout, setLayout] = useState(() => readLayout()[mode])
|
|
1666
|
+
const applyLayout = useCallback((patch, persist = true) => {
|
|
1667
|
+
setLayout(prev => ({ ...prev, ...patch }))
|
|
1668
|
+
if (persist) writeLayout(mode, patch)
|
|
1669
|
+
}, [mode])
|
|
1670
|
+
return [layout, applyLayout]
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
/**
|
|
1674
|
+
* Run `work` every interval while the document is visible.
|
|
1675
|
+
*
|
|
1676
|
+
* The host scheduler is the primary matcher; this is only the visible
|
|
1677
|
+
* panel's extra trigger, and a hidden panel must not poll.
|
|
1678
|
+
*/
|
|
1679
|
+
function useVisiblePolling(work, intervalMs = 5000) {
|
|
1680
|
+
useEffect(() => {
|
|
1681
|
+
const timer = setInterval(() => {
|
|
1682
|
+
if (document.visibilityState === 'visible') void work()
|
|
1683
|
+
}, intervalMs)
|
|
1684
|
+
return () => clearInterval(timer)
|
|
1685
|
+
}, [work, intervalMs])
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
/**
|
|
1689
|
+
* One account's free-form notes: load on account/tab switch, debounce the
|
|
1690
|
+
* edits, flush on the way out. The model has no tool for this text.
|
|
1691
|
+
*
|
|
1692
|
+
* The in-flight save is stamped with its account id: a response that lands
|
|
1693
|
+
* after the panel switched belongs to the old account and must not retarget
|
|
1694
|
+
* later flushes.
|
|
1695
|
+
*/
|
|
1696
|
+
function useAccountNotes(request, accountId, tab) {
|
|
1697
|
+
const [text, setText] = useState('')
|
|
1698
|
+
const [meta, setMeta] = useState(null)
|
|
1699
|
+
const [status, setStatus] = useState('idle')
|
|
1700
|
+
const [error, setError] = useState('')
|
|
1701
|
+
const textRef = useRef('')
|
|
1702
|
+
const timer = useRef(null)
|
|
1703
|
+
const ref = useRef({ accountId: null, saved: '' })
|
|
1704
|
+
const alive = useRef(true)
|
|
1705
|
+
useEffect(() => {
|
|
1706
|
+
alive.current = true
|
|
1707
|
+
return () => { alive.current = false }
|
|
1708
|
+
}, [])
|
|
1709
|
+
|
|
1710
|
+
const save = useCallback(async (value, id) => {
|
|
1711
|
+
if (id === null || id === undefined) return
|
|
1712
|
+
setStatus('saving')
|
|
1713
|
+
try {
|
|
1714
|
+
const view = await request('note/set', { text: value }, id)
|
|
1715
|
+
if (!alive.current || ref.current.accountId !== id) return
|
|
1716
|
+
ref.current = { accountId: id, saved: value }
|
|
1717
|
+
setMeta(view)
|
|
1718
|
+
setStatus('saved')
|
|
1719
|
+
setError('')
|
|
1720
|
+
} catch (cause) {
|
|
1721
|
+
if (!alive.current || ref.current.accountId !== id) return
|
|
1722
|
+
setStatus('error')
|
|
1723
|
+
setError(errorOf(cause).text)
|
|
1724
|
+
}
|
|
1725
|
+
}, [])
|
|
1726
|
+
|
|
1727
|
+
/** Persist a pending edit now; a no-op when nothing changed. */
|
|
1728
|
+
const flush = useCallback(async () => {
|
|
1729
|
+
if (timer.current !== null) {
|
|
1730
|
+
clearTimeout(timer.current)
|
|
1731
|
+
timer.current = null
|
|
1732
|
+
}
|
|
1733
|
+
const { accountId: id, saved } = ref.current
|
|
1734
|
+
if (id === null || textRef.current === saved) return
|
|
1735
|
+
await save(textRef.current, id)
|
|
1736
|
+
}, [save])
|
|
1737
|
+
|
|
1738
|
+
const load = useCallback(async (id, options = {}) => {
|
|
1739
|
+
if (id === null) return
|
|
1740
|
+
// Switching accounts must not drop the previous account's edit, but an
|
|
1741
|
+
// explicit "重新加载" must: discard is what that button promises.
|
|
1742
|
+
if (options.discard !== true) await flush()
|
|
1743
|
+
else if (timer.current !== null) {
|
|
1744
|
+
clearTimeout(timer.current)
|
|
1745
|
+
timer.current = null
|
|
1746
|
+
}
|
|
1747
|
+
ref.current = { accountId: id, saved: '' }
|
|
1748
|
+
// Blank the editor while loading: keeping the previous account's text
|
|
1749
|
+
// would let a keystroke save it into the new account.
|
|
1750
|
+
textRef.current = ''
|
|
1751
|
+
setText('')
|
|
1752
|
+
setStatus('idle')
|
|
1753
|
+
setError('')
|
|
1754
|
+
try {
|
|
1755
|
+
const view = await request('note/get', {}, id)
|
|
1756
|
+
if (!alive.current || ref.current.accountId !== id) return
|
|
1757
|
+
ref.current = { accountId: id, saved: view.text }
|
|
1758
|
+
textRef.current = view.text
|
|
1759
|
+
setText(view.text)
|
|
1760
|
+
setMeta(view)
|
|
1761
|
+
} catch (cause) {
|
|
1762
|
+
if (!alive.current) return
|
|
1763
|
+
setError(errorOf(cause).text)
|
|
1764
|
+
}
|
|
1765
|
+
}, [flush])
|
|
1766
|
+
|
|
1767
|
+
const change = useCallback(value => {
|
|
1768
|
+
setText(value)
|
|
1769
|
+
textRef.current = value
|
|
1770
|
+
setStatus('idle')
|
|
1771
|
+
if (timer.current !== null) clearTimeout(timer.current)
|
|
1772
|
+
const id = ref.current.accountId
|
|
1773
|
+
timer.current = setTimeout(() => {
|
|
1774
|
+
timer.current = null
|
|
1775
|
+
void save(value, id)
|
|
1776
|
+
}, 700)
|
|
1777
|
+
}, [save])
|
|
1778
|
+
|
|
1779
|
+
useEffect(() => {
|
|
1780
|
+
if (accountId !== null) void load(accountId)
|
|
1781
|
+
}, [accountId, load])
|
|
1782
|
+
|
|
1783
|
+
useEffect(() => {
|
|
1784
|
+
if (tab === 'notes') void load(accountId)
|
|
1785
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1786
|
+
}, [tab, accountId, load])
|
|
1787
|
+
|
|
1788
|
+
// Leaving the tab (or the panel) within the debounce window still writes.
|
|
1789
|
+
useEffect(() => () => {
|
|
1790
|
+
if (timer.current !== null) clearTimeout(timer.current)
|
|
1791
|
+
void flush()
|
|
1792
|
+
}, [flush])
|
|
1793
|
+
|
|
1794
|
+
return {
|
|
1795
|
+
text, meta, status, error,
|
|
1796
|
+
change, flush, load,
|
|
1797
|
+
reload: () => load(accountId, { discard: true }),
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
/**
|
|
1802
|
+
* The stock account registry and the selected account.
|
|
1803
|
+
*
|
|
1804
|
+
* One place applies the selection: the dashboard's scope ref stamps
|
|
1805
|
+
* account-scoped requests, so it is set before the reload; per-account view
|
|
1806
|
+
* state is cleared so nothing from the previous ledger (a preview, a
|
|
1807
|
+
* receipt) survives the switch. The futures ledger is filtered out: this
|
|
1808
|
+
* panel only manages stock accounts, and picking futures would fail every
|
|
1809
|
+
* request.
|
|
1810
|
+
*/
|
|
1811
|
+
function useAccountRegistry({ scope, request, tab, loadAll, loadReviewDetail, loadCompare, clearView, setBusy, setError, setNotice, onNotes }) {
|
|
1812
|
+
const [accounts, setAccounts] = useState(null)
|
|
1813
|
+
const [archived, setArchived] = useState([])
|
|
1814
|
+
const [tickMs, setTickMs] = useState(5000)
|
|
1815
|
+
const [currentAccountId, setCurrentAccountId] = useState(null)
|
|
1816
|
+
const [accountEditor, setAccountEditor] = useState(null)
|
|
1817
|
+
const alive = useRef(true)
|
|
1818
|
+
useEffect(() => {
|
|
1819
|
+
alive.current = true
|
|
1820
|
+
return () => { alive.current = false }
|
|
1821
|
+
}, [])
|
|
1822
|
+
|
|
1823
|
+
/** The registry is metadata only: a failure leaves the panel on default. */
|
|
1824
|
+
const loadAccounts = useCallback(async () => {
|
|
1825
|
+
try {
|
|
1826
|
+
// The panel asks for archived entries too: it renders them in the
|
|
1827
|
+
// "已归档" section and needs them out of the selectable list only.
|
|
1828
|
+
const view = await request('accounts/list', { kind: 'stock', includeArchived: true })
|
|
1829
|
+
if (!alive.current) return
|
|
1830
|
+
const visible = view.accounts.filter(item => item.archived !== true)
|
|
1831
|
+
setAccounts(visible)
|
|
1832
|
+
setArchived(view.accounts.filter(item => item.archived === true))
|
|
1833
|
+
if (typeof view.tickMs === 'number' && view.tickMs > 0) setTickMs(view.tickMs)
|
|
1834
|
+
setCurrentAccountId(previous => {
|
|
1835
|
+
if (previous !== null && visible.some(item => item.id === previous)) return previous
|
|
1836
|
+
const remembered = visible.find(item => item.id === readCurrentAccount())
|
|
1837
|
+
return remembered === undefined ? view.defaultIds.stock : remembered.id
|
|
1838
|
+
})
|
|
1839
|
+
} catch {
|
|
1840
|
+
// Keep whatever is selected; the default account still answers.
|
|
1841
|
+
}
|
|
1842
|
+
}, [])
|
|
1843
|
+
|
|
1844
|
+
const stockAccounts = useMemo(() => accounts ?? [], [accounts])
|
|
1845
|
+
const currentAccount = useMemo(
|
|
1846
|
+
() => stockAccounts.find(item => item.id === currentAccountId) ?? null,
|
|
1847
|
+
[stockAccounts, currentAccountId],
|
|
1848
|
+
)
|
|
1849
|
+
|
|
1850
|
+
useEffect(() => {
|
|
1851
|
+
if (currentAccountId === null) return
|
|
1852
|
+
scope.current = currentAccountId
|
|
1853
|
+
writeCurrentAccount(currentAccountId)
|
|
1854
|
+
clearView()
|
|
1855
|
+
void loadAll()
|
|
1856
|
+
if (tab === 'review') void loadReviewDetail()
|
|
1857
|
+
if (tab === 'compare') void loadCompare()
|
|
1858
|
+
// `tab` and `clearView` are read but not dependencies: switching tabs
|
|
1859
|
+
// must not re-query, and the clear callback only touches setters.
|
|
1860
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1861
|
+
}, [currentAccountId, loadAll, loadReviewDetail, loadCompare])
|
|
1862
|
+
|
|
1863
|
+
useEffect(() => {
|
|
1864
|
+
void loadAccounts()
|
|
1865
|
+
return () => { scope.current = null }
|
|
1866
|
+
}, [loadAccounts])
|
|
1867
|
+
|
|
1868
|
+
/** Create/rename go through the registry, then re-read it. */
|
|
1869
|
+
const submitAccountEditor = useCallback(async values => {
|
|
1870
|
+
if (accountEditor === null) return
|
|
1871
|
+
const mode = accountEditor
|
|
1872
|
+
setBusy(true)
|
|
1873
|
+
try {
|
|
1874
|
+
if (mode === 'create') {
|
|
1875
|
+
const created = await request('accounts/create', {
|
|
1876
|
+
name: values.name.trim(),
|
|
1877
|
+
...(values.cash.trim() === '' ? {} : { initialCash: Number(values.cash) }),
|
|
1878
|
+
})
|
|
1879
|
+
await loadAccounts()
|
|
1880
|
+
setNotice(`已创建账户「${created.name}」`)
|
|
1881
|
+
scope.current = created.id
|
|
1882
|
+
setCurrentAccountId(created.id)
|
|
1883
|
+
} else {
|
|
1884
|
+
await request('accounts/rename', { id: currentAccountId, name: values.name.trim() })
|
|
1885
|
+
await loadAccounts()
|
|
1886
|
+
setNotice('账户已改名')
|
|
1887
|
+
}
|
|
1888
|
+
setAccountEditor(null)
|
|
1889
|
+
} catch (cause) {
|
|
1890
|
+
setError(errorOf(cause))
|
|
1891
|
+
} finally {
|
|
1892
|
+
setBusy(false)
|
|
1893
|
+
}
|
|
1894
|
+
}, [accountEditor, currentAccountId, loadAccounts, setBusy, setError, setNotice])
|
|
1895
|
+
|
|
1896
|
+
/** Picker actions: editor modes open a form, archive/lock apply immediately. */
|
|
1897
|
+
const runAccountAction = useCallback(async action => {
|
|
1898
|
+
if (currentAccount === null) return
|
|
1899
|
+
if (action === 'notes') {
|
|
1900
|
+
onNotes()
|
|
1901
|
+
return
|
|
1902
|
+
}
|
|
1903
|
+
if (action === 'create' || action === 'rename') {
|
|
1904
|
+
setAccountEditor(action)
|
|
1905
|
+
return
|
|
1906
|
+
}
|
|
1907
|
+
setBusy(true)
|
|
1908
|
+
try {
|
|
1909
|
+
if (action === 'archive') {
|
|
1910
|
+
await request('accounts/archive', { id: currentAccount.id })
|
|
1911
|
+
setNotice(`已归档「${currentAccount.name}」:数据保留,可随时恢复归档`)
|
|
1912
|
+
// The reload drops it from the selectable list, so the selection
|
|
1913
|
+
// effect moves the panel to another account on its own.
|
|
1914
|
+
} else {
|
|
1915
|
+
await rpc(currentAccount.locked ? 'accounts/unlock' : 'accounts/lock', { id: currentAccount.id })
|
|
1916
|
+
setNotice(currentAccount.locked ? '已解锁账户' : '已锁定账户')
|
|
1917
|
+
}
|
|
1918
|
+
await loadAccounts()
|
|
1919
|
+
} catch (cause) {
|
|
1920
|
+
setError(errorOf(cause))
|
|
1921
|
+
} finally {
|
|
1922
|
+
setBusy(false)
|
|
1923
|
+
}
|
|
1924
|
+
}, [currentAccount, loadAccounts, onNotes, setBusy, setError, setNotice])
|
|
1925
|
+
|
|
1926
|
+
/** Bring one archived account back: unlock-free, selection follows it. */
|
|
1927
|
+
const restoreArchived = useCallback(async id => {
|
|
1928
|
+
setBusy(true)
|
|
1929
|
+
try {
|
|
1930
|
+
const meta = await request('accounts/unarchive', { id })
|
|
1931
|
+
await loadAccounts()
|
|
1932
|
+
setNotice(`已恢复归档「${meta.name}」`)
|
|
1933
|
+
setCurrentAccountId(meta.id)
|
|
1934
|
+
} catch (cause) {
|
|
1935
|
+
setError(errorOf(cause))
|
|
1936
|
+
} finally {
|
|
1937
|
+
setBusy(false)
|
|
1938
|
+
}
|
|
1939
|
+
}, [loadAccounts, setBusy, setError, setNotice])
|
|
1940
|
+
|
|
1941
|
+
return {
|
|
1942
|
+
accounts, archived, tickMs, stockAccounts, currentAccountId, setCurrentAccountId, currentAccount,
|
|
1943
|
+
accountEditor, setAccountEditor, loadAccounts, restoreArchived,
|
|
1944
|
+
submitAccountEditor, runAccountAction,
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
/**
|
|
1949
|
+
* The open ticket's quote and preview.
|
|
1950
|
+
*
|
|
1951
|
+
* One preview per input change, debounced; the response carries the quote,
|
|
1952
|
+
* so a complete draft costs a single request. While the draft is unfinished
|
|
1953
|
+
* the price line asks for the quote alone — a limit order whose limit is
|
|
1954
|
+
* still being typed must show what the stock costs. A nonce forces a
|
|
1955
|
+
* re-preview after a fill or a reset without touching the form.
|
|
1956
|
+
*/
|
|
1957
|
+
function useTicketPreview(request, form) {
|
|
1958
|
+
const [preview, setPreview] = useState(null)
|
|
1959
|
+
const [previewState, setPreviewState] = useState('idle')
|
|
1960
|
+
const [previewError, setPreviewError] = useState('')
|
|
1961
|
+
const [previewNonce, setPreviewNonce] = useState(0)
|
|
1962
|
+
// Quote for an unfinished draft (symbol known, qty/limit still missing).
|
|
1963
|
+
// A complete draft gets its quote from the preview response instead.
|
|
1964
|
+
const [symbolQuote, setSymbolQuote] = useState(null)
|
|
1965
|
+
const [quoteError, setQuoteError] = useState('')
|
|
1966
|
+
const [quoteNotice, setQuoteNotice] = useState('')
|
|
1967
|
+
const previewSymbol = useRef('')
|
|
1968
|
+
const previewSeq = useRef(0)
|
|
1969
|
+
// Symbols whose quote the blocked-preview path already asked for.
|
|
1970
|
+
const quoteSymbol = useRef('')
|
|
1971
|
+
const quoteRef = useRef(null)
|
|
1972
|
+
const lastTicketRefresh = useRef(0)
|
|
1973
|
+
const alive = useRef(true)
|
|
1974
|
+
useEffect(() => {
|
|
1975
|
+
alive.current = true
|
|
1976
|
+
return () => { alive.current = false }
|
|
1977
|
+
}, [])
|
|
1978
|
+
|
|
1979
|
+
const draft = useCallback(() => ({
|
|
1980
|
+
symbol: form.symbol.trim(),
|
|
1981
|
+
side: form.side,
|
|
1982
|
+
type: form.type,
|
|
1983
|
+
qty: Number(form.qty),
|
|
1984
|
+
limitPrice: form.type === 'limit' ? Number(form.limitPrice) : undefined,
|
|
1985
|
+
price: form.type === 'market' && form.price !== '' ? Number(form.price) : undefined,
|
|
1986
|
+
note: form.note.trim() === '' ? undefined : form.note.trim(),
|
|
1987
|
+
}), [form])
|
|
1988
|
+
|
|
1989
|
+
// The note is not part of the preview: only the trading fields are.
|
|
1990
|
+
const previewDraft = useCallback(() => ({
|
|
1991
|
+
symbol: form.symbol.trim(),
|
|
1992
|
+
side: form.side,
|
|
1993
|
+
type: form.type,
|
|
1994
|
+
qty: Number(form.qty),
|
|
1995
|
+
limitPrice: form.type === 'limit' ? Number(form.limitPrice) : undefined,
|
|
1996
|
+
price: form.type === 'market' && form.price !== '' ? Number(form.price) : undefined,
|
|
1997
|
+
}), [form.symbol, form.side, form.type, form.qty, form.limitPrice, form.price])
|
|
1998
|
+
|
|
1999
|
+
useEffect(() => {
|
|
2000
|
+
const current = previewDraft()
|
|
2001
|
+
previewSeq.current += 1
|
|
2002
|
+
const seq = previewSeq.current
|
|
2003
|
+
if (previewBlockReason(current) !== '') {
|
|
2004
|
+
previewSymbol.current = ''
|
|
2005
|
+
setPreview(null)
|
|
2006
|
+
setPreviewState('idle')
|
|
2007
|
+
setPreviewError('')
|
|
2008
|
+
if (current.symbol.length < 6) {
|
|
2009
|
+
quoteSymbol.current = ''
|
|
2010
|
+
setSymbolQuote(null)
|
|
2011
|
+
setQuoteError('')
|
|
2012
|
+
setQuoteNotice('')
|
|
2013
|
+
return
|
|
2014
|
+
}
|
|
2015
|
+
if (quoteSymbol.current === current.symbol) return
|
|
2016
|
+
const timer = setTimeout(() => {
|
|
2017
|
+
request('market/quote', { symbols: [current.symbol] })
|
|
2018
|
+
.then(result => {
|
|
2019
|
+
if (!alive.current || seq !== previewSeq.current) return
|
|
2020
|
+
const found = result.quotes[0] ?? null
|
|
2021
|
+
quoteSymbol.current = found === null ? '' : current.symbol
|
|
2022
|
+
setSymbolQuote(found)
|
|
2023
|
+
setQuoteError(found ? '' : (result.notice ?? '没有查到行情'))
|
|
2024
|
+
setQuoteNotice(found ? (result.notice ?? '') : '')
|
|
2025
|
+
})
|
|
2026
|
+
.catch(cause => {
|
|
2027
|
+
if (!alive.current || seq !== previewSeq.current) return
|
|
2028
|
+
quoteSymbol.current = ''
|
|
2029
|
+
setSymbolQuote(null)
|
|
2030
|
+
setQuoteError(errorOf(cause).text)
|
|
2031
|
+
setQuoteNotice('')
|
|
2032
|
+
})
|
|
2033
|
+
}, 300)
|
|
2034
|
+
return () => clearTimeout(timer)
|
|
2035
|
+
}
|
|
2036
|
+
quoteSymbol.current = current.symbol
|
|
2037
|
+
// A completed draft gets its quote from the preview; any error left
|
|
2038
|
+
// over from the earlier quote-only probe belongs to the old symbol and
|
|
2039
|
+
// must not stay on screen after the ticket has been corrected.
|
|
2040
|
+
setQuoteError('')
|
|
2041
|
+
setQuoteNotice('')
|
|
2042
|
+
if (previewSymbol.current !== current.symbol) {
|
|
2043
|
+
previewSymbol.current = current.symbol
|
|
2044
|
+
setPreview(null)
|
|
2045
|
+
}
|
|
2046
|
+
setPreviewState('loading')
|
|
2047
|
+
const timer = setTimeout(() => {
|
|
2048
|
+
request('order/preview', current)
|
|
2049
|
+
.then(result => {
|
|
2050
|
+
if (!alive.current || seq !== previewSeq.current) return
|
|
2051
|
+
setPreview(result)
|
|
2052
|
+
// Keep the quote for an unfinished draft: switching to 限价 must
|
|
2053
|
+
// not blank the price line while the limit is still being typed.
|
|
2054
|
+
if (result.quote) setSymbolQuote(result.quote)
|
|
2055
|
+
setPreviewError('')
|
|
2056
|
+
setPreviewState('ready')
|
|
2057
|
+
})
|
|
2058
|
+
.catch(cause => {
|
|
2059
|
+
if (!alive.current || seq !== previewSeq.current) return
|
|
2060
|
+
setPreviewError(errorOf(cause).text)
|
|
2061
|
+
setPreviewState('error')
|
|
2062
|
+
})
|
|
2063
|
+
}, 300)
|
|
2064
|
+
return () => clearTimeout(timer)
|
|
2065
|
+
}, [previewDraft, previewNonce])
|
|
2066
|
+
|
|
2067
|
+
const quote = preview ? preview.quote ?? null : symbolQuote
|
|
2068
|
+
quoteRef.current = quote
|
|
2069
|
+
|
|
2070
|
+
/**
|
|
2071
|
+
* Re-price the open ticket on the polling beat. An unfinished draft only
|
|
2072
|
+
* fetches the quote, so clear its dedupe key too; a degraded quote
|
|
2073
|
+
* refreshes slowly, otherwise the 5 s beat is the biggest free-tier cost.
|
|
2074
|
+
*/
|
|
2075
|
+
const maybeRefreshQuote = useCallback(() => {
|
|
2076
|
+
if (Date.now() - lastTicketRefresh.current < ticketRefreshInterval(quoteRef.current)) return
|
|
2077
|
+
lastTicketRefresh.current = Date.now()
|
|
2078
|
+
quoteSymbol.current = ''
|
|
2079
|
+
setPreviewNonce(value => value + 1)
|
|
2080
|
+
}, [])
|
|
908
2081
|
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
2082
|
+
/** Retry the quote even when the symbol did not change. */
|
|
2083
|
+
const forceQuoteRefresh = useCallback(() => {
|
|
2084
|
+
quoteSymbol.current = ''
|
|
2085
|
+
setPreviewNonce(value => value + 1)
|
|
2086
|
+
}, [])
|
|
912
2087
|
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
2088
|
+
/** Drop the preview after a reset or fill; the next edit rebuilds it. */
|
|
2089
|
+
const invalidate = useCallback(() => setPreview(null), [])
|
|
2090
|
+
const bump = useCallback(() => setPreviewNonce(value => value + 1), [])
|
|
2091
|
+
/** Clear everything that belonged to the previous account. */
|
|
2092
|
+
const clear = useCallback(() => {
|
|
2093
|
+
setPreview(null)
|
|
2094
|
+
setSymbolQuote(null)
|
|
2095
|
+
setQuoteError('')
|
|
2096
|
+
setQuoteNotice('')
|
|
2097
|
+
}, [])
|
|
2098
|
+
|
|
2099
|
+
return {
|
|
2100
|
+
preview, previewState, previewError, symbolQuote, quote, quoteError, quoteNotice,
|
|
2101
|
+
previewDraft, draft, maybeRefreshQuote, forceQuoteRefresh, invalidate, bump, clear,
|
|
927
2102
|
}
|
|
928
|
-
return false
|
|
929
2103
|
}
|
|
930
2104
|
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
const SLOT_PAINT_TIMEOUT = 6000
|
|
934
|
-
|
|
935
|
-
/**
|
|
936
|
-
* Always-visible K-line rail; dsh_kline fills the slot when installed.
|
|
937
|
-
* The slot owns its own interval switch, so the built-in day/minute
|
|
938
|
-
* buttons only exist for the fallback SVG (no dead controls).
|
|
939
|
-
*/
|
|
940
|
-
function KlinePane({ renderSlot, symbol, quote, bars, error, interval, onInterval, onRefresh, onIdentity }) {
|
|
941
|
-
const slot = typeof renderSlot === 'function'
|
|
942
|
-
? renderSlot('paperTrading.kline', { symbol, onIdentity })
|
|
943
|
-
: null
|
|
944
|
-
const hasSlot = slot !== null && slot !== undefined && slot !== false
|
|
945
|
-
&& !(Array.isArray(slot) && slot.length === 0)
|
|
946
|
-
// A registered slot can still render an empty host (no data, failed
|
|
947
|
-
// mount). Poll it briefly; if nothing shows up, fall back to the built-in
|
|
948
|
-
// chart instead of leaving 35% of the panel blank. The timeout is wall
|
|
949
|
-
// clock rather than a tick count: a hidden/occluded window throttles
|
|
950
|
-
// timers to one per second (or per minute), which would otherwise keep
|
|
951
|
-
// the rail on "加载中…" for minutes while a real chart is already drawn.
|
|
952
|
-
const [slotFailed, setSlotFailed] = useState(false)
|
|
953
|
-
const [slotChecking, setSlotChecking] = useState(hasSlot)
|
|
954
|
-
const [slotNonce, setSlotNonce] = useState(0)
|
|
955
|
-
const slotRef = useRef(null)
|
|
956
|
-
useEffect(() => {
|
|
957
|
-
if (!hasSlot) return undefined
|
|
958
|
-
setSlotFailed(false)
|
|
959
|
-
setSlotChecking(true)
|
|
960
|
-
const deadline = Date.now() + SLOT_PAINT_TIMEOUT
|
|
961
|
-
const timer = setInterval(() => {
|
|
962
|
-
if (paintsSomething(slotRef.current)) { setSlotChecking(false); clearInterval(timer) }
|
|
963
|
-
else if (Date.now() >= deadline) { setSlotFailed(true); setSlotChecking(false); clearInterval(timer) }
|
|
964
|
-
}, 300)
|
|
965
|
-
return () => clearInterval(timer)
|
|
966
|
-
}, [hasSlot, symbol, slotNonce])
|
|
967
|
-
const showFallback = !hasSlot || slotFailed
|
|
968
|
-
return h('aside', { className: 'pt-kline-rail', 'aria-label': 'K线' },
|
|
969
|
-
h('div', { className: 'pt-card pt-kline-card' },
|
|
970
|
-
h('div', { className: 'pt-kline-head' },
|
|
971
|
-
h('div', { className: 'pt-kline-title' },
|
|
972
|
-
h('div', { className: 'pt-card-title', style: { margin: 0 } }, `${symbol || '—'} K线`),
|
|
973
|
-
h('div', { className: 'pt-note' }, quote ? `${symbolText(quote)} · ${quote.source === 'daily-bar' ? '收盘' : '现价'} ${money(quote.last)}` : '等待行情'),
|
|
974
|
-
),
|
|
975
|
-
showFallback ? h('div', { className: 'pt-row', style: { flexWrap: 'nowrap', alignItems: 'center' } },
|
|
976
|
-
h('div', { className: 'pt-seg' },
|
|
977
|
-
[['day', '日K'], ['minute', '分时']].map(([key, label]) =>
|
|
978
|
-
h('button', { key, 'data-active': interval === key, onClick: () => onInterval(key) }, label),
|
|
979
|
-
),
|
|
980
|
-
),
|
|
981
|
-
h('button', { className: 'pt-btn', onClick: onRefresh }, '刷新'),
|
|
982
|
-
) : null,
|
|
983
|
-
),
|
|
984
|
-
h('div', { className: 'pt-kline-body' },
|
|
985
|
-
showFallback
|
|
986
|
-
? h(PriceChart, { bars, interval })
|
|
987
|
-
: h('div', { className: 'pt-kline-slot', ref: slotRef, key: slotNonce }, slot),
|
|
988
|
-
),
|
|
989
|
-
showFallback ? h('div', { className: 'pt-note pt-kline-hint' },
|
|
990
|
-
slotFailed
|
|
991
|
-
? 'K 线视图未加载,当前为内置简图。'
|
|
992
|
-
: error !== '' ? error : '安装或升级 dsh_kline 后显示完整 K 线;当前为内置简图。',
|
|
993
|
-
slotFailed ? h('button', {
|
|
994
|
-
className: 'pt-btn', style: { marginLeft: 8 },
|
|
995
|
-
onClick: () => { setSlotFailed(false); setSlotNonce(value => value + 1) },
|
|
996
|
-
}, '重试 K 线') : null,
|
|
997
|
-
) : slotChecking ? h('div', { className: 'pt-note pt-kline-hint' }, 'K 线加载中…') : null,
|
|
998
|
-
),
|
|
999
|
-
)
|
|
1000
|
-
}
|
|
2105
|
+
/* ---- 40-stock-tabs.js ---- */
|
|
2106
|
+
/* 40 · stock tabs — ticket, book, market, positions, orders, review, basket. */
|
|
1001
2107
|
|
|
1002
2108
|
/* ----------------------------------------------------------- tabs ----- */
|
|
1003
2109
|
|
|
@@ -1639,6 +2745,9 @@ window.__ModuleLoader__.load({
|
|
|
1639
2745
|
)
|
|
1640
2746
|
}
|
|
1641
2747
|
|
|
2748
|
+
/* ---- 50-futures.js ---- */
|
|
2749
|
+
/* 50 · futures — the futures dashboard and its tabs/rail. */
|
|
2750
|
+
|
|
1642
2751
|
/* -------------------------------------------------------- futures ----- */
|
|
1643
2752
|
|
|
1644
2753
|
/**
|
|
@@ -1675,6 +2784,7 @@ window.__ModuleLoader__.load({
|
|
|
1675
2784
|
const [quote, setQuote] = useState(null)
|
|
1676
2785
|
const [quoteNotice, setQuoteNotice] = useState('')
|
|
1677
2786
|
const [dataSource, setDataSource] = useState(null)
|
|
2787
|
+
const dataSourceRef = useRef(null)
|
|
1678
2788
|
const quoteRef = useRef(null)
|
|
1679
2789
|
const lastTicketRefresh = useRef(0)
|
|
1680
2790
|
const quoteSeq = useRef(0)
|
|
@@ -1687,6 +2797,7 @@ window.__ModuleLoader__.load({
|
|
|
1687
2797
|
const [form, setForm] = useState({
|
|
1688
2798
|
side: 'long', offset: 'open', type: 'market', qty: '1', limitPrice: '', price: '', note: '',
|
|
1689
2799
|
})
|
|
2800
|
+
const [layout, applyLayout] = useRailLayout('futures')
|
|
1690
2801
|
|
|
1691
2802
|
const alive = useRef(true)
|
|
1692
2803
|
useEffect(() => {
|
|
@@ -1694,7 +2805,7 @@ window.__ModuleLoader__.load({
|
|
|
1694
2805
|
return () => { alive.current = false }
|
|
1695
2806
|
}, [])
|
|
1696
2807
|
|
|
1697
|
-
const loadAll = useCallback(async (quiet = false, reviewPeriod =
|
|
2808
|
+
const loadAll = useCallback(async (quiet = false, reviewPeriod = periodRef.current) => {
|
|
1698
2809
|
const seq = ++loadAllSeq.current
|
|
1699
2810
|
const requestedPeriod = reviewPeriod
|
|
1700
2811
|
try {
|
|
@@ -1712,6 +2823,7 @@ window.__ModuleLoader__.load({
|
|
|
1712
2823
|
setPositions(nextPositions)
|
|
1713
2824
|
setOrders(nextOrders)
|
|
1714
2825
|
setDataSource(nextDataSource)
|
|
2826
|
+
dataSourceRef.current = nextDataSource
|
|
1715
2827
|
if (!quiet) setError(null)
|
|
1716
2828
|
}
|
|
1717
2829
|
return { account: nextAccount }
|
|
@@ -1737,12 +2849,26 @@ window.__ModuleLoader__.load({
|
|
|
1737
2849
|
} catch (cause) {
|
|
1738
2850
|
if (alive.current && seq === reviewSeq.current && key === periodRef.current) setError(errorOf(cause))
|
|
1739
2851
|
}
|
|
1740
|
-
}, [
|
|
2852
|
+
}, [])
|
|
1741
2853
|
|
|
1742
2854
|
useEffect(() => {
|
|
1743
2855
|
if (tab === 'review') void loadReview()
|
|
1744
2856
|
}, [tab, loadReview])
|
|
1745
2857
|
|
|
2858
|
+
// A period switch reloads the review bundle (account cards included)
|
|
2859
|
+
// without touching the ticket, which the old loadAll dependency did by
|
|
2860
|
+
// accident. `tab` is read at switch time only.
|
|
2861
|
+
const periodMounted = useRef(false)
|
|
2862
|
+
useEffect(() => {
|
|
2863
|
+
if (!periodMounted.current) {
|
|
2864
|
+
periodMounted.current = true
|
|
2865
|
+
return
|
|
2866
|
+
}
|
|
2867
|
+
void loadAll(false, period)
|
|
2868
|
+
if (tab === 'review') void loadReview(period)
|
|
2869
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2870
|
+
}, [period, loadAll, loadReview])
|
|
2871
|
+
|
|
1746
2872
|
const fetchQuote = useCallback(async symbol => {
|
|
1747
2873
|
const seq = ++quoteSeq.current
|
|
1748
2874
|
try {
|
|
@@ -1774,7 +2900,11 @@ window.__ModuleLoader__.load({
|
|
|
1774
2900
|
// until the next edit. With no quote (free tier or an outage) retry
|
|
1775
2901
|
// slowly instead of every beat.
|
|
1776
2902
|
if (!alive.current || contract === null) return
|
|
1777
|
-
|
|
2903
|
+
// A free-tier quote is yesterday's close and does not move: re-price
|
|
2904
|
+
// at the degraded cadence instead of spending the 5 s beat. The data
|
|
2905
|
+
// source, not the quote object, tells free tier from configured.
|
|
2906
|
+
const refreshInterval = dataSourceRef.current?.state === 'configured' ? 5_000 : 300_000
|
|
2907
|
+
if (Date.now() - lastTicketRefresh.current >= refreshInterval) {
|
|
1778
2908
|
lastTicketRefresh.current = Date.now()
|
|
1779
2909
|
void fetchQuote(contract.symbol)
|
|
1780
2910
|
setPreviewNonce(value => value + 1)
|
|
@@ -1782,14 +2912,9 @@ window.__ModuleLoader__.load({
|
|
|
1782
2912
|
} catch {
|
|
1783
2913
|
// Polling failures stay silent; the manual refresh shows the error.
|
|
1784
2914
|
}
|
|
1785
|
-
}, [loadAll, contract, fetchQuote, tab,
|
|
2915
|
+
}, [loadAll, contract, fetchQuote, tab, loadReview])
|
|
1786
2916
|
|
|
1787
|
-
|
|
1788
|
-
const timer = setInterval(() => {
|
|
1789
|
-
if (document.visibilityState === 'visible') poll()
|
|
1790
|
-
}, 5000)
|
|
1791
|
-
return () => clearInterval(timer)
|
|
1792
|
-
}, [poll])
|
|
2917
|
+
useVisiblePolling(poll)
|
|
1793
2918
|
|
|
1794
2919
|
const searchContracts = useCallback(async (refresh = false) => {
|
|
1795
2920
|
const seq = ++contractSeq.current
|
|
@@ -1909,7 +3034,7 @@ window.__ModuleLoader__.load({
|
|
|
1909
3034
|
|
|
1910
3035
|
const submitReason = useMemo(() => {
|
|
1911
3036
|
if (account === null) return '加载账户中'
|
|
1912
|
-
if (account.blocked === true) return '
|
|
3037
|
+
if (account.blocked === true) return '账本异常,需恢复或重置'
|
|
1913
3038
|
if (contract === null) return '选择合约'
|
|
1914
3039
|
if (String(form.qty).trim() === '') return '填写手数'
|
|
1915
3040
|
const qty = Number(form.qty)
|
|
@@ -2140,7 +3265,7 @@ window.__ModuleLoader__.load({
|
|
|
2140
3265
|
}) : null,
|
|
2141
3266
|
account.blocked ? h('div', { className: 'pt-blocked' },
|
|
2142
3267
|
h('div', { className: 'pt-blocked-text' },
|
|
2143
|
-
h('div', null, '
|
|
3268
|
+
h('div', null, '期货账本校验失败,账户已冻结。'),
|
|
2144
3269
|
account.blockedReason ? h('div', { className: 'pt-blocked-detail', title: account.blockedReason }, `原因:${account.blockedReason}`) : null,
|
|
2145
3270
|
account.ledgerPath ? h('div', { className: 'pt-blocked-detail', title: account.ledgerPath }, `账本:${account.ledgerPath}`) : null,
|
|
2146
3271
|
h('div', { className: 'pt-blocked-hint' }, '可让 AI 助手用 paper_ledger 从备份恢复;重置会先备份。'),
|
|
@@ -2159,13 +3284,24 @@ window.__ModuleLoader__.load({
|
|
|
2159
3284
|
error ? h('div', { className: 'pt-error', title: error.detail || undefined }, error.text) : null,
|
|
2160
3285
|
notice ? h('div', { className: 'pt-note' }, notice) : null,
|
|
2161
3286
|
tab === 'trade'
|
|
2162
|
-
? h('div', {
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
3287
|
+
? h('div', {
|
|
3288
|
+
className: 'pt-workspace pt-workspace-futures',
|
|
3289
|
+
'data-rail-width': layout.rail === null ? undefined : String(layout.rail),
|
|
3290
|
+
'data-rail-collapsed': layout.collapsed ? 'true' : undefined,
|
|
3291
|
+
style: layout.rail === null ? undefined : { '--pt-rail-width': `${layout.rail}px` },
|
|
3292
|
+
},
|
|
3293
|
+
h('div', { className: 'pt-main' }, tabBar, h('div', { className: 'pt-tab-body' }, tabBody)),
|
|
3294
|
+
h(FuturesContractRail, {
|
|
3295
|
+
contract,
|
|
3296
|
+
quote: displayQuote,
|
|
3297
|
+
limit: preview !== null ? preview.limit ?? null : null,
|
|
3298
|
+
collapsed: layout.collapsed,
|
|
3299
|
+
onCollapse: () => applyLayout({ collapsed: true }),
|
|
3300
|
+
onExpand: () => applyLayout({ collapsed: false }),
|
|
3301
|
+
onRail: value => applyLayout({ rail: value }, false),
|
|
3302
|
+
onRailCommit: value => applyLayout({ rail: value }),
|
|
3303
|
+
onRailReset: () => applyLayout({ rail: null }),
|
|
3304
|
+
}),
|
|
2169
3305
|
)
|
|
2170
3306
|
: h('div', { className: 'pt-main' }, tabBar, h('div', { className: 'pt-tab-body' }, tabBody)),
|
|
2171
3307
|
)
|
|
@@ -2483,10 +3619,20 @@ window.__ModuleLoader__.load({
|
|
|
2483
3619
|
}
|
|
2484
3620
|
|
|
2485
3621
|
/** Right rail for the futures ticket: static terms plus the marked quote. */
|
|
2486
|
-
function FuturesContractRail({
|
|
3622
|
+
function FuturesContractRail({
|
|
3623
|
+
contract, quote, limit, collapsed, onCollapse, onExpand, onRail, onRailCommit, onRailReset,
|
|
3624
|
+
}) {
|
|
3625
|
+
if (collapsed) return h(CollapsedRail, { label: '合约要素栏', className: 'pt-futures-rail', onExpand })
|
|
2487
3626
|
return h('aside', { className: 'pt-futures-rail', 'aria-label': '合约要素' },
|
|
3627
|
+
h(RailSplitHandle, {
|
|
3628
|
+
mode: 'futures', label: '调整合约要素栏宽度',
|
|
3629
|
+
onPreview: onRail, onCommit: onRailCommit, onReset: onRailReset,
|
|
3630
|
+
}),
|
|
2488
3631
|
h('div', { className: 'pt-card' },
|
|
2489
|
-
h('div', { className: 'pt-card-
|
|
3632
|
+
h('div', { className: 'pt-card-head' },
|
|
3633
|
+
h('div', { className: 'pt-card-title', style: { margin: 0 } }, '合约要素'),
|
|
3634
|
+
h(RailToggle, { label: '合约要素栏', onClick: onCollapse }),
|
|
3635
|
+
),
|
|
2490
3636
|
contract === null
|
|
2491
3637
|
? h('div', { className: 'pt-empty' }, '搜索并选择合约')
|
|
2492
3638
|
: h('div', { className: 'pt-preview' },
|
|
@@ -2512,6 +3658,9 @@ window.__ModuleLoader__.load({
|
|
|
2512
3658
|
|
|
2513
3659
|
/* ---------------------------------------------------------- dashboard -- */
|
|
2514
3660
|
|
|
3661
|
+
/* ---- 60-shell.js ---- */
|
|
3662
|
+
/* 60 · shell — top-level Dashboard and the stock dashboard (state + effects). */
|
|
3663
|
+
|
|
2515
3664
|
/**
|
|
2516
3665
|
* Top-level shell: the account switch lives above both dashboards, so the
|
|
2517
3666
|
* stock half keeps its exact layout and the futures half mounts on demand.
|
|
@@ -2536,9 +3685,12 @@ window.__ModuleLoader__.load({
|
|
|
2536
3685
|
const periodRef = useRef(period)
|
|
2537
3686
|
useEffect(() => { periodRef.current = period }, [period])
|
|
2538
3687
|
const [tab, setTab] = useState('trade')
|
|
3688
|
+
const [compareData, setCompareData] = useState(null)
|
|
3689
|
+
const [compareError, setCompareError] = useState('')
|
|
2539
3690
|
const [error, setError] = useState(null)
|
|
2540
3691
|
const [notice, setNotice] = useState('')
|
|
2541
3692
|
const [busy, setBusy] = useState(false)
|
|
3693
|
+
const [layout, applyLayout] = useRailLayout('stock')
|
|
2542
3694
|
const [resetNonce, setResetNonce] = useState(0)
|
|
2543
3695
|
// Inline cash panel (注资/提款), hidden until the header button is pressed.
|
|
2544
3696
|
const [cashOpen, setCashOpen] = useState(false)
|
|
@@ -2550,18 +3702,7 @@ window.__ModuleLoader__.load({
|
|
|
2550
3702
|
const [resetCash, setResetCash] = useState('')
|
|
2551
3703
|
const submitting = useRef(false)
|
|
2552
3704
|
const placeKey = useRef({ key: '', id: '' })
|
|
2553
|
-
const [preview, setPreview] = useState(null)
|
|
2554
|
-
const [previewState, setPreviewState] = useState('idle')
|
|
2555
|
-
const [previewError, setPreviewError] = useState('')
|
|
2556
|
-
const [previewNonce, setPreviewNonce] = useState(0)
|
|
2557
|
-
const [quoteError, setQuoteError] = useState('')
|
|
2558
|
-
const [quoteNotice, setQuoteNotice] = useState('')
|
|
2559
3705
|
const [dataSource, setDataSource] = useState(null)
|
|
2560
|
-
const quoteRef = useRef(null)
|
|
2561
|
-
const lastTicketRefresh = useRef(0)
|
|
2562
|
-
// Quote for an unfinished draft (symbol known, qty/limit still missing).
|
|
2563
|
-
// A complete draft gets its quote from the preview response instead.
|
|
2564
|
-
const [symbolQuote, setSymbolQuote] = useState(null)
|
|
2565
3706
|
const [receipt, setReceipt] = useState(null)
|
|
2566
3707
|
const [session, setSession] = useState(null)
|
|
2567
3708
|
const [searchQuery, setSearchQuery] = useState('')
|
|
@@ -2596,6 +3737,17 @@ window.__ModuleLoader__.load({
|
|
|
2596
3737
|
note: '',
|
|
2597
3738
|
})
|
|
2598
3739
|
|
|
3740
|
+
const accountScope = useRef(null)
|
|
3741
|
+
/** This mount's account-scoped request; an explicit account wins (notes). */
|
|
3742
|
+
const request = useCallback((endpoint, payload, account) =>
|
|
3743
|
+
rpc(endpoint, payload, account === undefined ? accountScope.current : account), [])
|
|
3744
|
+
|
|
3745
|
+
const ticket = useTicketPreview(request, form)
|
|
3746
|
+
const {
|
|
3747
|
+
preview, previewState, previewError, symbolQuote, quote, quoteError, quoteNotice,
|
|
3748
|
+
previewDraft, draft, maybeRefreshQuote, forceQuoteRefresh, invalidate: invalidateTicket, bump: bumpTicket,
|
|
3749
|
+
} = ticket
|
|
3750
|
+
|
|
2599
3751
|
const alive = useRef(true)
|
|
2600
3752
|
const loadAllSeq = useRef(0)
|
|
2601
3753
|
const detailSeq = useRef(0)
|
|
@@ -2607,17 +3759,17 @@ window.__ModuleLoader__.load({
|
|
|
2607
3759
|
const formSymbol = useRef(form.symbol)
|
|
2608
3760
|
useEffect(() => { formSymbol.current = form.symbol }, [form.symbol])
|
|
2609
3761
|
|
|
2610
|
-
const loadAll = useCallback(async (quiet = false, reviewPeriod =
|
|
3762
|
+
const loadAll = useCallback(async (quiet = false, reviewPeriod = periodRef.current) => {
|
|
2611
3763
|
const seq = ++loadAllSeq.current
|
|
2612
3764
|
const requestedPeriod = reviewPeriod
|
|
2613
3765
|
try {
|
|
2614
3766
|
const [nextAccount, nextOrders, nextTrades, nextReview, nextSession, nextDataSource] = await Promise.all([
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
3767
|
+
request('account/get'),
|
|
3768
|
+
request('list/orders'),
|
|
3769
|
+
request('list/trades'),
|
|
3770
|
+
request('review/get', { period: reviewPeriod }),
|
|
3771
|
+
request('market/status'),
|
|
3772
|
+
request('market/data-source'),
|
|
2621
3773
|
])
|
|
2622
3774
|
if (!alive.current) return null
|
|
2623
3775
|
// A poll started before a period switch carries the old review;
|
|
@@ -2637,15 +3789,15 @@ window.__ModuleLoader__.load({
|
|
|
2637
3789
|
if (alive.current && seq === loadAllSeq.current) setError(errorOf(cause))
|
|
2638
3790
|
return null
|
|
2639
3791
|
}
|
|
2640
|
-
}, [
|
|
3792
|
+
}, [])
|
|
2641
3793
|
|
|
2642
3794
|
const loadReviewDetail = useCallback(async () => {
|
|
2643
3795
|
const seq = ++detailSeq.current
|
|
2644
3796
|
try {
|
|
2645
3797
|
const [nextDaily, nextCash, nextTrips] = await Promise.all([
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
3798
|
+
request('review/daily'),
|
|
3799
|
+
request('cash/flow'),
|
|
3800
|
+
request('review/roundtrips'),
|
|
2649
3801
|
])
|
|
2650
3802
|
if (!alive.current || seq !== detailSeq.current) return
|
|
2651
3803
|
setDaily(nextDaily)
|
|
@@ -2656,39 +3808,77 @@ window.__ModuleLoader__.load({
|
|
|
2656
3808
|
}
|
|
2657
3809
|
}, [])
|
|
2658
3810
|
|
|
2659
|
-
|
|
3811
|
+
const loadCompare = useCallback(async () => {
|
|
3812
|
+
try {
|
|
3813
|
+
const view = await request('compare/get')
|
|
3814
|
+
if (!alive.current) return
|
|
3815
|
+
setCompareData(view)
|
|
3816
|
+
setCompareError('')
|
|
3817
|
+
} catch (cause) {
|
|
3818
|
+
if (alive.current) setCompareError(errorOf(cause).text)
|
|
3819
|
+
}
|
|
3820
|
+
}, [])
|
|
3821
|
+
|
|
3822
|
+
// A period switch only re-queries the review bundle. It must not re-run
|
|
3823
|
+
// the account-switch effect (which clears the open ticket's preview and
|
|
3824
|
+
// receipt); `tab` is read but not a dependency for the same reason.
|
|
3825
|
+
const periodMounted = useRef(false)
|
|
3826
|
+
useEffect(() => {
|
|
3827
|
+
if (!periodMounted.current) {
|
|
3828
|
+
periodMounted.current = true
|
|
3829
|
+
return
|
|
3830
|
+
}
|
|
3831
|
+
void loadAll(false)
|
|
3832
|
+
if (tab === 'review') void loadReviewDetail()
|
|
3833
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3834
|
+
}, [period, loadAll, loadReviewDetail])
|
|
3835
|
+
|
|
3836
|
+
/** Per-account view state cleared on every account switch. */
|
|
3837
|
+
const clearAccountView = useCallback(() => {
|
|
3838
|
+
setNotice('')
|
|
3839
|
+
setReceipt(null)
|
|
3840
|
+
ticket.clear()
|
|
3841
|
+
}, [ticket.clear])
|
|
3842
|
+
|
|
3843
|
+
const registry = useAccountRegistry({
|
|
3844
|
+
scope: accountScope, request,
|
|
3845
|
+
tab,
|
|
3846
|
+
loadAll,
|
|
3847
|
+
loadReviewDetail,
|
|
3848
|
+
loadCompare,
|
|
3849
|
+
clearView: clearAccountView,
|
|
3850
|
+
setBusy,
|
|
3851
|
+
setError,
|
|
3852
|
+
setNotice,
|
|
3853
|
+
onNotes: () => setTab('notes'),
|
|
3854
|
+
})
|
|
3855
|
+
const {
|
|
3856
|
+
tickMs, stockAccounts, archived, currentAccountId, setCurrentAccountId, currentAccount,
|
|
3857
|
+
restoreArchived, accountEditor, setAccountEditor, submitAccountEditor, runAccountAction,
|
|
3858
|
+
} = registry
|
|
3859
|
+
|
|
3860
|
+
const notes = useAccountNotes(request, currentAccountId, tab)
|
|
2660
3861
|
|
|
2661
3862
|
const tick = useCallback(async () => {
|
|
2662
3863
|
try {
|
|
2663
|
-
const result = await
|
|
3864
|
+
const result = await request('tick')
|
|
2664
3865
|
if (!alive.current) return
|
|
2665
3866
|
if (result.filled.length > 0) setNotice(`成交 ${result.filled.length} 笔`)
|
|
2666
3867
|
if (result.notices.length > 0) setNotice(result.notices.join(';'))
|
|
2667
3868
|
await loadAll(true, periodRef.current)
|
|
2668
3869
|
if (alive.current && tab === 'review') await loadReviewDetail()
|
|
3870
|
+
if (alive.current && tab === 'compare') await loadCompare()
|
|
2669
3871
|
// Re-price the open ticket: the quote strip and preview otherwise
|
|
2670
|
-
// froze at the moment the symbol was entered.
|
|
2671
|
-
|
|
2672
|
-
// quotes refresh slowly, otherwise this 5 s beat is the biggest
|
|
2673
|
-
// free-tier cost of all.
|
|
2674
|
-
if (alive.current && Date.now() - lastTicketRefresh.current >= ticketRefreshInterval(quoteRef.current)) {
|
|
2675
|
-
lastTicketRefresh.current = Date.now()
|
|
2676
|
-
quoteSymbol.current = ''
|
|
2677
|
-
setPreviewNonce(value => value + 1)
|
|
2678
|
-
}
|
|
3872
|
+
// froze at the moment the symbol was entered.
|
|
3873
|
+
if (alive.current) maybeRefreshQuote()
|
|
2679
3874
|
} catch {
|
|
2680
3875
|
// Polling failures stay silent; the manual refresh shows the error.
|
|
2681
3876
|
}
|
|
2682
|
-
}, [loadAll, loadReviewDetail, tab])
|
|
3877
|
+
}, [loadAll, loadReviewDetail, loadCompare, tab, maybeRefreshQuote])
|
|
2683
3878
|
|
|
2684
3879
|
// The host scheduler is the primary matcher; this stays as a live extra
|
|
2685
3880
|
// trigger while the panel is visible.
|
|
2686
|
-
|
|
2687
|
-
const timer = setInterval(() => {
|
|
2688
|
-
if (document.visibilityState === 'visible') tick()
|
|
2689
|
-
}, 5000)
|
|
2690
|
-
return () => clearInterval(timer)
|
|
2691
|
-
}, [tick])
|
|
3881
|
+
useVisiblePolling(tick, tickMs)
|
|
2692
3882
|
|
|
2693
3883
|
const loadBars = useCallback(async (symbol = form.symbol) => {
|
|
2694
3884
|
const seq = ++barsSeq.current
|
|
@@ -2698,7 +3888,7 @@ window.__ModuleLoader__.load({
|
|
|
2698
3888
|
return
|
|
2699
3889
|
}
|
|
2700
3890
|
try {
|
|
2701
|
-
const result = await
|
|
3891
|
+
const result = await request('market/bars', { symbol: symbol.trim(), interval: barInterval, limit: 80 })
|
|
2702
3892
|
if (!alive.current || seq !== barsSeq.current) return
|
|
2703
3893
|
if (result.state === 'ok') {
|
|
2704
3894
|
setBars(result.bars ?? [])
|
|
@@ -2720,7 +3910,7 @@ window.__ModuleLoader__.load({
|
|
|
2720
3910
|
setSearchAttempted(true)
|
|
2721
3911
|
const seq = ++searchSeq.current
|
|
2722
3912
|
try {
|
|
2723
|
-
const hits = await
|
|
3913
|
+
const hits = await request('market/search', { query: searchQuery.trim(), limit: 12 })
|
|
2724
3914
|
if (alive.current && seq === searchSeq.current) setSearchHits(hits)
|
|
2725
3915
|
} catch (cause) {
|
|
2726
3916
|
if (alive.current && seq === searchSeq.current) setError(errorOf(cause))
|
|
@@ -2730,7 +3920,7 @@ window.__ModuleLoader__.load({
|
|
|
2730
3920
|
const loadMarket = useCallback(async (page = 1) => {
|
|
2731
3921
|
const seq = ++marketSeq.current
|
|
2732
3922
|
try {
|
|
2733
|
-
const next = await
|
|
3923
|
+
const next = await request('market/list', { board: marketBoard, page, pageSize: 50 })
|
|
2734
3924
|
if (alive.current && seq === marketSeq.current) setMarketList(next)
|
|
2735
3925
|
} catch (cause) {
|
|
2736
3926
|
if (alive.current && seq === marketSeq.current) setError(errorOf(cause))
|
|
@@ -2754,12 +3944,14 @@ window.__ModuleLoader__.load({
|
|
|
2754
3944
|
|
|
2755
3945
|
useEffect(() => {
|
|
2756
3946
|
if (tab === 'review') void loadReviewDetail()
|
|
2757
|
-
|
|
3947
|
+
if (tab === 'compare') void loadCompare()
|
|
3948
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3949
|
+
}, [tab, loadReviewDetail, loadCompare])
|
|
2758
3950
|
|
|
2759
3951
|
useEffect(() => {
|
|
2760
3952
|
if (tab === 'market') {
|
|
2761
3953
|
void loadMarket(1)
|
|
2762
|
-
|
|
3954
|
+
request('shortlist/get').then(result => { if (alive.current) setShortlist(result.symbols ?? []) }).catch(() => {})
|
|
2763
3955
|
}
|
|
2764
3956
|
}, [tab, marketBoard, loadMarket])
|
|
2765
3957
|
|
|
@@ -2777,7 +3969,7 @@ window.__ModuleLoader__.load({
|
|
|
2777
3969
|
setShortlist(next)
|
|
2778
3970
|
const seq = ++shortlistSeq.current
|
|
2779
3971
|
try {
|
|
2780
|
-
const result = await
|
|
3972
|
+
const result = await request('shortlist/set', { symbols: next })
|
|
2781
3973
|
if (!alive.current || seq !== shortlistSeq.current) return
|
|
2782
3974
|
shortlistRef.current = result.symbols ?? next
|
|
2783
3975
|
setShortlist(result.symbols ?? next)
|
|
@@ -2786,7 +3978,7 @@ window.__ModuleLoader__.load({
|
|
|
2786
3978
|
setError(errorOf(cause))
|
|
2787
3979
|
// The server is the source of truth after a failed write.
|
|
2788
3980
|
try {
|
|
2789
|
-
const fresh = await
|
|
3981
|
+
const fresh = await request('shortlist/get')
|
|
2790
3982
|
if (alive.current && seq === shortlistSeq.current) {
|
|
2791
3983
|
shortlistRef.current = fresh.symbols ?? []
|
|
2792
3984
|
setShortlist(fresh.symbols ?? [])
|
|
@@ -2802,103 +3994,6 @@ window.__ModuleLoader__.load({
|
|
|
2802
3994
|
setTab('trade')
|
|
2803
3995
|
}, [])
|
|
2804
3996
|
|
|
2805
|
-
const draft = useCallback(() => ({
|
|
2806
|
-
symbol: form.symbol.trim(),
|
|
2807
|
-
side: form.side,
|
|
2808
|
-
type: form.type,
|
|
2809
|
-
qty: Number(form.qty),
|
|
2810
|
-
limitPrice: form.type === 'limit' ? Number(form.limitPrice) : undefined,
|
|
2811
|
-
price: form.type === 'market' && form.price !== '' ? Number(form.price) : undefined,
|
|
2812
|
-
note: form.note.trim() === '' ? undefined : form.note.trim(),
|
|
2813
|
-
}), [form])
|
|
2814
|
-
|
|
2815
|
-
// The note is not part of the preview: only the trading fields are.
|
|
2816
|
-
const previewDraft = useCallback(() => ({
|
|
2817
|
-
symbol: form.symbol.trim(),
|
|
2818
|
-
side: form.side,
|
|
2819
|
-
type: form.type,
|
|
2820
|
-
qty: Number(form.qty),
|
|
2821
|
-
limitPrice: form.type === 'limit' ? Number(form.limitPrice) : undefined,
|
|
2822
|
-
price: form.type === 'market' && form.price !== '' ? Number(form.price) : undefined,
|
|
2823
|
-
}), [form.symbol, form.side, form.type, form.qty, form.limitPrice, form.price])
|
|
2824
|
-
|
|
2825
|
-
const previewSymbol = useRef('')
|
|
2826
|
-
const previewSeq = useRef(0)
|
|
2827
|
-
// Symbols whose quote the blocked-preview path already asked for.
|
|
2828
|
-
const quoteSymbol = useRef('')
|
|
2829
|
-
|
|
2830
|
-
// One preview per input change, debounced; the response carries the quote,
|
|
2831
|
-
// so a complete draft still costs a single request. While the draft is
|
|
2832
|
-
// unfinished the price line asks for the quote alone — a limit order
|
|
2833
|
-
// whose limit is still being typed must show what the stock costs.
|
|
2834
|
-
useEffect(() => {
|
|
2835
|
-
const current = previewDraft()
|
|
2836
|
-
previewSeq.current += 1
|
|
2837
|
-
const seq = previewSeq.current
|
|
2838
|
-
if (previewBlockReason(current) !== '') {
|
|
2839
|
-
previewSymbol.current = ''
|
|
2840
|
-
setPreview(null)
|
|
2841
|
-
setPreviewState('idle')
|
|
2842
|
-
setPreviewError('')
|
|
2843
|
-
if (current.symbol.length < 6) {
|
|
2844
|
-
quoteSymbol.current = ''
|
|
2845
|
-
setSymbolQuote(null)
|
|
2846
|
-
setQuoteError('')
|
|
2847
|
-
setQuoteNotice('')
|
|
2848
|
-
return
|
|
2849
|
-
}
|
|
2850
|
-
if (quoteSymbol.current === current.symbol) return
|
|
2851
|
-
const timer = setTimeout(() => {
|
|
2852
|
-
rpc('market/quote', { symbols: [current.symbol] })
|
|
2853
|
-
.then(result => {
|
|
2854
|
-
if (!alive.current || seq !== previewSeq.current) return
|
|
2855
|
-
const found = result.quotes[0] ?? null
|
|
2856
|
-
quoteSymbol.current = found === null ? '' : current.symbol
|
|
2857
|
-
setSymbolQuote(found)
|
|
2858
|
-
setQuoteError(found ? '' : (result.notice ?? '没有查到行情'))
|
|
2859
|
-
setQuoteNotice(found ? (result.notice ?? '') : '')
|
|
2860
|
-
})
|
|
2861
|
-
.catch(cause => {
|
|
2862
|
-
if (!alive.current || seq !== previewSeq.current) return
|
|
2863
|
-
quoteSymbol.current = ''
|
|
2864
|
-
setSymbolQuote(null)
|
|
2865
|
-
setQuoteError(errorOf(cause).text)
|
|
2866
|
-
setQuoteNotice('')
|
|
2867
|
-
})
|
|
2868
|
-
}, 300)
|
|
2869
|
-
return () => clearTimeout(timer)
|
|
2870
|
-
}
|
|
2871
|
-
quoteSymbol.current = current.symbol
|
|
2872
|
-
// A completed draft gets its quote from the preview; any error left
|
|
2873
|
-
// over from the earlier quote-only probe belongs to the old symbol and
|
|
2874
|
-
// must not stay on screen after the ticket has been corrected.
|
|
2875
|
-
setQuoteError('')
|
|
2876
|
-
setQuoteNotice('')
|
|
2877
|
-
if (previewSymbol.current !== current.symbol) {
|
|
2878
|
-
previewSymbol.current = current.symbol
|
|
2879
|
-
setPreview(null)
|
|
2880
|
-
}
|
|
2881
|
-
setPreviewState('loading')
|
|
2882
|
-
const timer = setTimeout(() => {
|
|
2883
|
-
rpc('order/preview', current)
|
|
2884
|
-
.then(result => {
|
|
2885
|
-
if (!alive.current || seq !== previewSeq.current) return
|
|
2886
|
-
setPreview(result)
|
|
2887
|
-
// Keep the quote for an unfinished draft: switching to 限价 must
|
|
2888
|
-
// not blank the price line while the limit is still being typed.
|
|
2889
|
-
if (result.quote) setSymbolQuote(result.quote)
|
|
2890
|
-
setPreviewError('')
|
|
2891
|
-
setPreviewState('ready')
|
|
2892
|
-
})
|
|
2893
|
-
.catch(cause => {
|
|
2894
|
-
if (!alive.current || seq !== previewSeq.current) return
|
|
2895
|
-
setPreviewError(errorOf(cause).text)
|
|
2896
|
-
setPreviewState('error')
|
|
2897
|
-
})
|
|
2898
|
-
}, 300)
|
|
2899
|
-
return () => clearTimeout(timer)
|
|
2900
|
-
}, [previewDraft, previewNonce])
|
|
2901
|
-
|
|
2902
3997
|
const doSubmit = useCallback(async () => {
|
|
2903
3998
|
if (submitting.current) return
|
|
2904
3999
|
submitting.current = true
|
|
@@ -2913,13 +4008,13 @@ window.__ModuleLoader__.load({
|
|
|
2913
4008
|
id: typeof crypto !== 'undefined' && crypto.randomUUID ? crypto.randomUUID() : `req-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
2914
4009
|
}
|
|
2915
4010
|
}
|
|
2916
|
-
const order = await
|
|
4011
|
+
const order = await request('order/place', { draft: current, requestId: placeKey.current.id })
|
|
2917
4012
|
const snapshot = await loadAll(true)
|
|
2918
4013
|
const fill = snapshot === null ? undefined : snapshot.trades.find(item => item.orderId === order.id)
|
|
2919
4014
|
setReceipt({ order, fill, cash: snapshot === null ? undefined : snapshot.account.cash })
|
|
2920
4015
|
placeKey.current = { key: '', id: '' }
|
|
2921
4016
|
// Keep the card's numbers; recompute them against the new cash.
|
|
2922
|
-
|
|
4017
|
+
bumpTicket()
|
|
2923
4018
|
} catch (cause) {
|
|
2924
4019
|
setReceipt({ failure: errorOf(cause) })
|
|
2925
4020
|
} finally {
|
|
@@ -2931,7 +4026,7 @@ window.__ModuleLoader__.load({
|
|
|
2931
4026
|
const cancel = useCallback(async orderId => {
|
|
2932
4027
|
setBusy(true)
|
|
2933
4028
|
try {
|
|
2934
|
-
await
|
|
4029
|
+
await request('order/cancel', { orderId })
|
|
2935
4030
|
await loadAll(true)
|
|
2936
4031
|
} catch (cause) {
|
|
2937
4032
|
// A lost response can make the retry see an already-finished order;
|
|
@@ -2958,7 +4053,7 @@ window.__ModuleLoader__.load({
|
|
|
2958
4053
|
|
|
2959
4054
|
const exportLedger = useCallback(async () => {
|
|
2960
4055
|
try {
|
|
2961
|
-
const result = await
|
|
4056
|
+
const result = await request('account/export')
|
|
2962
4057
|
if (!result.exists || !result.content) {
|
|
2963
4058
|
setNotice(result.notice ?? '账本文件尚未创建')
|
|
2964
4059
|
return
|
|
@@ -2986,12 +4081,12 @@ window.__ModuleLoader__.load({
|
|
|
2986
4081
|
if (cents === null) return
|
|
2987
4082
|
setBusy(true)
|
|
2988
4083
|
try {
|
|
2989
|
-
setAccount(await
|
|
2990
|
-
|
|
4084
|
+
setAccount(await request('account/reset', { confirm: true, initialCash: cents / 100 }))
|
|
4085
|
+
invalidateTicket()
|
|
2991
4086
|
setReceipt(null)
|
|
2992
4087
|
await loadAll(true)
|
|
2993
4088
|
await loadReviewDetail()
|
|
2994
|
-
|
|
4089
|
+
bumpTicket()
|
|
2995
4090
|
setResetNonce(value => value + 1)
|
|
2996
4091
|
setResetOpen(false)
|
|
2997
4092
|
setResetCash('')
|
|
@@ -3011,10 +4106,10 @@ window.__ModuleLoader__.load({
|
|
|
3011
4106
|
const depositing = cashSide === 'deposit'
|
|
3012
4107
|
setBusy(true)
|
|
3013
4108
|
try {
|
|
3014
|
-
setAccount(await
|
|
4109
|
+
setAccount(await request(depositing ? 'account/deposit' : 'account/withdraw', { amount }))
|
|
3015
4110
|
await loadAll(true)
|
|
3016
4111
|
await loadReviewDetail()
|
|
3017
|
-
|
|
4112
|
+
bumpTicket()
|
|
3018
4113
|
setCashAmount('')
|
|
3019
4114
|
setCashOpen(false)
|
|
3020
4115
|
setError(null)
|
|
@@ -3032,26 +4127,25 @@ window.__ModuleLoader__.load({
|
|
|
3032
4127
|
try {
|
|
3033
4128
|
await loadAll()
|
|
3034
4129
|
if (tab === 'review') await loadReviewDetail()
|
|
4130
|
+
if (tab === 'compare') await loadCompare()
|
|
3035
4131
|
// 刷新 must also retry the current tab's own fetch, not just the
|
|
3036
4132
|
// account bundle: a failed market list otherwise stays broken.
|
|
3037
4133
|
if (tab === 'market') await loadMarket(marketList?.page ?? 1)
|
|
3038
4134
|
// Force the incomplete-draft quote branch to fetch again even when
|
|
3039
4135
|
// the symbol did not change (a transient quote failure is retryable).
|
|
3040
|
-
|
|
3041
|
-
setPreviewNonce(value => value + 1)
|
|
4136
|
+
forceQuoteRefresh()
|
|
3042
4137
|
} finally {
|
|
3043
4138
|
setBusy(false)
|
|
3044
4139
|
}
|
|
3045
|
-
}, [loadAll, loadReviewDetail, tab, loadMarket, marketList?.page])
|
|
4140
|
+
}, [loadAll, loadReviewDetail, tab, loadMarket, marketList?.page, forceQuoteRefresh])
|
|
3046
4141
|
|
|
3047
4142
|
/** Only real blockers disable submit; a failed preview never does. */
|
|
3048
4143
|
/** Read the flag outside the deps array: `account` is null on the first render. */
|
|
3049
4144
|
const blocked = account?.blocked === true
|
|
3050
|
-
const quote = preview ? preview.quote ?? null : symbolQuote
|
|
3051
|
-
quoteRef.current = quote
|
|
3052
4145
|
const submitReason = useMemo(() => {
|
|
3053
4146
|
if (account === null) return '加载账户中'
|
|
3054
|
-
if (
|
|
4147
|
+
if (currentAccount !== null && currentAccount.locked) return '账户已锁定,先在账户菜单解锁'
|
|
4148
|
+
if (blocked) return '账本异常,需恢复或重置'
|
|
3055
4149
|
const symbol = form.symbol.trim()
|
|
3056
4150
|
if (symbol.length < 6) return '输入代码'
|
|
3057
4151
|
if (String(form.qty).trim() === '') return '填写数量'
|
|
@@ -3109,6 +4203,16 @@ window.__ModuleLoader__.load({
|
|
|
3109
4203
|
),
|
|
3110
4204
|
h('div', { className: 'pt-row' },
|
|
3111
4205
|
accountSwitch,
|
|
4206
|
+
h(AccountPicker, {
|
|
4207
|
+
accounts: stockAccounts,
|
|
4208
|
+
archived,
|
|
4209
|
+
current: currentAccount,
|
|
4210
|
+
onRestoreArchived: restoreArchived,
|
|
4211
|
+
busy,
|
|
4212
|
+
onSelect: id => setCurrentAccountId(id),
|
|
4213
|
+
onCreate: () => setAccountEditor('create'),
|
|
4214
|
+
onAction: runAccountAction,
|
|
4215
|
+
}),
|
|
3112
4216
|
h(DataSourceBadge, { status: dataSource }),
|
|
3113
4217
|
h('button', { className: 'pt-btn', onClick: refreshAll, disabled: busy }, '刷新'),
|
|
3114
4218
|
h('button', {
|
|
@@ -3156,9 +4260,17 @@ window.__ModuleLoader__.load({
|
|
|
3156
4260
|
},
|
|
3157
4261
|
onSubmit: reset,
|
|
3158
4262
|
}) : null,
|
|
4263
|
+
accountEditor === null ? null : h(AccountEditor, {
|
|
4264
|
+
key: `${accountEditor}:${currentAccountId ?? ''}`,
|
|
4265
|
+
mode: accountEditor,
|
|
4266
|
+
current: currentAccount,
|
|
4267
|
+
busy,
|
|
4268
|
+
onCancel: () => setAccountEditor(null),
|
|
4269
|
+
onSubmit: submitAccountEditor,
|
|
4270
|
+
}),
|
|
3159
4271
|
account.blocked ? h('div', { className: 'pt-blocked' },
|
|
3160
4272
|
h('div', { className: 'pt-blocked-text' },
|
|
3161
|
-
h('div', null, '
|
|
4273
|
+
h('div', null, '账本校验失败,账户已冻结。'),
|
|
3162
4274
|
account.blockedReason ? h('div', { className: 'pt-blocked-detail', title: account.blockedReason }, `原因:${account.blockedReason}`) : null,
|
|
3163
4275
|
account.ledgerPath ? h('div', { className: 'pt-blocked-detail', title: account.ledgerPath }, `账本:${account.ledgerPath}`) : null,
|
|
3164
4276
|
h('div', { className: 'pt-blocked-hint' }, '可让 AI 助手用 paper_ledger 从备份恢复;重置会先备份。'),
|
|
@@ -3176,10 +4288,16 @@ window.__ModuleLoader__.load({
|
|
|
3176
4288
|
),
|
|
3177
4289
|
error ? h('div', { className: 'pt-error', title: error.detail || undefined }, error.text) : null,
|
|
3178
4290
|
notice ? h('div', { className: 'pt-note' }, notice) : null,
|
|
3179
|
-
h('div', {
|
|
4291
|
+
h('div', {
|
|
4292
|
+
className: 'pt-workspace',
|
|
4293
|
+
'data-rail-width': layout.rail === null ? undefined : String(layout.rail),
|
|
4294
|
+
'data-rail-collapsed': layout.collapsed ? 'true' : undefined,
|
|
4295
|
+
'data-kline-height': layout.klineHeight === 'auto' ? undefined : layout.klineHeight,
|
|
4296
|
+
style: layout.rail === null ? undefined : { '--pt-rail-width': `${layout.rail}px` },
|
|
4297
|
+
},
|
|
3180
4298
|
h('div', { className: 'pt-main' },
|
|
3181
4299
|
h('div', { className: 'pt-tabs' },
|
|
3182
|
-
[['trade', '交易'], ['basket', '批量'], ['market', '行情'], ['positions', `持仓 ${positions.length}`], ['orders', `订单 ${pending.length}`], ['review', '复盘']].map(([key, label]) =>
|
|
4300
|
+
[['trade', '交易'], ['basket', '批量'], ['market', '行情'], ['positions', `持仓 ${positions.length}`], ['orders', `订单 ${pending.length}`], ['review', '复盘'], ['compare', '对比'], ['notes', '笔记']].map(([key, label]) =>
|
|
3183
4301
|
h('button', { key, className: 'pt-tab', 'data-active': tab === key, onClick: () => setTab(key) }, label),
|
|
3184
4302
|
),
|
|
3185
4303
|
),
|
|
@@ -3212,6 +4330,17 @@ window.__ModuleLoader__.load({
|
|
|
3212
4330
|
setPeriod: key => setPeriod(key),
|
|
3213
4331
|
trades, daily, cashFlow, trips,
|
|
3214
4332
|
}) : null,
|
|
4333
|
+
tab === 'compare' ? h(CompareTab, { data: compareData, error: compareError }) : null,
|
|
4334
|
+
tab === 'notes' ? h(NotesTab, {
|
|
4335
|
+
text: notes.text,
|
|
4336
|
+
status: notes.status,
|
|
4337
|
+
updatedAt: notes.meta === null ? undefined : notes.meta.updatedAt,
|
|
4338
|
+
error: notes.error,
|
|
4339
|
+
onChange: notes.change,
|
|
4340
|
+
onSave: () => { void notes.flush() },
|
|
4341
|
+
onReload: () => { void notes.reload() },
|
|
4342
|
+
maxBytes: notes.meta === null || notes.meta.maxBytes === undefined ? 100000 : notes.meta.maxBytes,
|
|
4343
|
+
}) : null,
|
|
3215
4344
|
),
|
|
3216
4345
|
),
|
|
3217
4346
|
h(KlinePane, {
|
|
@@ -3224,11 +4353,22 @@ window.__ModuleLoader__.load({
|
|
|
3224
4353
|
onInterval: setBarInterval,
|
|
3225
4354
|
onRefresh: () => loadBars(),
|
|
3226
4355
|
onIdentity: klineIdentity,
|
|
4356
|
+
collapsed: layout.collapsed,
|
|
4357
|
+
onCollapse: () => applyLayout({ collapsed: true }),
|
|
4358
|
+
onExpand: () => applyLayout({ collapsed: false }),
|
|
4359
|
+
onRail: value => applyLayout({ rail: value }, false),
|
|
4360
|
+
onRailCommit: value => applyLayout({ rail: value }),
|
|
4361
|
+
onRailReset: () => applyLayout({ rail: null }),
|
|
4362
|
+
height: layout.klineHeight,
|
|
4363
|
+
onHeight: value => { if (KLINE_HEIGHTS.includes(value)) applyLayout({ klineHeight: value }) },
|
|
3227
4364
|
}),
|
|
3228
4365
|
),
|
|
3229
4366
|
)
|
|
3230
4367
|
}
|
|
3231
4368
|
|
|
4369
|
+
/* ---- 70-plugin.js ---- */
|
|
4370
|
+
/* 70 · plugin — sidebar glyph, cordis apply and the exported surface. */
|
|
4371
|
+
|
|
3232
4372
|
const PANEL_ID = 'ft-paper-trading'
|
|
3233
4373
|
|
|
3234
4374
|
/** Candlestick glyph; the sidebar owns the button, label and tooltip. */
|
|
@@ -3244,11 +4384,35 @@ window.__ModuleLoader__.load({
|
|
|
3244
4384
|
}
|
|
3245
4385
|
|
|
3246
4386
|
function apply(ctx) {
|
|
4387
|
+
// The sidebar renders this row, so its text is host chrome and follows the
|
|
4388
|
+
// host interface language — not the panel copy, which stays Chinese. The
|
|
4389
|
+
// host re-reads `label` on every locale change, so a thunk is enough; the
|
|
4390
|
+
// two product names match `locale/zh.json` and `locale/en.json`, which
|
|
4391
|
+
// carry the same names into the plugin list.
|
|
4392
|
+
let hostLocale
|
|
4393
|
+
const panelLabel = () => {
|
|
4394
|
+
let active
|
|
4395
|
+
try {
|
|
4396
|
+
active = hostLocale?.getLocale?.().active
|
|
4397
|
+
} catch {
|
|
4398
|
+
active = undefined
|
|
4399
|
+
}
|
|
4400
|
+
const tag = active ?? (typeof navigator === 'undefined' ? '' : navigator.language)
|
|
4401
|
+
return String(tag).toLowerCase().startsWith('zh') ? '模拟交易' : 'Paper Trading'
|
|
4402
|
+
}
|
|
4403
|
+
// Optional: hosts without the locale service keep browser-language naming
|
|
4404
|
+
// instead of losing the whole client half to an unmet injection.
|
|
4405
|
+
ctx.inject(['locale'], scope => {
|
|
4406
|
+
const locale = scope.get('locale')
|
|
4407
|
+
if (locale === undefined) return () => {}
|
|
4408
|
+
hostLocale = locale
|
|
4409
|
+
return () => { if (hostLocale === locale) hostLocale = undefined }
|
|
4410
|
+
})
|
|
3247
4411
|
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
|
|
3248
4412
|
name: 'sidebar.panellist',
|
|
3249
4413
|
id: PANEL_ID,
|
|
3250
4414
|
order: 30,
|
|
3251
|
-
label:
|
|
4415
|
+
label: panelLabel,
|
|
3252
4416
|
}, PaperGlyph))
|
|
3253
4417
|
ctx.slots.inject('main', () => ctx.slots.register({
|
|
3254
4418
|
name: 'main',
|
|
@@ -3270,6 +4434,8 @@ window.__ModuleLoader__.load({
|
|
|
3270
4434
|
const inject = ['slots']
|
|
3271
4435
|
exports.apply = apply
|
|
3272
4436
|
exports.inject = inject
|
|
4437
|
+
|
|
4438
|
+
|
|
3273
4439
|
return module.exports
|
|
3274
4440
|
},
|
|
3275
4441
|
})
|