Guest User

Untitled

a guest
Aug 29th, 2023
1,831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36";
  2.  
  3. function _jsonGet(url) {
  4.   let response = UrlFetchApp.fetch(url, {
  5.     "headers": {
  6.       "User-Agent": UA
  7.     },
  8.     "muteHttpExceptions": true
  9.   });
  10.   let status = response.getResponseCode();
  11.   Logger.log(`Url: ${url} status=${status}`);
  12.  
  13.   if (status !== 200) {
  14.     return null;
  15.   } else {
  16.     var rsp = response.getContentText();
  17.     return JSON.parse(rsp);
  18.   }
  19. }
  20. function getBisqPrice(a, b) {
  21.   const Day = 60 * 60 * 24;
  22.   let now = new Date().getTime() / 1000.0;
  23.   let today = now - (now % Day);
  24.  
  25.   let json = _jsonGet(`https://bisq.markets/api/hloc?market=${a.toLowerCase()}_${b.toLowerCase()}&interval=day&timestamp_from=${today}`);
  26.   if (json !== null) {
  27.     return json[0].avg;
  28.   } else {
  29.     return -0.0;
  30.   }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment