candlestick-chart-generator
Version:
A Node.js library for generating candlestick chart screenshots using financial data
92 lines (80 loc) • 3.35 kB
JavaScript
const CandlestickChartGeneratorSimple = require('../index_simple');
async function testSimpleCanvasCharts() {
const generator = new CandlestickChartGeneratorSimple();
try {
console.log('=== Testing Simple Canvas-based Candlestick Chart Generator ===\n');
// Test 1: AAPL Daily Chart
console.log('1. Generating AAPL daily chart with Simple Canvas...');
await generator.generateChartScreenshot({
symbol: 'AAPL',
interval: '1d',
startDate: '2023-01-01',
endDate: '2023-12-31',
outputPath: 'examples/aapl_daily_simple.png',
width: 1000,
height: 500
});
console.log('✅ AAPL daily chart saved to examples/aapl_daily_simple.png\n');
// Test 2: BTC-USD Hourly Chart
console.log('2. Generating BTC-USD hourly chart with Simple Canvas...');
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_simple.png',
width: 1200,
height: 600
});
console.log('✅ BTC-USD hourly chart saved to examples/btc_hourly_simple.png\n');
// Test 3: EURUSD 1-minute Chart
console.log('3. Generating EURUSD 1-minute chart with Simple Canvas...');
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_simple.png',
width: 1200,
height: 600
});
console.log('✅ EURUSD 1-minute chart saved to examples/eurusd_1m_simple.png\n');
// Test 4: Generate chart as base64 data
console.log('4. Generating chart as base64 data with Simple Canvas...');
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`);
// Test 5: Custom styling
console.log('5. Generating custom styled chart with Simple Canvas...');
await generator.generateChartScreenshot({
symbol: 'GOOGL',
interval: '1d',
startDate: '2023-06-01',
endDate: '2023-12-31',
outputPath: 'examples/googl_custom_simple.png',
width: 1200,
height: 600,
chartOptions: {
backgroundColor: '#000000'
}
});
console.log('✅ GOOGL custom styled chart saved to examples/googl_custom_simple.png\n');
console.log('🎉 All Simple Canvas chart tests completed successfully!');
} catch (error) {
console.error('❌ Error:', error.message);
console.error('Stack trace:', error.stack);
} finally {
// Clean up
await generator.close();
}
}
// Run the tests
testSimpleCanvasCharts();