initial symbols done, not liking the outcome, gonna switch to queue based approach
This commit is contained in:
parent
174346ea2f
commit
0cf0b315df
3 changed files with 27 additions and 4 deletions
|
|
@ -157,7 +157,7 @@ export async function fetchExchanges(sessionHeaders: Record<string, string>): Pr
|
||||||
|
|
||||||
logger.info('Saving IB exchanges to MongoDB...');
|
logger.info('Saving IB exchanges to MongoDB...');
|
||||||
const client = getMongoDBClient();
|
const client = getMongoDBClient();
|
||||||
await client.batchUpsert('ib_exchanges', exchanges, ['id', 'country_code']);
|
await client.batchUpsert('ibExchanges', exchanges, ['id', 'country_code']);
|
||||||
logger.info('✅ Exchange IB data saved to MongoDB:', {
|
logger.info('✅ Exchange IB data saved to MongoDB:', {
|
||||||
count: exchanges.length,
|
count: exchanges.length,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,10 @@ export function initializeQMProvider() {
|
||||||
type: 'search-symbols',
|
type: 'search-symbols',
|
||||||
operation: 'search-symbols',
|
operation: 'search-symbols',
|
||||||
payload: {},
|
payload: {},
|
||||||
cronPattern: '*/1 * * * *', // Every minute
|
cronPattern: '0 0 * * 0', // Every minute
|
||||||
priority: 10,
|
priority: 10,
|
||||||
immediately: false,
|
immediately: true,
|
||||||
|
delay: 100000, // Delay to allow sessions to be ready
|
||||||
description: 'Comprehensive symbol search using QM API',
|
description: 'Comprehensive symbol search using QM API',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRandomUserAgent } from '@stock-bot/http';
|
import { getRandomUserAgent } from '@stock-bot/http';
|
||||||
import { getLogger } from '@stock-bot/logger';
|
import { getLogger } from '@stock-bot/logger';
|
||||||
|
import { getMongoDBClient } from '@stock-bot/mongodb-client';
|
||||||
import { SymbolSearchUtil } from '../utils/symbol-search.util';
|
import { SymbolSearchUtil } from '../utils/symbol-search.util';
|
||||||
import { getProxy } from './webshare.provider';
|
import { getProxy } from './webshare.provider';
|
||||||
|
|
||||||
|
|
@ -15,6 +16,7 @@ export interface QMSession {
|
||||||
failedCalls: number;
|
failedCalls: number;
|
||||||
lastUsed: Date;
|
lastUsed: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQmHeaders(): Record<string, string> {
|
function getQmHeaders(): Record<string, string> {
|
||||||
return {
|
return {
|
||||||
'User-Agent': getRandomUserAgent(),
|
'User-Agent': getRandomUserAgent(),
|
||||||
|
|
@ -71,7 +73,7 @@ export async function createSessions(): Promise<void> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (sessionCache[sessionId].length < 5) {
|
while (sessionCache[sessionId].length < 50) {
|
||||||
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) {
|
||||||
|
|
@ -151,11 +153,31 @@ async function searchQMSymbolsAPI(query: string): Promise<string[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const symbols = await response.json();
|
const symbols = await response.json();
|
||||||
|
const client = getMongoDBClient();
|
||||||
|
await client.batchUpsert('qmSymbols', symbols, ['symbol', 'exchange']);
|
||||||
|
const exchanges: any[] = [];
|
||||||
|
for (const symbol of symbols) {
|
||||||
|
if (!exchanges.some(ex => ex.exchange === symbol.exchange)) {
|
||||||
|
exchanges.push({
|
||||||
|
exchange: symbol.exchange,
|
||||||
|
exchangeCode: symbol.exchangeCode,
|
||||||
|
exchangeShortName: symbol.exchangeShortName,
|
||||||
|
countryCode: symbol.countryCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await client.batchUpsert('qmExchanges', exchanges, ['exchange']);
|
||||||
|
session.successfulCalls++;
|
||||||
|
session.lastUsed = new Date();
|
||||||
|
|
||||||
logger.info(`QM API returned ${symbols.length} symbols for query: ${query}`);
|
logger.info(`QM API returned ${symbols.length} symbols for query: ${query}`);
|
||||||
return symbols;
|
return symbols;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error searching QM symbols for query "${query}":`, error);
|
logger.error(`Error searching QM symbols for query "${query}":`, error);
|
||||||
|
if (session) {
|
||||||
|
session.failedCalls++;
|
||||||
|
session.lastUsed = new Date();
|
||||||
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue