feat: paper trading capital controls — add, withdraw, and full reset
Three distinct capital operations on the Trading Controls page: - Set Capital: overwrites pool balances to a new amount (existing) - Add/Withdraw: adjusts active pool by a delta without touching positions, orders, or history. Validates sufficient balance for withdrawals. Logged to reserve_pool_ledger as manual_adjustment. - Reset Everything: nuclear option — deletes all positions, orders, trading decisions, stop levels, snapshots, backtests, notifications, and circuit breaker events, then resets capital fresh. Red button with double-confirmation dialog. Backend: POST /api/trading/capital/adjust and POST /api/trading/reset Frontend: CapitalCard rebuilt with three sections and confirmation UIs
This commit is contained in:
@@ -309,6 +309,38 @@ export function useBacktestLaunch() {
|
||||
});
|
||||
}
|
||||
|
||||
/** Full paper trading reset: clears all positions, orders, decisions, and resets capital. */
|
||||
export function useResetPaperTrading() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (initial_capital: number) =>
|
||||
apiPost<{ reset: boolean; initial_capital: number; active_pool: number; reserve_pool: number }>(
|
||||
'trading', '/api/trading/reset', { initial_capital },
|
||||
),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['trading-status'] });
|
||||
qc.invalidateQueries({ queryKey: ['trading-decisions'] });
|
||||
qc.invalidateQueries({ queryKey: ['trading-metrics'] });
|
||||
qc.invalidateQueries({ queryKey: ['trading-metrics-history'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** 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