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());
}

