got symbols and exchanges working with sessions

This commit is contained in:
Boki 2025-06-16 22:19:56 -04:00
parent f05d26d703
commit 174346ea2f

View file

@ -60,11 +60,18 @@ export async function createSessions(): Promise<void> {
} }
logger.info('Creating QM sessions...'); logger.info('Creating QM sessions...');
for (const [sessionId, sessionArray] of Object.entries(sessionCache)) { for (const [sessionId, sessionArray] of Object.entries(sessionCache)) {
// remove any sessions with failedCalls > 10 const initialCount = sessionArray.length;
// const filteredArray = sessionArray.filter(session => session.failedCalls <= 10); const filteredArray = sessionArray.filter(session => session.failedCalls <= 10);
// sessionCache[sessionId] = filteredArray; sessionCache[sessionId] = filteredArray;
// if sessionArray is empty or has less than 5 sessions, create a new session
while (sessionArray.length < 2) { const removedCount = initialCount - filteredArray.length;
if (removedCount > 0) {
logger.info(
`Removed ${removedCount} sessions with excessive failures for ${sessionId}. Remaining: ${filteredArray.length}`
);
}
while (sessionCache[sessionId].length < 5) {
logger.info(`Creating new session for ${sessionId}`); logger.info(`Creating new session for ${sessionId}`);
const proxy = getProxy(); const proxy = getProxy();
if (proxy === null) { if (proxy === null) {
@ -103,10 +110,10 @@ export async function createSessions(): Promise<void> {
logger.info('QM session created successfully', { logger.info('QM session created successfully', {
sessionId, sessionId,
sessionData, sessionData,
sessionCount: sessionCache[sessionId].length + 1,
}); });
newSession.headers['Datatool-Token'] = sessionData.token; newSession.headers['Datatool-Token'] = sessionData.token;
console.log(newSession.headers); sessionCache[sessionId].push(newSession);
sessionArray.push(newSession);
} }
} }
return undefined; return undefined;