fix: remove broken capital controls, reset now queries broker for real balance
- Removed PUT /api/trading/capital (set capital) — only touched in-memory state - Removed POST /api/trading/capital/adjust (add/withdraw) — same problem - Reset endpoint now: liquidates Alpaca positions, cancels orders, clears DB, then queries Alpaca for real portfolio_value to set engine capital - Frontend: replaced CapitalCard with simple ResetCard (one button) - Removed useSetTradingCapital and useAdjustCapital hooks
This commit is contained in:
@@ -426,15 +426,6 @@ export function useSetTradingMode() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useSetTradingCapital() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (initial_capital: number) =>
|
||||
apiPut<{ initial_capital: number; active_pool: number; reserve_pool: number }>('trading', '/api/trading/capital', { initial_capital }),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ['trading-config'] }),
|
||||
});
|
||||
}
|
||||
|
||||
export function usePendingApprovals() {
|
||||
return useGet<Approval[]>(['pending-approvals'], 'query', '/api/admin/trading/approvals');
|
||||
}
|
||||
|
||||
@@ -309,12 +309,13 @@ export function useBacktestLaunch() {
|
||||
});
|
||||
}
|
||||
|
||||
/** Full paper trading reset: clears all positions, orders, decisions, and resets capital. */
|
||||
/** Full paper trading reset: liquidates broker positions, cancels orders,
|
||||
* clears all local trading state, and syncs capital from the broker. */
|
||||
export function useResetPaperTrading() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (initial_capital: number) =>
|
||||
apiPost<{ reset: boolean; initial_capital: number; active_pool: number; reserve_pool: number }>(
|
||||
mutationFn: (initial_capital: number = 0) =>
|
||||
apiPost<{ reset: boolean; initial_capital: number; active_pool: number; reserve_pool: number; broker: Record<string, number> }>(
|
||||
'trading', '/api/trading/reset', { initial_capital },
|
||||
),
|
||||
onSuccess: () => {
|
||||
@@ -326,21 +327,6 @@ export function useResetPaperTrading() {
|
||||
});
|
||||
}
|
||||
|
||||
/** Add or subtract capital from the active pool without resetting anything else. */
|
||||
export function useAdjustCapital() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (amount: number) =>
|
||||
apiPost<{ adjusted: number; active_pool: number; reserve_pool: number; total_value: number }>(
|
||||
'trading', '/api/trading/capital/adjust', { amount },
|
||||
),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['trading-status'] });
|
||||
qc.invalidateQueries({ queryKey: ['trading-metrics'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** Update notification preferences. */
|
||||
export function useUpdateNotificationConfig() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
Reference in New Issue
Block a user