Remove broker session rest

Reverts 062ec07 and 5eb0ea7: every firm's broker session stays logged in
around the clock again, renewing its token on the fixed timer as before.
The tree is back to 6dd2528's. A session_rest row left in settings is
unused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Li
2026-10-21 23:39:53 -05:00
co-authored by Claude Opus 5.5
parent 062ec07f0a
commit 5ec5abde6e
19 changed files with 43 additions and 901 deletions
+1 -6
View File
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from 'next/server';
import { getCachedFirm } from '@/lib/firm-catalog';
import { firmInstruments, isFuturesFirm } from '@/lib/instruments';
import { getClients, isWaking, wakeFirm } from '@/lib/clients';
import { getClients } from '@/lib/clients';
export async function POST(
req: NextRequest,
@@ -27,11 +27,6 @@ export async function POST(
const clients = getClients();
const client = clients.get(firmId);
if (!client) return NextResponse.json({ error: 'Client not found for firm' }, { status: 404 });
// A resting session (lib/clients.ts) holds no login: start one, and
// let the caller come back once it's up.
if (wakeFirm(firmId, 'manual order') || isWaking(firmId)) {
return NextResponse.json({ error: "the firm's session is logging back in — try again in a minute" }, { status: 503 });
}
// A futures firm trades only what its instrument list (master Firms
// page) names.
+5 -11
View File
@@ -1,7 +1,7 @@
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { NextResponse } from 'next/server';
import { getClients, isWaking, sessionRestEnabled, sessionRestInfo } from '@/lib/clients';
import { getClients } from '@/lib/clients';
import { getTradableFirms } from '@/lib/firm-catalog';
import { getSchedulerHealth, getSchedulerStatus } from '@/lib/auto-trade';
import { getBuildVersion } from '@/lib/version';
@@ -41,26 +41,20 @@ export async function GET() {
const entries = getTradableFirms().map((firm) => {
const base = { firmId: firm.id, firm: firm.name, platform: firm.platform };
const client = clients.get(firm.id);
if (!client) return { ...base, hasClient: false, ready: false, resting: null, waking: false, accounts: 0 };
if (!client) return { ...base, hasClient: false, ready: false, accounts: 0 };
const ready = isClientReady(client, now);
const accounts = client.accountList.length;
// Logged out on purpose while nothing needs it (lib/clients.ts):
// not ready, and nothing wrong. Nor is logging back in after it,
// within its grace — a login that fails stays not ready past that.
const resting = sessionRestInfo(firm.id);
const waking = isWaking(firm.id, now);
try {
return { ...base, hasClient: true, ready, resting, waking, accounts, ...client.health() };
return { ...base, hasClient: true, ready, accounts, ...client.health() };
} catch (err) {
// One client's broken health() must not hide the rest.
return { ...base, hasClient: true, ready, resting, waking, accounts, healthError: errorMessage(err) };
return { ...base, hasClient: true, ready, accounts, healthError: errorMessage(err) };
}
});
return NextResponse.json({
ok: entries.every((e) => !e.hasClient || e.ready || !!e.resting || e.waking),
sessionRest: sessionRestEnabled(),
ok: entries.every((e) => !e.hasClient || e.ready),
now,
uptimeSec: Math.round(process.uptime()),
version: getBuildVersion(),
+1 -1
View File
@@ -3,7 +3,7 @@ import { getSetting, setSetting } from '@/lib/db';
import { scheduleBackupPush } from '@/lib/backup-sync';
import { getRequestUserAgent } from '@/lib/request-user-agent';
const VALID_KEYS = ['max_concurrent_accounts', 'tick_interval_seconds', 'master_dashboard_url', 'instance_name', 'trading_hours', 'twocaptcha_api_key', 'twocaptcha_proxy', 'master_backup_token', 'proxy_url', 'session_rest'] as const;
const VALID_KEYS = ['max_concurrent_accounts', 'tick_interval_seconds', 'master_dashboard_url', 'instance_name', 'trading_hours', 'twocaptcha_api_key', 'twocaptcha_proxy', 'master_backup_token', 'proxy_url'] as const;
type SettingKey = typeof VALID_KEYS[number];
export async function GET() {
+3 -5
View File
@@ -1,6 +1,6 @@
import { NextResponse } from 'next/server';
import { listAssignments, loadDailyPnL } from '@/lib/db';
import { getClients, restingWakeAt, sessionRestInfo } from '@/lib/clients';
import { getClients } 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,10 +27,8 @@ 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, ...resting, accounts: [] };
return { firmId: f.id, firm: f.name, connected, accounts: [] };
}
// Accounts whose rules date was set by hand — one read per firm
// rather than one per account.
@@ -316,7 +314,7 @@ export async function GET() {
keptRules,
};
});
return { firmId: f.id, firm: f.name, connected, ...resting, accounts };
return { firmId: f.id, firm: f.name, connected, accounts };
});
return NextResponse.json(state);