News for hackers. Stuff that matters.
Re:Show HN: RandomCoin – A cryptocurrency that changes its p... by unlog on Saturday January 29, 2022 @10:19PM (#30133574)
Wrote a bot for it, very constructive experience.

Something that I didn't expect is that is not that easy as "buy low" and "sell high". I had to cap the buying price for the bot to make money at all, else the "bought at" will get so high, that you won't have a chance to buy much.

    let bougthAt = 0;

    let fn = { click: () => {} };
    let buy = document.querySelector("#buy");
    let sell = document.querySelector("#sell");

    (function work() {

      let founds = +document.querySelector("#funds-fiat").innerText;
      let coins = +document.querySelector("#funds-coin").innerText;
      let price = +document.querySelector("#price").innerText;

      if (founds > price && price < 5000) {
        fn = buy;
        bougthAt = price;
        console.log("bougthAt", bougthAt);
      } else if (price > bougthAt && coins > 0) {
        fn = sell;
        console.log("sellingAt", price);
      }
      fn.click();
      requestAnimationFrame(work);
    })();
Re:Show HN: RandomCoin – A cryptocurrency that changes its p... by mdrzn on Monday January 31, 2022 @04:51AM (#30146303)
OOC question regarding console scripts: unless it's specified by the code that the function will stop at a certain point, most functions like yours will loop forever. Is there a way to stop them, once pasted in the console, apart from refreshing the page? Is there no way to "stop" the loop of that specific function that was started? I googled around a bit but I think I'm out of my depth here.
Re:Show HN: RandomCoin – A cryptocurrency that changes its p... by unlog on Thursday February 03, 2022 @07:29AM (#30191598)
Yes, but you have to code for it. I guess you mean you want to "kill the process" in some way, and that's not possible as far as I know.

One easy way is to add a flag

        let working = true;
        (function work() {
          console.log("running");
          if (working) requestAnimationFrame(work);
          else console.log("stopped");
        })();
Programmatically, you have the function cancelAnimationFrame that you give as parameter what requestAnimationFrame returns. The same as setTimeout and clearTimeout
Re:Show HN: RandomCoin – A cryptocurrency that changes its p... by 2Gkashmiri on Sunday January 30, 2022 @12:20AM (#30134292)
also, why not set the buy to a "below 2000" and sell at "above 7000". ?
Re:Show HN: RandomCoin – A cryptocurrency that changes its p... by 2Gkashmiri on Sunday January 30, 2022 @12:18AM (#30134282)
are you not "mining" at this point?