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:
Senofy
2026-03-09 18:57:12 -05:00
co-authored by Claude Sonnet 4.6
parent 95e7433941
commit 570a54fe60
10 changed files with 218 additions and 66 deletions
+8 -3
View File
@@ -35,8 +35,8 @@ export function computeDailyTarget(
minDayPnL: number = 0, // -999 or 0 = no minimum per day
minTradingDays: number = 0 // 0 = no minimum trading days
): { amount: number; path: 'first_day' | 'normal_day' | 'reduced_day' } {
const positiveDays = dailyPnL.filter((d) => d.pnl > 0);
const daysTraded = positiveDays.length;
const qualifyingDays = minDayPnL === 0 ? dailyPnL : dailyPnL.filter((d) => d.pnl >= minDayPnL);
const daysTraded = qualifyingDays.length;
// --- Base target via consistency logic ---
let baseAmount: number;
@@ -45,8 +45,13 @@ export function computeDailyTarget(
if (daysTraded === 0) {
baseAmount = profitTarget * consistency;
path = 'first_day';
} else if (consistency === 0) {
// 0% consistency means no consistency rule to satisfy — base amount is always $0.
// The min-day reservation block below handles any mandatory-day targeting.
baseAmount = 0;
path = 'reduced_day';
} else {
const maxDay = Math.max(...positiveDays.map((d) => d.pnl));
const maxDay = Math.max(...qualifyingDays.map((d) => d.pnl));
const realTarget = maxDay / consistency;
const needed = realTarget - totalProfit;