Published
Edited
May 3, 2022
Insert cell
## LCDOT/DOT price RATIO on Acala
Insert cell
Insert cell
## LCDOT price vs DOT
Insert cell
Plot.plot({
style: "overflow: visible;",
y: {
grid: true,
label: "priceUSD",
type: "log",
title: () => "het"
},
marks: [
Plot.line(dataSet, {
x: "date",
y: "priceUSD",
z: "token",
stroke: 'token',
title: () => "het"
})
]
})
Insert cell
ratios = dataSet.filter(x=>x.ratio).map((r,i,ratios)=> ({
...r,
rollingAverageRatio: (() => {
if (i < 6) return 0
const ratiosLastWeek = []
for (let a of R.range(i-6, i+1)) {
ratiosLastWeek.push(ratios[a].ratio)
}
return d3.mean(ratiosLastWeek)
})()
}))

Insert cell
dataSet = [...pricesDOT, ...pricesLCDOT, ...ratio].map(x=> ({
...x,
date: new Date(x.date)
}))
Insert cell
ratio = pricesLCDOT.map(lcd => ({
date: lcd.date,
ratio: lcd.priceUSD / (pricesDOT.find(d => d.date === lcd.date)?.priceUSD),
}))
Insert cell
pricesDOT = dotUSD.map(x => ({
date: x.time_period_start.substring(0,10),
priceUSD: x.rate_close,
token: 'DOT'
}))
Insert cell
dotUSD = FileAttachment("dot-usd2.json").json()
Insert cell
pricesLCDOT = lcDotDays.map(x => ({
date: x.date.substring(0,10),
priceUSD: 1 / (x.token0Close / 10000000000),
token: 'LCDOT'
}))
Insert cell
lcDotDays = poolDayDataResult.poolDayData.nodes
Insert cell
ratiosDOT = lcDotDays2.map(x => ({
date: new Date(x.date.substring(0,10)),
ratio: 1/(x.token0Close / 10000000000),
}))
Insert cell
lcDotDays2 = poolDayDataResult2.poolDayData.nodes
Insert cell
poolDayDataResult2 = graph(`query {
poolDayData (filter: { token0Id: { equalTo: "DOT" }, token1Id: { equalTo: "lc://13"} }) {
nodes {
date, token0 { name, id}, token1 {name, id}, volumeUSD, token0Close }
}
}`)()
Insert cell
poolDayDataResult = graph(`query {
poolDayData (filter: { token0Id: { equalTo: "AUSD" }, token1Id: { equalTo: "lc://13"} }) {
nodes {
date, token0 { name, id }, token1 {name, id}, volumeUSD, token0Close }
}
}`)()
Insert cell
tokens = tokensResult.tokens
Insert cell
/*
// node.js script to download the above files
'use strict'
const apiKey = "9A6AA41C-0FF4-4D35-ADD7-49E4205B7BC0"

import fs from 'fs'
import fetch from 'node-fetch'


async function download(pair, filename ) {
if(pair.length !== 2)
throw new Error('pair must be array of 2')
if(!filename.includes('.json'))
throw new Error('Filename must have .json')
const res = await fetch(`https://rest.coinapi.io/v1/exchangerate/${pair[0]}/${pair[1]}/history?period_id=1DAY&time_start=2022-02-12T00:00:00&time_end=2023-01-01T00:00:00&limit=1000`, {
method: 'GET',
"headers": {
'X-CoinAPI-Key': apiKey,
"Accept": "application/json",
"Accept-Encoding": "deflate, gzip"
}
})
const body = await res.json()
fs.writeFile(filename, JSON.stringify(body),function(err, suc) {
console.log('File successfully written', err, suc)
})
}

download(['DOT', 'USD'], 'dot-usd.json')
//download(['KSM', 'USD'], 'ksm-usd.json')

*/
Insert cell
R = require('ramda')
Insert cell
tokensResult = graph(`query { tokens {
nodes { name, price, __typename}
} } `)()
Insert cell
import {Plot} from "@mkfreeman/plot-tooltip"
Insert cell
graphql = require("graphql.js")
Insert cell
graph = graphql("https://api.subquery.network/sq/rogerjbos/acala-swap-day-data")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more