Add max_position_size to account configs
- DB migration: ALTER TABLE account_configs ADD COLUMN max_position_size INTEGER NOT NULL DEFAULT 0 - Added max_position_size to AccountConfigRow, createAccountConfig, updateAccountConfig in lib/db.ts - Added maxPositionSize to AccountConfig type in types.ts (0 = no limit) - GET /api/firms/[id] now returns maxPositionSize per account - POST /api/firms/[id]/accounts and PUT /api/account-configs/[id] accept maxPositionSize - Firm settings page: new Max Contracts column (blank = no limit) - auto-trade: contracts capped at maxPositionSize when > 0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
b2a1bdd1c3
commit
49580c6bb4
+3
-1
@@ -41,6 +41,7 @@ function mapFirmConfig(firm: FirmWithAccounts): FirmConfig {
|
||||
minTradingDays: a.min_trading_days,
|
||||
accountSize: a.account_size,
|
||||
maxLoss: a.max_loss,
|
||||
maxPositionSize: a.max_position_size,
|
||||
})),
|
||||
};
|
||||
}
|
||||
@@ -124,7 +125,8 @@ export async function runTrade(action: 'Buy' | 'Sell', symbol: string) {
|
||||
const totalProfit = dailyPnL.reduce((sum, d) => sum + d.pnl, 0);
|
||||
const target = computeDailyTarget(cfg.profitTarget, cfg.consistency, totalProfit, dailyPnL);
|
||||
|
||||
const contracts = Math.max(1, Math.ceil(target.amount / 1000));
|
||||
const rawContracts = Math.max(1, Math.ceil(target.amount / 1000));
|
||||
const contracts = cfg.maxPositionSize > 0 ? Math.min(rawContracts, cfg.maxPositionSize) : rawContracts;
|
||||
const fill = await client.sendOrder(acc.id, contract.name, contracts, action, 'Market');
|
||||
|
||||
// Wait briefly for the cash balance WebSocket update to reflect entry commission
|
||||
|
||||
Reference in New Issue
Block a user