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

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

    try {
        console.log('Testing Crypto BTCUSD...');
        const bars = alpaca.getBarsV2('BTCUSD', {
            timeframe: '1Min',
            limit: 1,
            start: new Date(Date.now() - 3600000 * 24).toISOString()
        });
        for await (const b of bars) {
            console.log('Got Crypto Bar!');
        }
        console.log('Success with Crypto BTCUSD!');
    } catch (e: any) {
        console.error('Test Failed:', e.message, 'Code:', e.code);
    }
}

test();
