Refresh dailyPnL on a fixed hourly interval instead of throttling
- Replace the reactive throttle with a proactive setInterval in requestSync that fires fetchDaysTraded exactly once per hour per client - Remove post-fill fetchDaysTraded calls from auto-trade.ts — no longer needed and were causing bursts of report API requests on simultaneous fills - Guard against duplicate intervals if requestSync fires more than once Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
92b929f4ce
commit
d0065ab047
@@ -180,11 +180,6 @@ export async function runTrade(action: 'Buy' | 'Sell' | 'Random', symbol: string
|
||||
const exitAction: 'Buy' | 'Sell' = resolvedAction === 'Buy' ? 'Sell' : 'Buy';
|
||||
const exitFill = await client.sendOrder(acc.id, mnqContract.name, 1, exitAction, 'Market');
|
||||
|
||||
// Refresh daily P&L immediately after the extra-day round-trip completes
|
||||
client.fetchDaysTraded().catch((err) =>
|
||||
console.error('[auto-trade] post-fill fetchDaysTraded error:', err)
|
||||
);
|
||||
|
||||
console.log(`[auto-trade] ${acc.name} (${item.firmName}) extra-day: ${resolvedAction} 1xMNQ @ ${fill.price} | exited @ ${exitFill.price} (market)`);
|
||||
|
||||
return {
|
||||
@@ -226,15 +221,6 @@ export async function runTrade(action: 'Buy' | 'Sell' | 'Random', symbol: string
|
||||
const exitAction: 'Buy' | 'Sell' = resolvedAction === 'Buy' ? 'Sell' : 'Buy';
|
||||
const exitOrder = await client.placeOrderNoWait(acc.id, contract.name, contracts, exitAction, 'Limit', exitPrice);
|
||||
|
||||
// Refresh daily P&L as soon as the exit limit order fills
|
||||
if (exitOrder.orderId != null) {
|
||||
client.onFill(exitOrder.orderId, () => {
|
||||
client.fetchDaysTraded().catch((err) =>
|
||||
console.error('[auto-trade] post-fill fetchDaysTraded error:', err)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`[auto-trade] ${acc.name} (${item.firmName}) ${resolvedAction} ${contracts}x${resolvedSymbol} @ ${fill.price} | target $${target.amount} [${target.path}] (+$${totalCommission.toFixed(2)} comm) | exit @ ${exitPrice} (orderId=${exitOrder.orderId})`);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user