29 lines
805 B
TypeScript
29 lines
805 B
TypeScript
import Alpaca from '@alpacahq/alpaca-trade-api';
|
|
|
|
const alpaca = new (Alpaca as any)({
|
|
keyId: 'PKTHEUUYVGMCWDLAREMD2YXNOV',
|
|
secretKey: 'eVi9LZQ1rKx4yy9ExbtLt2fCMWAMujJfapyv9RHnixK',
|
|
paper: true,
|
|
});
|
|
|
|
async function run() {
|
|
const symbol = 'BTCUSD';
|
|
console.log(`Testing ${symbol} with getBarsV2 and feed: us...`);
|
|
try {
|
|
const bars = alpaca.getBarsV2(symbol, {
|
|
timeframe: '1Min',
|
|
start: new Date(Date.now() - 3600000 * 24).toISOString(),
|
|
limit: 5,
|
|
feed: 'us'
|
|
});
|
|
let count = 0;
|
|
for await (const b of bars) {
|
|
count++;
|
|
}
|
|
console.log(`Finished. Found ${count} bars.`);
|
|
} catch (e: any) {
|
|
console.log('FAILED:', e.message);
|
|
}
|
|
}
|
|
run();
|