From 81c11f2a978841ff193e9a44a3d8d589938a5fa1 Mon Sep 17 00:00:00 2001 From: "XM-VLADIN\\vladimir.nattis_xmcy" Date: Sat, 5 Feb 2022 14:53:54 +0200 Subject: [PATCH] Don't sell if cramer would sell --- functions/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/functions/index.js b/functions/index.js index a47dabc..04d147b 100644 --- a/functions/index.js +++ b/functions/index.js @@ -68,7 +68,10 @@ exports.getRichQuick = functions const stocksToBuy = gptCompletion.data.choices[0].text.match(/\b[A-Z]+\b/g); console.log(`Thanks for the tips Jim! ${stocksToBuy}`); - if (!stocksToBuy) { + const holdingStonk = await alpaca.getPositions().at(0).symbol; // assuming there's only 1 open position + const shouldTradeToday = !(stocksToBuy.includes(holdingStonk)); + + if (!stocksToBuy || !shouldTradeToday) { console.log('sitting this one out'); return null; }