Merge branch 'tinkle-community:main' into main

This commit is contained in:
d0lwl0b
2025-10-30 12:13:00 +08:00
committed by GitHub
22 changed files with 1758 additions and 30 deletions

View File

@@ -1,6 +1,7 @@
import useSWR from 'swr';
import { useLanguage } from '../contexts/LanguageContext';
import { t } from '../i18n/translations';
import { api } from '../lib/api';
interface TradeOutcome {
symbol: string;
@@ -44,13 +45,11 @@ interface AILearningProps {
traderId: string;
}
const fetcher = (url: string) => fetch(url).then(res => res.json());
export default function AILearning({ traderId }: AILearningProps) {
const { language } = useLanguage();
const { data: performance, error } = useSWR<PerformanceAnalysis>(
`http://localhost:8080/api/performance?trader_id=${traderId}`,
fetcher,
traderId ? `performance-${traderId}` : 'performance',
() => api.getPerformance(traderId),
{ refreshInterval: 10000 }
);

View File

@@ -80,8 +80,10 @@ export function EquityChart({ traderId }: EquityChartProps) {
? history.slice(-MAX_DISPLAY_POINTS)
: history;
// 计算初始余额(使用第一个数据点)
const initialBalance = history[0]?.total_equity || 1000;
// 计算初始余额(使用第一个数据点如果无数据则从account获取最后才用默认值
const initialBalance = history[0]?.total_equity
|| account?.total_equity
|| 100; // 默认值改为100与常见配置一致
// 转换数据格式
const chartData = displayHistory.map((point) => {

View File

@@ -100,4 +100,14 @@ export const api = {
if (!res.ok) throw new Error('获取历史数据失败');
return res.json();
},
// 获取AI学习表现分析支持trader_id
async getPerformance(traderId?: string): Promise<any> {
const url = traderId
? `${API_BASE}/performance?trader_id=${traderId}`
: `${API_BASE}/performance`;
const res = await fetch(url);
if (!res.ok) throw new Error('获取AI学习数据失败');
return res.json();
},
};