Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: add dia fair price feed #1619

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions api/market_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,38 @@ const dia_assets = {
"wrapped-bitcoin": "/Ethereum/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
}

// Coingecko to Dia XLSD tickers
const dia_xlsd = {
"voucher-ksm": "vKSM",
"voucher-dot": "vDOT",
}

// retrieve Dia XLSD fair prices
const fetchDiaXLSD = async () => {
const url = 'https://api.diadata.org/xlsd'
const resp = await fetch(url, { headers: { "accept": "application/json" } })
if (!resp.ok) {
throw new Error(resp.status)
}
const json = await resp.json()
return new Map(json.map(x => [x.Token, x]))
}

const fetchDiaAsset = async (asset) => {
try {
if (!dia_assets[asset]) {
console.log('Missing DIA asset: ', asset)
return coingecko({ ids: [asset], vs_currencies: ["usd"] })
}
if (asset in dia_xlsd) {
const prices = await fetchDiaXLSD();
return {
[asset]: {
'usd': prices.get(dia_xlsd[asset]).FairPrice
}
}
}

const url = 'https://api.diadata.org/v1/assetQuotation' + dia_assets[asset]
const response = await fetch(url, { headers: { "accept": "application/json" } })
if (!response.ok) {
Expand All @@ -56,6 +82,7 @@ const fetchDiaAsset = async (asset) => {
}
} catch (error) {
console.log(error)
throw error;
}
}

Expand Down
Loading