mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-14 16:26:57 +08:00
@@ -1,6 +1,7 @@
|
|||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
import { useLanguage } from '../contexts/LanguageContext';
|
import { useLanguage } from '../contexts/LanguageContext';
|
||||||
import { t } from '../i18n/translations';
|
import { t } from '../i18n/translations';
|
||||||
|
import { api } from '../lib/api';
|
||||||
|
|
||||||
interface TradeOutcome {
|
interface TradeOutcome {
|
||||||
symbol: string;
|
symbol: string;
|
||||||
@@ -44,13 +45,11 @@ interface AILearningProps {
|
|||||||
traderId: string;
|
traderId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetcher = (url: string) => fetch(url).then(res => res.json());
|
|
||||||
|
|
||||||
export default function AILearning({ traderId }: AILearningProps) {
|
export default function AILearning({ traderId }: AILearningProps) {
|
||||||
const { language } = useLanguage();
|
const { language } = useLanguage();
|
||||||
const { data: performance, error } = useSWR<PerformanceAnalysis>(
|
const { data: performance, error } = useSWR<PerformanceAnalysis>(
|
||||||
`http://localhost:8080/api/performance?trader_id=${traderId}`,
|
traderId ? `performance-${traderId}` : 'performance',
|
||||||
fetcher,
|
() => api.getPerformance(traderId),
|
||||||
{ refreshInterval: 10000 }
|
{ refreshInterval: 10000 }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -100,4 +100,14 @@ export const api = {
|
|||||||
if (!res.ok) throw new Error('获取历史数据失败');
|
if (!res.ok) throw new Error('获取历史数据失败');
|
||||||
return res.json();
|
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();
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user