/** * 全部持仓 tab 组件 * 显示全量真实持仓(QMT),标注每只票的份额分配 */ import { useState, useEffect, useCallback } from 'react'; import { useRpc } from './connection.jsx'; import { LoadState } from './LoadState.jsx'; import { useMarket } from '../market/MarketDataProvider.jsx'; import { PriceCell } from './PriceCell.jsx'; export function AllPositionsTab(props) { const [positions, setPositions] = useState(null); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); const call = useRpc(); const { getPrice, registerCodes } = useMarket(); const load = useCallback(async () => { setLoading(true); setError(null); try { const res = await call('one-divine-lot/summary'); if (res && res.ok) { setPositions(res.value); // 上报持仓 code 给行情 Provider(去重:不再由 Provider 自拉 positions) const codes = (res.value?.positions ?? []).map((p) => p.code).filter(Boolean); registerCodes(codes); } else setError((res && res.error && res.error.message) || '加载失败'); } catch (e) { setError(e.message); } finally { setLoading(false); } }, [call]); useEffect(() => { load(); }, [load]); return (
| 代码 | 名称 | 现价 | 总持仓 | 已分配 | 未分配 | 分配详情 |
|---|---|---|---|---|---|---|
| {p.code} | {p.name} | {p.totalVolume} | {p.allocated} | 0 ? '#e65100' : '#2e7d32' }}>{p.unallocated} | {Object.entries(p.shares).map(([sid, n]) => sid + ': ' + n).join(', ') || '—'} |