Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 77 additions & 15 deletions frontend/lib/services/accounts.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>;
config: AccountSettingsConfig;
account_id: string;
version: number;
updated_at: string;
updated_by: string | null;
}

export interface AccountConnectionTestResponse {
status: "success" | "error";
message: string;
data?: Record<string, unknown>;
}

export interface AccountDashboardResponse {
account_summary: {
total_wallet_balance: string;
total_unrealized_pnl: string;
total_margin_balance: string;
available_balance: string;
};
balances: Array<Record<string, unknown>>;
positions: Array<Record<string, unknown>>;
open_orders: Array<Record<string, unknown>>;
recent_trades: Array<Record<string, unknown>>;
income_history: Array<Record<string, unknown>>;
}

export interface EmergencyCloseResponse {
status: string;
details: Record<string, string>;
}

export interface AccountResponse {
id: string;
workspace_id: string;
Expand Down Expand Up @@ -43,46 +105,46 @@ export interface PlatformTradingStatus {
export const accountsService = {
async listAccounts(): Promise<AccountResponse[]> {
const response = await api.get("/accounts/");
return response.json();
return (await response.json()) as AccountResponse[];
},

async getAccount(accountId: string): Promise<AccountResponse> {
const response = await api.get(`/accounts/${accountId}`);
return response.json();
return (await response.json()) as AccountResponse;
},

async createAccount(data: AccountCreate): Promise<AccountResponse> {
const response = await api.post("/accounts/", data);
return response.json();
return (await response.json()) as AccountResponse;
},

async updateAccount(accountId: string, data: Partial<AccountCreate>): Promise<AccountResponse> {
const response = await api.patch(`/accounts/${accountId}`, data);
return response.json();
return (await response.json()) as AccountResponse;
},

async updateAccountSettings(accountId: string, config: Record<string, any>): Promise<AccountSettingsResponse> {
async updateAccountSettings(accountId: string, config: AccountSettingsConfig): Promise<AccountSettingsResponse> {
const response = await api.patch(`/accounts/${accountId}/settings`, { config });
return response.json();
return (await response.json()) as AccountSettingsResponse;
},

async deleteAccount(accountId: string): Promise<void> {
await api.delete(`/accounts/${accountId}`);
},

async testConnection(accountId: string): Promise<any> {
async testConnection(accountId: string): Promise<AccountConnectionTestResponse> {
const response = await api.post(`/accounts/${accountId}/test-connection`, {});
return response.json();
return (await response.json()) as AccountConnectionTestResponse;
},

async previewConnection(data: ConnectionTestRequest): Promise<any> {
async previewConnection(data: ConnectionTestRequest): Promise<AccountConnectionTestResponse> {
const response = await api.post("/accounts/test-connection/preview", data);
return response.json();
return (await response.json()) as AccountConnectionTestResponse;
},

async getAccountDashboard(accountId: string): Promise<any> {
async getAccountDashboard(accountId: string): Promise<AccountDashboardResponse> {
const response = await api.get(`/accounts/${accountId}/dashboard`);
return response.json();
return (await response.json()) as AccountDashboardResponse;
},

async toggleAutoTrade(accountId: string, enabled: boolean): Promise<AccountResponse> {
Expand All @@ -100,9 +162,9 @@ export const accountsService = {
return response.json();
},

async emergencyClose(accountId: string): Promise<any> {
async emergencyClose(accountId: string): Promise<EmergencyCloseResponse> {
const response = await api.post(`/accounts/${accountId}/emergency-close`, {});
return response.json();
return (await response.json()) as EmergencyCloseResponse;
},

async getPlatformTradingStatus(): Promise<PlatformTradingStatus> {
Expand Down
Loading