market.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // src/market.ts
  2. async function fetchData() {
  3. const exchanges = await fetch("https://api.prunplanner.org/data/exchanges");
  4. return await exchanges.json();
  5. }
  6. function render(prices) {
  7. const markets = [];
  8. for (const price of prices) {
  9. if (price.ExchangeCode !== "IC1" || price.Traded < 100)
  10. continue;
  11. const spread = (price.Ask - price.Bid) / price.Ask;
  12. if (spread < 0.15)
  13. continue;
  14. markets.push({ material: price.MaterialTicker, bid: price.Bid, ask: price.Ask, spread, traded: price.Traded });
  15. }
  16. markets.sort((a, b) => b.spread - a.spread);
  17. const fmt = new Intl.NumberFormat(undefined, { maximumFractionDigits: 2 });
  18. const tbody = document.querySelector("tbody");
  19. tbody.innerHTML = "";
  20. for (const market of markets) {
  21. const row = document.createElement("tr");
  22. row.innerHTML = `
  23. <td>${market.material}</td>
  24. <td>${fmt.format(market.bid)}</td>
  25. <td>${fmt.format(market.ask)}</td>
  26. <td>${fmt.format(market.spread)}</td>
  27. <td>${fmt.format(market.traded)}</td>
  28. `;
  29. tbody.appendChild(row);
  30. }
  31. }
  32. fetchData().then(render);
  33. //# debugId=BED9426CD318F82764756E2164756E21