Skip to content

How the script works

Manu Masson edited this page Jul 9, 2017 · 1 revision
  • Fetching and computing JSON from markets APIs'

    The script requests as many APIs as there are in the settings.js, in parallel. Once the JSON is available for any market, its last() method is called, which loops through the JSON and gets the last price of every coin available, adding those results to the global object coin_prices. As soon as there as been a response from at least 2 markets the function computePrices(coin_prices) is called, which finds the highest difference in price between markets for each coin, and adds that to an array which sorted from lowest to highest difference in price, and finally is sent to the browser via websockets. Every time a new market loads the function is called again, sending the updated results to the browser. This whole process is repeated every 10s (requests and computes the JSON again) and the browser automatically updates the frontend every time because of the magic which is websockets!

Clone this wiki locally