From 0f95fa6d59a1b14f6dae6683d29fbd7080fa99f0 Mon Sep 17 00:00:00 2001 From: Kunal Bhatia Date: Mon, 11 May 2026 22:22:14 +0530 Subject: [PATCH 1/3] feat: add production-scan script and align API request format --- production-scan.ts | 33 +++++++++++++++++++++++++++++++++ tsconfig.json | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 production-scan.ts diff --git a/production-scan.ts b/production-scan.ts new file mode 100644 index 0000000..df4cead --- /dev/null +++ b/production-scan.ts @@ -0,0 +1,33 @@ +import { login } from './src/helpers/login.js'; +import { downloadScripMaster } from './src/helpers/scripMaster.js'; +import { runMorningScanner } from './src/jobs/morningScanner.js'; +import { logger } from './src/helpers/logger.js'; +import 'dotenv/config'; + +async function start(): Promise { + try { + console.log('\n--- ORB ALGO: PRODUCTION SCAN START ---'); + + // 1. Authenticate + await login(); + logger.info('Login successful'); + + // 2. Sync Scrip Master + await downloadScripMaster(); + logger.info('Scrip master synced'); + + // 3. Run Scanner + console.log('Running scanner with Batch API and dual-factor S/R logic...'); + await runMorningScanner(); + + console.log('--- PRODUCTION SCAN COMPLETE ---'); + process.exit(0); + } catch (error) { + logger.error( + `Production scan failed: ${error instanceof Error ? error.message : String(error)}`, + ); + process.exit(1); + } +} + +void start(); diff --git a/tsconfig.json b/tsconfig.json index ce645fb..8f4a726 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,5 +10,5 @@ "forceConsistentCasingInFileNames": true, "skipLibCheck": true }, - "include": ["src", "__tests__", "__mocks__", "jest.config.ts"] + "include": ["src", "__tests__", "__mocks__", "jest.config.ts", "production-scan.ts"] } From 2c23eaf15ab4a5beda9494fbfbec17794ca2e106 Mon Sep 17 00:00:00 2001 From: Kunal Bhatia Date: Mon, 11 May 2026 22:34:06 +0530 Subject: [PATCH 2/3] fix: move production-scan to src and fix build error --- production-scan.ts | 33 --------------------------------- tsconfig.json | 2 +- 2 files changed, 1 insertion(+), 34 deletions(-) delete mode 100644 production-scan.ts diff --git a/production-scan.ts b/production-scan.ts deleted file mode 100644 index df4cead..0000000 --- a/production-scan.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { login } from './src/helpers/login.js'; -import { downloadScripMaster } from './src/helpers/scripMaster.js'; -import { runMorningScanner } from './src/jobs/morningScanner.js'; -import { logger } from './src/helpers/logger.js'; -import 'dotenv/config'; - -async function start(): Promise { - try { - console.log('\n--- ORB ALGO: PRODUCTION SCAN START ---'); - - // 1. Authenticate - await login(); - logger.info('Login successful'); - - // 2. Sync Scrip Master - await downloadScripMaster(); - logger.info('Scrip master synced'); - - // 3. Run Scanner - console.log('Running scanner with Batch API and dual-factor S/R logic...'); - await runMorningScanner(); - - console.log('--- PRODUCTION SCAN COMPLETE ---'); - process.exit(0); - } catch (error) { - logger.error( - `Production scan failed: ${error instanceof Error ? error.message : String(error)}`, - ); - process.exit(1); - } -} - -void start(); diff --git a/tsconfig.json b/tsconfig.json index 8f4a726..ce645fb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,5 +10,5 @@ "forceConsistentCasingInFileNames": true, "skipLibCheck": true }, - "include": ["src", "__tests__", "__mocks__", "jest.config.ts", "production-scan.ts"] + "include": ["src", "__tests__", "__mocks__", "jest.config.ts"] } From fcee65b9d54037d3d8b0dd4bf399d595e95d948c Mon Sep 17 00:00:00 2001 From: Kunal Bhatia Date: Tue, 12 May 2026 12:19:50 +0530 Subject: [PATCH 3/3] fix: increase API delays and correct support sorting logic --- src/jobs/morningScanner.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/jobs/morningScanner.ts b/src/jobs/morningScanner.ts index 1150dad..45a1e8a 100644 --- a/src/jobs/morningScanner.ts +++ b/src/jobs/morningScanner.ts @@ -26,10 +26,13 @@ export async function runMorningScanner(): Promise { const watchList: WatchStock[] = []; for (const stock of gainers) { - await new Promise(resolve => setTimeout(resolve, 500)); + // Delay between stocks to respect rate limits + await new Promise(resolve => setTimeout(resolve, 2000)); + const chain = await getOptionChain(stock.name, expiry); const oiResistance = findResistance(chain, stock.ltp); + await new Promise(resolve => setTimeout(resolve, 500)); const morningCandles = await getMorningCandles(stock.symbolToken); const morningLevels = morningCandles.length > 0 @@ -40,6 +43,7 @@ export async function runMorningScanner(): Promise { : stock.ltp; // Historical Analysis (90 Days) + await new Promise(resolve => setTimeout(resolve, 500)); const histCandles = await getHistoricalData( stock.symbolToken, 'NSE', @@ -74,10 +78,13 @@ export async function runMorningScanner(): Promise { } for (const stock of losers) { - await new Promise(resolve => setTimeout(resolve, 500)); + // Delay between stocks to respect rate limits + await new Promise(resolve => setTimeout(resolve, 2000)); + const chain = await getOptionChain(stock.name, expiry); const oiSupport = findSupport(chain, stock.ltp); + await new Promise(resolve => setTimeout(resolve, 500)); const morningCandles = await getMorningCandles(stock.symbolToken); const morningLevels = morningCandles.length > 0 @@ -86,6 +93,7 @@ export async function runMorningScanner(): Promise { const candleSupport = morningLevels ? morningLevels.support : stock.ltp; // Historical Analysis (90 Days) + await new Promise(resolve => setTimeout(resolve, 500)); const histCandles = await getHistoricalData( stock.symbolToken, 'NSE',