Last active
November 11, 2024 12:27
-
-
Save shortthefomo/4f47d90200f87dc503e3f3f04494b918 to your computer and use it in GitHub Desktop.
Fetch USD price XRPL - DEVNET THREE ORACLE
This file contains 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
const { XrplClient } = require('xrpl-client') | |
const xrpl = new XrplClient() | |
// change this code to a different currency code one of others published, EUR/ZAR/MXN/JPY/BTC/USDT...... | |
let code = 'USD' | |
if (code.length > 3) { | |
const characters = Buffer.from(code, 'utf8').toString('hex') | |
let s = '0' | |
for (let index = 1; index < 40 - characters.length; index++) { | |
s = s + '0' | |
} | |
code = (characters + s).toUpperCase() | |
} | |
const command = { | |
'command': 'get_aggregate_price', | |
'ledger_index': 'current', | |
'base_asset': 'XRP', | |
'quote_asset': code, | |
'trim': 20, | |
'oracles': [ | |
{ | |
'account': 'roosteri9aGNFRXZrJNYQKVBfxHiE5abg', | |
'oracle_document_id': 0 | |
}, | |
{ | |
'account': 'roosteri9aGNFRXZrJNYQKVBfxHiE5abg', | |
'oracle_document_id': 1 | |
}, | |
{ | |
'account': 'roosteri9aGNFRXZrJNYQKVBfxHiE5abg', | |
'oracle_document_id': 2 | |
}, | |
{ | |
'account': 'roosteri9aGNFRXZrJNYQKVBfxHiE5abg', | |
'oracle_document_id': 3 | |
}, | |
{ | |
'account': 'roosteri9aGNFRXZrJNYQKVBfxHiE5abg', | |
'oracle_document_id': 4 | |
}, | |
{ | |
'account': 'roosteri9aGNFRXZrJNYQKVBfxHiE5abg', | |
'oracle_document_id': 5 | |
} | |
] | |
} | |
const response = await xrpl.send(command) | |
if ('error' in response) { return } | |
console.log(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment