Created
August 29, 2020 10:36
-
-
Save smiled0g/774c6e6fe1d48420d1e333924e6383a7 to your computer and use it in GitHub Desktop.
BAND/USD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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