UNPKG

candlestick-chart-generator

Version:

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

76 lines (67 loc) 2.71 kB
const CandlestickChartGenerator = require('../index'); async function runExamples() { const generator = new CandlestickChartGenerator(); try { console.log('=== Candlestick Chart Generator Examples ===\n'); // Example 1: AAPL Daily Chart console.log('1. Generating AAPL daily chart...'); await generator.generateChartScreenshot({ symbol: 'AAPL', interval: '1d', startDate: '2023-01-01', endDate: '2023-12-31', outputPath: 'examples/aapl_daily_chart.png', width: 1000, height: 500 }); console.log('✅ AAPL daily chart saved to examples/aapl_daily_chart.png\n'); // Example 2: BTC-USD Hourly Chart with Custom Styling console.log('2. Generating BTC-USD hourly chart with custom styling...'); const oneWeekAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000); await generator.generateChartScreenshot({ symbol: 'BTC-USD', interval: '1h', startDate: oneWeekAgo, endDate: new Date(), outputPath: 'examples/btc_hourly_chart.png', width: 1200, height: 600, chartOptions: { backgroundColor: '#000000' } }); console.log('✅ BTC-USD hourly chart saved to examples/btc_hourly_chart.png\n'); // Example 3: EURUSD 1-minute Chart console.log('3. Generating EURUSD 1-minute chart...'); const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000); await generator.generateChartScreenshot({ symbol: 'EURUSD=X', interval: '1m', startDate: oneDayAgo, endDate: new Date(), outputPath: 'examples/eurusd_1m_chart.png', width: 1200, height: 600 }); console.log('✅ EURUSD 1-minute chart saved to examples/eurusd_1m_chart.png\n'); // Example 4: Generate chart as base64 data console.log('4. Generating chart as base64 data...'); const base64Data = await generator.generateChartBase64({ symbol: 'TSLA', interval: '1d', startDate: '2023-06-01', endDate: '2023-12-31', width: 800, height: 400 }); console.log(`✅ TSLA chart generated as base64 (${base64Data.length} characters)\n`); console.log('🎉 All examples completed successfully!'); } catch (error) { console.error('❌ Error:', error.message); } finally { // Always close the generator to free resources await generator.close(); } } // Run the examples runExamples();