From 4d8a56bda4f1e85b5cb9a7865e8ac55f560f6685 Mon Sep 17 00:00:00 2001 From: Sanjana Date: Sat, 11 Jul 2026 22:33:03 +0530 Subject: [PATCH] refactor(frontend): replace explicit any types in accounts service --- frontend/lib/services/accounts.ts | 92 ++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 15 deletions(-) diff --git a/frontend/lib/services/accounts.ts b/frontend/lib/services/accounts.ts index 20a97b6..b886799 100644 --- a/frontend/lib/services/accounts.ts +++ b/frontend/lib/services/accounts.ts @@ -1,13 +1,75 @@ import api from "../api"; +export interface AccountSettingsConfig { + active_symbols?: string[]; + active_symbol?: string; + leverage?: number; + sizing_mode?: "fixed_usd" | "pct_capital"; + base_order_usd?: number; + base_order_pct?: number; + compounding_enabled?: boolean; + compounding_pct?: number; + volume_scale?: number; + max_safety_orders?: number; + step_scale?: number; + take_profit_pct?: number; + tp_mode?: "pct" | "fixed"; + tp_fixed_amount?: number; + rsi_long_threshold?: number; + rsi_short_threshold?: number; + signal_threshold?: number; + allow_long?: boolean; + allow_short?: boolean; + max_basket_age_hours?: number; + trend_filter_enabled?: boolean; + trend_timeframes?: string[]; + trend_mode?: string; + trend_ema_fast?: number; + trend_ema_slow?: number; + risk_controller_enabled?: boolean; + rc_max_so_trigger?: number; + rc_margin_usage_pct?: number; + rc_max_basket_loss_pct?: number; + rc_max_basket_loss_usd?: number; + rc_loss_mode?: "pct_wallet" | "fixed_usd"; + rc_loss_direction?: "exceeds" | "recovers_to"; + rc_margin_guard_enabled?: boolean; + [key: string]: unknown; +} + export interface AccountSettingsResponse { - config: Record; + config: AccountSettingsConfig; account_id: string; version: number; updated_at: string; updated_by: string | null; } +export interface AccountConnectionTestResponse { + status: "success" | "error"; + message: string; + data?: Record; +} + +export interface AccountDashboardResponse { + account_summary: { + total_wallet_balance: string; + total_unrealized_pnl: string; + total_margin_balance: string; + available_balance: string; + }; + balances: Array>; + positions: Array>; + open_orders: Array>; + recent_trades: Array>; + income_history: Array>; +} + +export interface EmergencyCloseResponse { + status: string; + details: Record; +} + export interface AccountResponse { id: string; workspace_id: string; @@ -43,46 +105,46 @@ export interface PlatformTradingStatus { export const accountsService = { async listAccounts(): Promise { const response = await api.get("/accounts/"); - return response.json(); + return (await response.json()) as AccountResponse[]; }, async getAccount(accountId: string): Promise { const response = await api.get(`/accounts/${accountId}`); - return response.json(); + return (await response.json()) as AccountResponse; }, async createAccount(data: AccountCreate): Promise { const response = await api.post("/accounts/", data); - return response.json(); + return (await response.json()) as AccountResponse; }, async updateAccount(accountId: string, data: Partial): Promise { const response = await api.patch(`/accounts/${accountId}`, data); - return response.json(); + return (await response.json()) as AccountResponse; }, - async updateAccountSettings(accountId: string, config: Record): Promise { + async updateAccountSettings(accountId: string, config: AccountSettingsConfig): Promise { const response = await api.patch(`/accounts/${accountId}/settings`, { config }); - return response.json(); + return (await response.json()) as AccountSettingsResponse; }, async deleteAccount(accountId: string): Promise { await api.delete(`/accounts/${accountId}`); }, - async testConnection(accountId: string): Promise { + async testConnection(accountId: string): Promise { const response = await api.post(`/accounts/${accountId}/test-connection`, {}); - return response.json(); + return (await response.json()) as AccountConnectionTestResponse; }, - async previewConnection(data: ConnectionTestRequest): Promise { + async previewConnection(data: ConnectionTestRequest): Promise { const response = await api.post("/accounts/test-connection/preview", data); - return response.json(); + return (await response.json()) as AccountConnectionTestResponse; }, - async getAccountDashboard(accountId: string): Promise { + async getAccountDashboard(accountId: string): Promise { const response = await api.get(`/accounts/${accountId}/dashboard`); - return response.json(); + return (await response.json()) as AccountDashboardResponse; }, async toggleAutoTrade(accountId: string, enabled: boolean): Promise { @@ -100,9 +162,9 @@ export const accountsService = { return response.json(); }, - async emergencyClose(accountId: string): Promise { + async emergencyClose(accountId: string): Promise { const response = await api.post(`/accounts/${accountId}/emergency-close`, {}); - return response.json(); + return (await response.json()) as EmergencyCloseResponse; }, async getPlatformTradingStatus(): Promise {