diff --git a/frontend/src/services/api.js b/frontend/src/services/api.js index de3f677..3253ea4 100644 --- a/frontend/src/services/api.js +++ b/frontend/src/services/api.js @@ -88,8 +88,6 @@ const withAccountHeaders = (headers = {}, accountIdOverride = null) => { currentAccountIdFromStore = aid; } } - // 调试日志:记录使用的 accountId - console.log(`[API] withAccountHeaders: accountIdOverride=${accountIdOverride}, currentAccountIdFromStore=${currentAccountIdFromStore}, final accountId=${aid}`); return withAuthHeaders({ ...headers, 'X-Account-Id': String(aid) }); }; @@ -137,7 +135,7 @@ export const api = { // 账号管理 getAccounts: async () => { - const response = await fetch(buildUrl('/api/account'), { headers: withAccountHeaders() }); + const response = await fetch(buildUrl('/api/accounts'), { headers: withAccountHeaders() }); if (!response.ok) { const error = await response.json().catch(() => ({ detail: '获取账号列表失败' })); throw new Error(error.detail || '获取账号列表失败'); @@ -145,7 +143,7 @@ export const api = { return response.json(); }, createAccount: async (data) => { - const response = await fetch(buildUrl('/api/account'), { + const response = await fetch(buildUrl('/api/accounts'), { method: 'POST', headers: withAccountHeaders({ 'Content-Type': 'application/json' }), body: JSON.stringify(data || {}), @@ -157,7 +155,7 @@ export const api = { return response.json(); }, updateAccount: async (accountId, data) => { - const response = await fetch(buildUrl(`/api/account/${accountId}`), { + const response = await fetch(buildUrl(`/api/accounts/${accountId}`), { method: 'PUT', headers: withAccountHeaders({ 'Content-Type': 'application/json' }), body: JSON.stringify(data || {}), @@ -169,7 +167,7 @@ export const api = { return response.json(); }, updateAccountCredentials: async (accountId, data) => { - const response = await fetch(buildUrl(`/api/account/${accountId}/credentials`), { + const response = await fetch(buildUrl(`/api/accounts/${accountId}/credentials`), { method: 'PUT', headers: withAccountHeaders({ 'Content-Type': 'application/json' }), body: JSON.stringify(data || {}), @@ -183,7 +181,7 @@ export const api = { // 交易进程(按账号;需要 owner 或 admin) getAccountTradingStatus: async (accountId) => { - const response = await fetch(buildUrl(`/api/account/${accountId}/trading/status`), { headers: withAccountHeaders() }) + const response = await fetch(buildUrl(`/api/accounts/${accountId}/trading/status`), { headers: withAccountHeaders() }) if (!response.ok) { const error = await response.json().catch(() => ({ detail: '获取交易进程状态失败' })) throw new Error(error.detail || '获取交易进程状态失败') @@ -191,7 +189,7 @@ export const api = { return response.json() }, startAccountTrading: async (accountId) => { - const response = await fetch(buildUrl(`/api/account/${accountId}/trading/start`), { + const response = await fetch(buildUrl(`/api/accounts/${accountId}/trading/start`), { method: 'POST', headers: withAccountHeaders({ 'Content-Type': 'application/json' }), }) @@ -202,7 +200,7 @@ export const api = { return response.json() }, stopAccountTrading: async (accountId) => { - const response = await fetch(buildUrl(`/api/account/${accountId}/trading/stop`), { + const response = await fetch(buildUrl(`/api/accounts/${accountId}/trading/stop`), { method: 'POST', headers: withAccountHeaders({ 'Content-Type': 'application/json' }), }) @@ -213,7 +211,7 @@ export const api = { return response.json() }, restartAccountTrading: async (accountId) => { - const response = await fetch(buildUrl(`/api/account/${accountId}/trading/restart`), { + const response = await fetch(buildUrl(`/api/accounts/${accountId}/trading/restart`), { method: 'POST', headers: withAccountHeaders({ 'Content-Type': 'application/json' }), }) @@ -224,7 +222,7 @@ export const api = { return response.json() }, ensureAccountTradingProgram: async (accountId) => { - const response = await fetch(buildUrl(`/api/account/${accountId}/trading/ensure-program`), { + const response = await fetch(buildUrl(`/api/accounts/${accountId}/trading/ensure-program`), { method: 'POST', headers: withAccountHeaders({ 'Content-Type': 'application/json' }), })