Skip to content

Instantly share code, notes, and snippets.

@smiled0g
Created August 29, 2020 10:36
Show Gist options
  • Save smiled0g/774c6e6fe1d48420d1e333924e6383a7 to your computer and use it in GitHub Desktop.
Save smiled0g/774c6e6fe1d48420d1e333924e6383a7 to your computer and use it in GitHub Desktop.
BAND/USD
// npm install --save @bandprotocol/bandchain.js
import BandChain from '@bandprotocol/bandchain.js'
// Chain parameters
const endpoint = 'https://guanyu-devnet.bandchain.org/rest'
// Request parameters
const oracleScriptId = 13
const params = {
"base_symbol": "BAND",
"quote_symbol": "USD",
"aggregation_method": "median",
"multiplier": 1000000
}
const validatorCounts = {
minCount: 3,
askCount: 4,
}
async function getLatestRequestResult() {
const bandchain = new BandChain(endpoint)
const oracleScript = await bandchain.getOracleScript(oracleScriptId)
const { result, resolve_time } = await bandchain.getLastMatchingRequestResult(
oracleScript,
params,
validatorCounts,
)
return {
result: parseFloat(result.px) / params.multiplier,
resolve_time: new Date(resolve_time * 1000)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment