Broker sessions rest while nothing needs them
A firm's client used to stay logged in around the clock, renewing on a fixed timer overnight and at weekends. Now, once a firm has nothing open, nothing pending and nothing left to trade before its next session for a random 15–45 minutes, its client disconnects and the dashboard shows it Resting. It logs back in a random 20–50 minutes before the next session opens, at a check-in every 3–7 Central daytime hours, or at once when trading starts, a manual leg, copy trade, manual order or AutoBuyer run needs it. Token renewals fall at random points (Tradovate 15–45 min before expiry, TopstepX every 45–150 min). Settings → Trading → Rest idle broker sessions (session_rest) turns it off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6dd2528fe2
commit
5eb0ea7760
@@ -1,6 +1,6 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { listAssignments, loadDailyPnL } from '@/lib/db';
|
||||
import { getClients } from '@/lib/clients';
|
||||
import { getClients, restingWakeAt, sessionRestInfo } from '@/lib/clients';
|
||||
import { getAccountTypeById, getCachedCatalog } from '@/lib/firm-catalog';
|
||||
import { ruleDiffs } from '@/lib/kept-rules';
|
||||
import { getAccountConfig, getInferredSize, matchAccountType } from '@/lib/account-type-resolver';
|
||||
@@ -27,8 +27,10 @@ export async function GET() {
|
||||
// A firm with no accounts is a real, settled state and must not be
|
||||
// reported the same way as one that is still authenticating.
|
||||
const connected = !!client && client.syncComplete;
|
||||
const rest = sessionRestInfo(f.id);
|
||||
const resting = rest ? { resting: { since: rest.since, wakeAt: restingWakeAt(f.id) } } : {};
|
||||
if (!client || client.accountList.length === 0) {
|
||||
return { firmId: f.id, firm: f.name, connected, accounts: [] };
|
||||
return { firmId: f.id, firm: f.name, connected, ...resting, accounts: [] };
|
||||
}
|
||||
// Accounts whose rules date was set by hand — one read per firm
|
||||
// rather than one per account.
|
||||
@@ -314,7 +316,7 @@ export async function GET() {
|
||||
keptRules,
|
||||
};
|
||||
});
|
||||
return { firmId: f.id, firm: f.name, connected, accounts };
|
||||
return { firmId: f.id, firm: f.name, connected, ...resting, accounts };
|
||||
});
|
||||
|
||||
return NextResponse.json(state);
|
||||
|
||||
Reference in New Issue
Block a user