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

Add Tiingo Token-Allocation #632

Merged
merged 1 commit into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions composite/token-allocation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The data providers supported and their properties are as follows:
| cryptocompare | :white_check_mark: | :white_check_mark: | :white_check_mark: | |
| kaiko | :white_check_mark: | :white_check_mark: | :x: | Crypto Quotes are not supported |
| nomics | :white_check_mark: | :white_check_mark: | :white_check_mark: | |
| tiingo | :white_check_mark: | :white_check_mark: | :x: | |

## Input Params

Expand Down
3 changes: 3 additions & 0 deletions composite/token-allocation/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as coingecko from './data-providers/coingecko'
import * as coinapi from './data-providers/coinapi'
import * as amberdata from './data-providers/amberdata'
import * as kaiko from './data-providers/kaiko'
import * as tiingo from './data-providers/tiingo'
import { Config, PriceAdapter } from './types'

enum DataProvider {
Expand All @@ -19,6 +20,7 @@ enum DataProvider {
Coingecko = 'coingecko',
Coinapi = 'coinapi',
Kaiko = 'kaiko',
Tiingo = 'tiingo',
}

const providers: Record<string, PriceAdapter> = {
Expand All @@ -30,6 +32,7 @@ const providers: Record<string, PriceAdapter> = {
[DataProvider.Coingecko]: coingecko,
[DataProvider.Coinapi]: coinapi,
[DataProvider.Kaiko]: kaiko,
[DataProvider.Tiingo]: tiingo,
}

export const DEFAULT_TOKEN_DECIMALS = 18
Expand Down
65 changes: 65 additions & 0 deletions composite/token-allocation/src/data-providers/tiingo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Requester } from '@chainlink/external-adapter'
import { util } from '@chainlink/ea-bootstrap'

export interface ResponseSchema {
ticker: string
baseCurrency: string
quoteCurrency: string
priceData: {
date: string
open: number
high: number
low: number
close: number
volume: number
volumeNotional: number
fxOpen: number
fxHigh: number
fxLow: number
fxClose: number
fxVolumeNotional: number
fxRate: number
tradesDone: number
}[]
}

// When an invalid symbol is given the response body is empty
const customError = (data: ResponseSchema[]) => !data.length

const getPriceData = async (base: string, quote: string) => {
const options = {
url: 'https://api.tiingo.com/tiingo/crypto/prices',
params: {
token: util.getRequiredEnv('API_KEY'),
baseCurrency: base,
convertCurrency: quote,
consolidateBaseCurrency: true,
resampleFreq: '24hour',
},
}

const response = await Requester.request(options, customError)
return Requester.validateResultNumber(response.data as ResponseSchema[], [
0,
'priceData',
0,
'fxClose',
])
}

export const getPrices = async (
baseSymbols: string[],
quote: string,
): Promise<Record<string, number>> => {
const entries = await Promise.all(
baseSymbols.map(async (symbol) => {
const data = await getPriceData(symbol, quote)
return [symbol, data]
}),
)

return Object.fromEntries(entries)
}
export const getMarketCaps = () => {
throw Error('not implemented')
}