mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-03 19:11:02 +08:00
- Resolved conflicts in README.md: Combined web-based config updates with multi-exchange support - Resolved conflicts in main.go: Fixed database initialization and default coin settings - Resolved conflicts in manager/trader_manager.go: Updated trader management for new database structure - Resolved conflicts in web/src/App.tsx: Combined UI improvements with responsive design - Resolved conflicts in web/.dockerignore: Merged dependency exclusions - Removed deprecated files: Dockerfile, config/config.go, web/Dockerfile, ComparisonChart.tsx, CompetitionPage.tsx 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
175 lines
5.4 KiB
TypeScript
175 lines
5.4 KiB
TypeScript
import type {
|
||
SystemStatus,
|
||
AccountInfo,
|
||
Position,
|
||
DecisionRecord,
|
||
Statistics,
|
||
TraderInfo,
|
||
AIModel,
|
||
Exchange,
|
||
CreateTraderRequest,
|
||
UpdateModelConfigRequest,
|
||
UpdateExchangeConfigRequest,
|
||
} from '../types';
|
||
|
||
const API_BASE = '/api';
|
||
|
||
export const api = {
|
||
// AI交易员管理接口
|
||
async getTraders(): Promise<TraderInfo[]> {
|
||
const res = await fetch(`${API_BASE}/traders`);
|
||
if (!res.ok) throw new Error('获取trader列表失败');
|
||
return res.json();
|
||
},
|
||
|
||
async createTrader(request: CreateTraderRequest): Promise<TraderInfo> {
|
||
const res = await fetch(`${API_BASE}/traders`, {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify(request),
|
||
});
|
||
if (!res.ok) throw new Error('创建交易员失败');
|
||
return res.json();
|
||
},
|
||
|
||
async deleteTrader(traderId: string): Promise<void> {
|
||
const res = await fetch(`${API_BASE}/traders/${traderId}`, {
|
||
method: 'DELETE',
|
||
});
|
||
if (!res.ok) throw new Error('删除交易员失败');
|
||
},
|
||
|
||
async startTrader(traderId: string): Promise<void> {
|
||
const res = await fetch(`${API_BASE}/traders/${traderId}/start`, {
|
||
method: 'POST',
|
||
});
|
||
if (!res.ok) throw new Error('启动交易员失败');
|
||
},
|
||
|
||
async stopTrader(traderId: string): Promise<void> {
|
||
const res = await fetch(`${API_BASE}/traders/${traderId}/stop`, {
|
||
method: 'POST',
|
||
});
|
||
if (!res.ok) throw new Error('停止交易员失败');
|
||
},
|
||
|
||
// AI模型配置接口
|
||
async getModelConfigs(): Promise<AIModel[]> {
|
||
const res = await fetch(`${API_BASE}/models`);
|
||
if (!res.ok) throw new Error('获取模型配置失败');
|
||
return res.json();
|
||
},
|
||
|
||
async updateModelConfigs(request: UpdateModelConfigRequest): Promise<void> {
|
||
const res = await fetch(`${API_BASE}/models`, {
|
||
method: 'PUT',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify(request),
|
||
});
|
||
if (!res.ok) throw new Error('更新模型配置失败');
|
||
},
|
||
|
||
// 交易所配置接口
|
||
async getExchangeConfigs(): Promise<Exchange[]> {
|
||
const res = await fetch(`${API_BASE}/exchanges`);
|
||
if (!res.ok) throw new Error('获取交易所配置失败');
|
||
return res.json();
|
||
},
|
||
|
||
async updateExchangeConfigs(request: UpdateExchangeConfigRequest): Promise<void> {
|
||
const res = await fetch(`${API_BASE}/exchanges`, {
|
||
method: 'PUT',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify(request),
|
||
});
|
||
if (!res.ok) throw new Error('更新交易所配置失败');
|
||
},
|
||
|
||
// 获取系统状态(支持trader_id)
|
||
async getStatus(traderId?: string): Promise<SystemStatus> {
|
||
const url = traderId
|
||
? `${API_BASE}/status?trader_id=${traderId}`
|
||
: `${API_BASE}/status`;
|
||
const res = await fetch(url);
|
||
if (!res.ok) throw new Error('获取系统状态失败');
|
||
return res.json();
|
||
},
|
||
|
||
// 获取账户信息(支持trader_id)
|
||
async getAccount(traderId?: string): Promise<AccountInfo> {
|
||
const url = traderId
|
||
? `${API_BASE}/account?trader_id=${traderId}`
|
||
: `${API_BASE}/account`;
|
||
const res = await fetch(url, {
|
||
cache: 'no-store',
|
||
headers: {
|
||
'Cache-Control': 'no-cache',
|
||
},
|
||
});
|
||
if (!res.ok) throw new Error('获取账户信息失败');
|
||
const data = await res.json();
|
||
console.log('Account data fetched:', data);
|
||
return data;
|
||
},
|
||
|
||
// 获取持仓列表(支持trader_id)
|
||
async getPositions(traderId?: string): Promise<Position[]> {
|
||
const url = traderId
|
||
? `${API_BASE}/positions?trader_id=${traderId}`
|
||
: `${API_BASE}/positions`;
|
||
const res = await fetch(url);
|
||
if (!res.ok) throw new Error('获取持仓列表失败');
|
||
return res.json();
|
||
},
|
||
|
||
// 获取决策日志(支持trader_id)
|
||
async getDecisions(traderId?: string): Promise<DecisionRecord[]> {
|
||
const url = traderId
|
||
? `${API_BASE}/decisions?trader_id=${traderId}`
|
||
: `${API_BASE}/decisions`;
|
||
const res = await fetch(url);
|
||
if (!res.ok) throw new Error('获取决策日志失败');
|
||
return res.json();
|
||
},
|
||
|
||
// 获取最新决策(支持trader_id)
|
||
async getLatestDecisions(traderId?: string): Promise<DecisionRecord[]> {
|
||
const url = traderId
|
||
? `${API_BASE}/decisions/latest?trader_id=${traderId}`
|
||
: `${API_BASE}/decisions/latest`;
|
||
const res = await fetch(url);
|
||
if (!res.ok) throw new Error('获取最新决策失败');
|
||
return res.json();
|
||
},
|
||
|
||
// 获取统计信息(支持trader_id)
|
||
async getStatistics(traderId?: string): Promise<Statistics> {
|
||
const url = traderId
|
||
? `${API_BASE}/statistics?trader_id=${traderId}`
|
||
: `${API_BASE}/statistics`;
|
||
const res = await fetch(url);
|
||
if (!res.ok) throw new Error('获取统计信息失败');
|
||
return res.json();
|
||
},
|
||
|
||
// 获取收益率历史数据(支持trader_id)
|
||
async getEquityHistory(traderId?: string): Promise<any[]> {
|
||
const url = traderId
|
||
? `${API_BASE}/equity-history?trader_id=${traderId}`
|
||
: `${API_BASE}/equity-history`;
|
||
const res = await fetch(url);
|
||
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();
|
||
},
|
||
};
|