Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Or for people who want to make money as a trader.

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



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: