Bot validates strategy capital allocations, waits for market open, runs all strategies concurrently, and passes signals to the executor. The main loop in index.ts now delegates to Bot.runDay(). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
27 lines
725 B
TypeScript
27 lines
725 B
TypeScript
import { Alpaca } from "./alpaca";
|
|
|
|
export function wait(ms: number) {
|
|
return new Promise((resolve) => {
|
|
setTimeout(resolve, ms);
|
|
});
|
|
}
|
|
|
|
export async function printAsset(alpaca: Alpaca, symbol: string) {
|
|
const asset = await alpaca.getAsset(symbol);
|
|
if (asset && asset.fractionable)
|
|
console.log(symbol + ' is fractional')
|
|
else
|
|
console.log(symbol + ' is not fractional')
|
|
}
|
|
|
|
export async function accountBalance(alpaca: Alpaca) {
|
|
const account = await alpaca.getAccount();
|
|
return account.cash;
|
|
}
|
|
|
|
export async function waitForNextOpen(alpaca: Alpaca) {
|
|
const clock = await alpaca.getClock();
|
|
return wait(new Date(clock.next_open).valueOf() - new Date().valueOf());
|
|
}
|
|
|