First some libraries needed:
library(jsonlite)
library(ggplot2)Testing connection
resp <- fromJSON("https://cryptoderivatives.market/api/token/NMR/")Well, it works :) The data is inside trades. We can see it here:
names(resp$trades) [1] "type" "contract" "name" "owner" "asset"
[6] "symbol" "tokensFrom" "tokensTo" "usedRate" "buyRate"
[11] "sellRate" "blockNumber" "timestamp" "recid" "tokens"
[16] "ethers" "txHash" "txFee"
We can now create a function that loads the data and extract the buys events.
getBuys <- function() {
resp <- fromJSON("https://cryptoderivatives.market/api/token/NMR/");
resp$trades[resp$trades$type == "Taker Bought Asset", ]
}Now let's plot it :)
ggplot(getBuys(), aes(x=timestamp, y=sellRate)) + geom_line() + labs(x="Timestamp", y="ETH/NMR")Cool, but lets try doing a boxplot. We'll create a function so we can experiment with the timestamp.
prepareBoxplotData <- function(buys, tsWindow) {
buys$truncTimestamp <- buys$timestamp %/% tsWindow;
buys
}
buysBoxplot <- function(tsWindow) {
buys <- prepareBoxplotData(getBuys(), tsWindow)
ggplot(buys, aes(x=timestamp, y=as.numeric(sellRate), group=truncTimestamp)) + labs(x="Timestamp", y="ETH/NMR") + geom_boxplot()
}Now let's try it with a one-hour window.
buysBoxplot(1*60*60)Uh… To scattered. Let's try 4 hours:
buysBoxplot(4*60*60)Not that informative either… We should probably stick with the line plot.





