UNPKG

candlestick-chart-generator

Version:

A Node.js library for generating candlestick chart screenshots using financial data

83 lines (74 loc) 2.24 kB
const CandlestickChartGenerator = require('../index'); async function generateAaplAllTimeframes() { const generator = new CandlestickChartGenerator(); try { console.log('=== AAPL - All Timeframes ==='); const endDate = new Date(); const baseOutput = 'examples/aapl'; const timeframes = [ { label: '5m (Intraday) ~1 session', interval: '5m', output: `${baseOutput}_5m_intraday.png`, desiredBars: 240, includePrePost: false, }, { label: '1h (~35 calendar days for stocks)', interval: '1h', output: `${baseOutput}_1h_chart.png`, desiredBars: 160, includePrePost: false, }, { label: '4h (~6 months)', interval: '4h', output: `${baseOutput}_4h_chart.png`, desiredBars: 200, includePrePost: false, }, { label: '1d (~6 months)', interval: '1d', output: `${baseOutput}_1d_chart.png`, desiredBars: 180, includePrePost: false, }, { label: '1wk (2 years explicit)', interval: '1wk', output: `${baseOutput}_1wk_chart.png`, startDate: new Date(Date.now() - 2 * 365 * 24 * 60 * 60 * 1000), includePrePost: false, }, ]; for (const tf of timeframes) { try { const params = { symbol: 'AAPL', interval: tf.interval, endDate, outputPath: tf.output, width: 2400, height: 1600, includePrePost: tf.includePrePost, }; if (tf.startDate) params.startDate = tf.startDate; if (tf.desiredBars) params.desiredBars = tf.desiredBars; console.log(`Generating AAPL ${tf.label}...`); await generator.generateChartScreenshot(params); console.log(` ✅ Saved: ${tf.output}`); } catch (err) { console.error(` ❌ Failed ${tf.label}: ${err.message}`); } } } catch (error) { console.error('❌ AAPL all timeframes error:', error.message); } finally { await generator.close(); } } if (require.main === module) { generateAaplAllTimeframes().catch(console.error); } module.exports = { generateAaplAllTimeframes };