Fix fetchDaysTraded to use reports API with bearer auth and correct daysTraded counting
- Replace fill/ldeps and fill/list approaches with Tradovate reports API - Add bearer auth to getreport polling (root cause of prior 404s) - Use endDate = tomorrow to ensure current-session fills are included - Count all traded days when minDayPnL is 0, otherwise count days >= minDayPnL - Add PATCH /api/debug endpoint for proxying raw Tradovate API calls Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
95e7433941
commit
570a54fe60
@@ -163,6 +163,11 @@ export async function runTrade(action: 'Buy' | 'Sell', symbol: string) {
|
||||
const exitAction: 'Buy' | 'Sell' = action === '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: ${action} 1xMNQ @ ${fill.price} | exited @ ${exitFill.price} (market)`);
|
||||
|
||||
return {
|
||||
@@ -204,6 +209,15 @@ export async function runTrade(action: 'Buy' | 'Sell', symbol: string) {
|
||||
const exitAction: 'Buy' | 'Sell' = action === '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}) ${action} ${contracts}x${symbol} @ ${fill.price} | target $${target.amount} [${target.path}] (+$${totalCommission.toFixed(2)} comm) | exit @ ${exitPrice} (orderId=${exitOrder.orderId})`);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user