Skip to content

Commit

Permalink
Add Amberdata case for DIGG/BTC (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
boxhock authored Mar 4, 2021
1 parent 8eff899 commit bedd77d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Changed

- Updated support for `DIGG/BTC` in Kaiko
- Updated support for `DIGG/BTC` in Kaiko and Amberdata
- Updated base URL for GeoDB

## [0.2.0-rc.1] - 2021-2-4
Expand Down
22 changes: 20 additions & 2 deletions amberdata/src/endpoint/price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ const customError = (data: any) => {
return Object.keys(data.payload).length === 0
}

const addressMapping: { [symbol: string]: string } = {
DIGG: '0x798d1be841a82a273720ce31c822c61a67a601c3',
WBTC: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
}

const customParams = {
base: ['base', 'from', 'coin'],
quote: ['quote', 'to', 'market'],
includes: false,
}

export const execute: ExecuteWithConfig<Config> = async (input, config) => {
Expand All @@ -19,12 +25,24 @@ export const execute: ExecuteWithConfig<Config> = async (input, config) => {

const coin = validator.validated.data.base
const market = validator.validated.data.quote
const url = `/api/v2/market/spot/prices/pairs/${coin.toLowerCase()}_${market.toLowerCase()}/latest`
const includes = validator.validated.data.includes || []

const params = {
let url = `/api/v2/market/spot/prices/pairs/${coin.toLowerCase()}_${market.toLowerCase()}/latest`
let params: { [key: string]: any } = {
includeCrossRates: true,
}

if (
includes.length > 0 &&
includes[0].toLowerCase() === 'wbtc' &&
coin.toLowerCase() === 'digg'
) {
const fromAddress = addressMapping[coin.toUpperCase()]
const toAddress = addressMapping[includes[0].toUpperCase()]
url = `/api/v2/market/defi/prices/pairs/bases/${fromAddress}/quotes/${toAddress}/latest`
params = {}
}

const reqConfig = { ...config.api, params, url }

const response = await Requester.request(reqConfig, customError)
Expand Down

0 comments on commit bedd77d

Please sign in to comment.