import Alpaca from '@alpacahq/alpaca-trade-api';
import * as dotenv from 'dotenv';
dotenv.config();

const alpaca = new (Alpaca as any)({
    keyId: process.env.ALPACA_API_KEY,
    secretKey: process.env.ALPACA_API_SECRET,
    paper: true,
});

async function run() {
    console.log('Testing BTC/USD (arrayMap)...');
    try {
        const barsMap = await alpaca.getCryptoBars(['BTC/USD'], {
            timeframe: '1Min',
            start: new Date(Date.now() - 3600000).toISOString(),
            limit: 5
        });
        console.log('BarsMap keys:', Object.keys(barsMap));
        const bars = barsMap['BTC/USD'] || [];
        console.log(`Got ${bars.length} bars!`);
    } catch (e: any) {
        console.log('Error:', e.message);
    }
}
run();
