diff --git a/frontend/src/components/TradeList.jsx b/frontend/src/components/TradeList.jsx
index e40b709..8c9165a 100644
--- a/frontend/src/components/TradeList.jsx
+++ b/frontend/src/components/TradeList.jsx
@@ -22,6 +22,9 @@ const TradeList = () => {
const [exitReason, setExitReason] = useState('')
const [reconciledOnly, setReconciledOnly] = useState(true) // 默认仅可对账,与币安一致
const [timeFilter, setTimeFilter] = useState('exit') // 'exit' 按平仓时间(今天=今天平掉的单), 'entry' 按开仓时间
+ const [syncing, setSyncing] = useState(false) // 同步订单状态
+ const [syncResult, setSyncResult] = useState(null) // 同步结果
+ const [syncDays, setSyncDays] = useState(7) // 同步天数
useEffect(() => {
loadData()
@@ -87,6 +90,41 @@ const TradeList = () => {
setReconciledOnly(true)
}
+ // 同步订单:从币安同步历史订单,补全缺失的订单号
+ const handleSyncOrders = async () => {
+ if (syncing) {
+ return // 防止重复点击
+ }
+
+ if (!window.confirm(`确定要同步最近 ${syncDays} 天的订单吗?\n这将从币安拉取历史订单并补全缺失的订单号。`)) {
+ return
+ }
+
+ setSyncing(true)
+ setSyncResult(null)
+
+ try {
+ const result = await api.syncTradesFromBinance(syncDays)
+ setSyncResult({
+ success: true,
+ message: `同步完成:共处理 ${result.total_orders || 0} 个订单,更新 ${result.updated_trades || 0} 条记录`,
+ details: result
+ })
+ // 同步成功后自动刷新数据
+ setTimeout(() => {
+ loadData()
+ }, 1000)
+ } catch (error) {
+ setSyncResult({
+ success: false,
+ message: `同步失败:${error.message || '未知错误'}`,
+ details: null
+ })
+ } finally {
+ setSyncing(false)
+ }
+ }
+
// 导出当前订单数据(含入场/离场原因、入场思路等完整字段,便于后续分析)
// type: 'csv' | 'json'
const handleExport = (type = 'csv') => {
@@ -484,6 +522,35 @@ const TradeList = () => {
+
+
+
+
+
{trades.length > 0 && (
<>