Implementing DARK offchain worker fetching price in Cryptocompare API

Submitted by Stem on Sun, 01/31/2021 - 00:03
Implementing DARK offchain worker fetching price in Cryptocompare API

As we are preparing to release a public testnet "Dystopia" proof of concept as a Polkadot parachain, we tested a first implementation of an offchain-worker.

 

It's quite simple now and it fetches price from Cryptocompare API, but we can imagine it can also fetch prices from different sources like Coinmarketcap, Coingecko... in the future, with average calculation, variation checks etc.

Code is adapted from Substrate developers Hub recipes, with main functions, one for fetching price from eternal API with http get :

 

fetch function substrate offchain worker

 

And one for parsing result :

 

substrate offchain worker parse json http get

 

Compiling, and... it works :))

yes, there's a f32 conversion before printing.

 

 

This is a part of DarkBay incoming preview, stay tuned !