diff options
Diffstat (limited to 'screener.js')
-rw-r--r-- | screener.js | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/screener.js b/screener.js index 9fb0762..85e6183 100644 --- a/screener.js +++ b/screener.js @@ -1,7 +1,4 @@ -const { parse } = require('node:path'); -const { default: test } = require('node:test'); - -fs = require('node:fs'); +import fs from 'fs'; // this gets the HTML page of the SP500 list from slickcharts.com const getSPHTML = async () => { @@ -41,7 +38,7 @@ const parseHTMLToTickers = (html) => { fs.unlinkSync('sp500_tickers.json'); } fs.writeFileSync('sp500_tickers.json', JSON.stringify(tickers, null, 2)); - console.log(`Saved ${tickers.length} tickers to sp500_tickers.json`); + // console.log(`Saved ${tickers.length} tickers to sp500_tickers.json`); return tickers; } @@ -157,8 +154,8 @@ const formatDataFromHistories = (histories) => { const macd = calculateMACD(prices); // print first 5 timestamps and prices for debugging - console.log('First 5 timestamps:', timestamps.slice(0, 5).map(ts => new Date(ts * 1000).toLocaleDateString())); - console.log('First 5 prices:', prices.slice(0, 5)); + // console.log('First 5 timestamps:', timestamps.slice(0, 5).map(ts => new Date(ts * 1000).toLocaleDateString())); + // console.log('First 5 prices:', prices.slice(0, 5)); const currentPrice = prices[prices.length - 1]; // Directly calculate the percentage changes for 1W, 1M, 3M, and 6M\ @@ -198,7 +195,7 @@ const formatDataFromHistories = (histories) => { fs.unlinkSync('sp500_formatted_data.tsv'); } fs.writeFileSync('sp500_formatted_data.tsv', csvContent); - console.log('Formatted data saved to sp500_formatted_data.tsv'); + // console.log('Formatted data saved to sp500_formatted_data.tsv'); return csv_final; }; // testGetHistories(); @@ -263,7 +260,7 @@ const calculateRSI = (prices, period = 14) => { } const RSIs = [firstRSI]; - console.log(`Initial RSI for the first ${period} data points: ${firstRSI}`); + // `Initial RSI for the first ${period} data points: ${firstRSI}`); // Calculate the RSI for the rest of the data points let previousAverageGain = averageGain; @@ -327,7 +324,7 @@ const testGetSector = async () => { }); } -const main = async () => { +export const runScreener = async () => { try { // gt the test histories from the file // const histories = fs.readFileSync('sp500_histories.json', 'utf8'); @@ -340,20 +337,17 @@ const main = async () => { console.error('No tickers found. Please ensure sp500_tickers.json exists and is populated.'); return; } - console.log(`Found ${tickers.length} tickers in sp500_tickers.json`); + // console.log(`Found ${tickers.length} tickers in sp500_tickers.json`); // get histories for each symbol const parsedHistories = await getHistoriesForEachTicker(tickers); - console.log(`Fetched histories for ${parsedHistories.length} symbols.`); + // console.log(`Fetched histories for ${parsedHistories.length} symbols.`); // format the data from the histories const formattedData = formatDataFromHistories(parsedHistories); - console.log('Formatted data:', formattedData.slice(0, 5)); // Print first 5 entries for brevity + // console.log('Formatted data:', formattedData.slice(0, 5)); // Print first 5 entries for brevity } catch (error) { console.error('Error in main function:', error); } } - -main(); - |