-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add crypto endpoint to tiingo adapter
- Loading branch information
1 parent
1756fba
commit 9d0034d
Showing
7 changed files
with
170 additions
and
19 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Requester, Validator } from '@chainlink/external-adapter' | ||
import { ExecuteWithConfig, Config } from '@chainlink/types' | ||
|
||
export const NAME = 'top' | ||
|
||
export interface ResponseSchema { | ||
ticker: string | ||
baseCurrency: string | ||
quoteCurrency: string | ||
topOfBookData: { | ||
askSize: number | ||
bidSize: number | ||
lastSaleTimestamp: string | ||
lastPrice: number | ||
askPrice: number | ||
quoteTimestamp: string | ||
bidExchange: string | ||
lastSizeNotional: number | ||
lastExchange: string | ||
askExchange: string | ||
bidPrice: number | ||
lastSize: number | ||
}[] | ||
} | ||
|
||
const customParams = { | ||
base: ['base', 'from', 'coin'], | ||
quote: ['quote', 'to', 'market'], | ||
field: false, | ||
} | ||
|
||
// When an invalid symbol is given the response body is empty | ||
const customError = (data: ResponseSchema[]) => !data.length | ||
|
||
export const execute: ExecuteWithConfig<Config> = async (request, config) => { | ||
const validator = new Validator(request, customParams) | ||
if (validator.error) throw validator.error | ||
|
||
const jobRunID = validator.validated.id | ||
const base = validator.validated.data.base.toLowerCase() | ||
const quote = validator.validated.data.quote.toLowerCase() | ||
const field = validator.validated.data.field || 'lastPrice' | ||
|
||
const url = '/tiingo/crypto/top' | ||
|
||
const options = { | ||
...config.api, | ||
params: { | ||
token: config.apiKey, | ||
tickers: base + quote, | ||
}, | ||
url, | ||
} | ||
|
||
const response = await Requester.request(options, customError) | ||
const result = Requester.validateResultNumber(response.data as ResponseSchema[], [ | ||
0, | ||
'topOfBookData', | ||
0, | ||
field, | ||
]) | ||
|
||
return Requester.success(jobRunID, { | ||
data: config.verbose ? { ...response.data, result } : { result }, | ||
result, | ||
status: 200, | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * as eod from './eod' | ||
export * as iex from './iex' | ||
export * as top from './crypto/top' |
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