const lastPriceElement = document.querySelector('.last-price'); const buyButton = document.querySelector('.stock-btn.stock-buy'); const sellButton = document.querySelector('.stock-btn.stock-sell');
const buyPrice = 280; const sellPrice = 320;
function checkPriceAndTrade() {
if (lastPriceElement && buyButton && sellButton) { // Get the price text and convert to number const priceText = lastPriceElement.firstChild.textContent.trim(); const price = Number(priceText.replace(/[$,]/g, '')); // Execute trade based on price if (price < buyPrice) { console.log(`Price ${price} is below $` + buyPrice ` - Executing buy`); buyButton.click(); } else if (price > sellPrice) { console.log(`Price ${price} is above $` + sellPrice ` - Executing sell`); sellButton.click(); } else { console.log(`Price ${price} is between thresholds - No action taken`); } }
// Run the check every 20 milliseconds setInterval(checkPriceAndTrade, 20);
const lastPriceElement = document.querySelector('.last-price'); const buyButton = document.querySelector('.stock-btn.stock-buy'); const sellButton = document.querySelector('.stock-btn.stock-sell');
const buyPrice = 280; const sellPrice = 320;
function checkPriceAndTrade() {
}// Run the check every 20 milliseconds setInterval(checkPriceAndTrade, 20);