Skip to content

Commit

Permalink
api: add dia fair price feed (#1619)
Browse files Browse the repository at this point in the history
* api: add dia fair price feed

* api: add dia fair price feed
  • Loading branch information
ns212 authored Jan 4, 2024
1 parent ad10324 commit fd099b0
Showing 1 changed file with 27 additions and 0 deletions.
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

2 comments on commit fd099b0

@vercel
Copy link

@vercel vercel bot commented on fd099b0 Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on fd099b0 Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.