1async function makeGraphQLQuery(query) { 2 try { 3 const response = await fetch('https://kdswap-fd-prod-cpeabrdfgdg9hzen.z01.azurefd.net/graphql', { 4 method: 'POST', 5 headers: { 'Content-Type': 'application/json' }, 6 body: JSON.stringify({ 7 query: query 8 }) 9 }); 10 11 const responseData = await response.json(); 12 return responseData.data; 13 } catch (error) { 14 console.error('Error making GraphQL query:', error); 15 throw error; 16 } 17} 18 19function calculateDaysSince() { 20 const currentDate = new Date(); 21 const referenceDate = new Date('2022-07-14'); 22 const daysSince = Math.floor((currentDate - referenceDate) / (1000 * 60 * 60 * 24)); 23 return daysSince; 24} 25 26const query1H = `{ 27 price(token: "mok.token", period: 1) { 28 id 29 timestamp 30 priceInKda 31 intervalStamp 32 } 33}`; 34 35const queryDaysSince = `{ 36 price(token: "arkade.token", period: ${calculateDaysSince()}) { 37 id 38 timestamp 39 priceInKda 40 intervalStamp 41 } 42}`; 43 44async function fetchData() { 45 try { 46 const data1H = await makeGraphQLQuery(query1H); 47 const dataDaysSince = await makeGraphQLQuery(queryDaysSince); 48 49 // Fetch the current price from the 1-hour query 50 const currentPrice = parseFloat(data1H.price[0].priceInKda).toPrecision(4); 51 const FDMC = currentPrice * 500000000; 52 53 // Combine price data from both the 1-hour and daysSince queries 54 const combinedPriceData = data1H.price.concat(dataDaysSince.price); 55 56 let allTimeHigh = Number.MIN_VALUE; 57 let allTimeLow = Number.MAX_VALUE; 58 59 // Iterate over the combined price data to find the overall max and min 60 for (const priceData of combinedPriceData) { 61 const price = parseFloat(priceData.priceInKda); 62 allTimeHigh = Math.max(allTimeHigh, price); 63 allTimeLow = Math.min(allTimeLow, price); 64 } 65 66 allTimeHigh = allTimeHigh.toPrecision(4); 67 allTimeLow = allTimeLow.toPrecision(4); 68 69 document.getElementById("currentPrice").innerText = `${currentPrice} $KDA`; 70 document.getElementById("allTimeHigh").innerText = `${allTimeHigh} $KDA`; 71 document.getElementById("allTimeLow").innerText = `${allTimeLow} $KDA`; 72 document.getElementById("FDMC").innerText = `${parseFloat(FDMC).toLocaleString()} $KDA`; 73 } catch (error) { 74 console.error('Error fetching data:', error); 75 document.getElementById("currentPrice").innerText = "Error fetching current price"; 76 document.getElementById("allTimeHigh").innerText = "Error fetching all-time high"; 77 document.getElementById("allTimeLow").innerText = "Error fetching all-time low"; 78 } 79} 80 81fetchData();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.