diff --git a/src/index.ts b/src/index.ts index dc16c06..31a9ec7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,30 +20,36 @@ async function waitForNextOpen() { } function wait(ms :number) { return new Promise((resolve) => { - console.log('would wait: ' + ms + 'ms'); - resolve('') - //setTimeout(resolve, ms); + //console.log('would wait: ' + ms + 'ms'); + //resolve('') + setTimeout(resolve, ms); }); } async function runDay() { await waitForNextOpen(); - console.log('run the day'); - await printAsset('AAPL'); - await printAsset('TQQQ'); - await printAsset('SQQQ'); - console.log(await accountBalance()); - let stocks = [ - 'AAPL', - 'TQQQ', - 'SQQQ' - ] - console.log(await alpaca.getLatestTrades(stocks)) - //console.log(await alpaca.getLatestQuote('AAPL')); + await wait(1000); //wait a miniute + + const q = await alpaca.getLatestQuote('TQQQ'); + await wait(1000); + + const q2 = await alpaca.getLatestQuote('TQQQ'); + + if (q2.ap - q.ap > 0) { + //up day + console.log('up day: ', new Date()) + } + else { + //down day + console.log('down day', new Date()); + } } async function main() { - await runDay(); + while(true) { + await runDay(); + await wait(1000 * 60 * 60);//wait an hour before going and getting the next open + } }