-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added WS transport for coinpaprika (#3063)
* add ws transport for crypto endpoints * refactor ws transport * Marketcap & Volume soak test payloads --------- Co-authored-by: Alec Gard <[email protected]> Co-authored-by: cl-ea <[email protected]>
- Loading branch information
1 parent
82f3591
commit 0a5e11e
Showing
20 changed files
with
1,188 additions
and
657 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@chainlink/coinpaprika-adapter': patch | ||
--- | ||
|
||
Added websocket transport for crypto(price), volume and marketcap endpoints. Refactored crypto endpoint/transport |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,78 +1,17 @@ | ||
import { CryptoPriceEndpoint } from '@chainlink/external-adapter-framework/adapter' | ||
import { SingleNumberResultResponse } from '@chainlink/external-adapter-framework/util' | ||
import { InputParameters } from '@chainlink/external-adapter-framework/validation' | ||
import { config } from '../config' | ||
import { transport } from '../transport/crypto' | ||
import { TransportRoutes } from '@chainlink/external-adapter-framework/transports' | ||
import { buildCryptoHttpTransport, buildWebsocketTransport } from '../transport/utils' | ||
import { BaseEndpointTypes, cryptoInputParameters, customInputValidation } from './utils' | ||
import overrides from '../config/overrides.json' | ||
export const inputParameters = new InputParameters( | ||
{ | ||
base: { | ||
aliases: ['from', 'coin'], | ||
description: 'The symbol of symbols of the currency to query', | ||
required: true, | ||
type: 'string', | ||
}, | ||
quote: { | ||
aliases: ['to', 'market'], | ||
description: 'The symbol of the currency to convert to', | ||
required: true, | ||
type: 'string', | ||
}, | ||
coinid: { | ||
description: 'The coin ID (optional to use in place of `base`)', | ||
required: false, | ||
type: 'string', | ||
}, | ||
resultPath: { | ||
description: 'The path to the result within the asset quote in the provider response', | ||
required: false, | ||
type: 'string', | ||
options: ['price', 'volume_24h', 'market_cap'], | ||
}, | ||
}, | ||
[ | ||
{ | ||
base: 'AAAA', | ||
coinid: 'eth-ethereum', | ||
quote: 'USD', | ||
resultPath: 'price', | ||
}, | ||
{ | ||
base: 'ETH', | ||
quote: 'USD', | ||
resultPath: 'volume_24h', | ||
}, | ||
], | ||
) | ||
|
||
export type BaseEndpointTypes = { | ||
Parameters: typeof inputParameters.definition | ||
Settings: typeof config.settings | ||
Response: SingleNumberResultResponse | ||
} | ||
|
||
// Maps the input parameter value with the value that will be set in the requestContext.data object | ||
const resultPathMap = { | ||
price: 'price', | ||
crypto: 'price', | ||
volume: 'volume_24h', | ||
marketcap: 'market_cap', | ||
} as const | ||
|
||
export const endpoint = new CryptoPriceEndpoint({ | ||
name: 'crypto', | ||
aliases: ['price', 'marketcap', 'volume'], | ||
requestTransforms: [ | ||
(request) => { | ||
if (!request.requestContext.data.resultPath) { | ||
const endpoint = | ||
(request.body.data as { endpoint: keyof typeof resultPathMap }).endpoint || | ||
request.requestContext.endpointName | ||
request.requestContext.data.resultPath = resultPathMap[endpoint] | ||
} | ||
}, | ||
], | ||
transport, | ||
inputParameters: inputParameters, | ||
aliases: ['price'], | ||
transportRoutes: new TransportRoutes<BaseEndpointTypes>() | ||
.register('ws', buildWebsocketTransport('p')) | ||
.register('rest', buildCryptoHttpTransport('price')), | ||
defaultTransport: 'rest', | ||
inputParameters: cryptoInputParameters, | ||
overrides: overrides.coinpaprika, | ||
customInputValidation, | ||
}) |
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,16 @@ | ||
import { PriceEndpoint } from '@chainlink/external-adapter-framework/adapter' | ||
import overrides from '../config/overrides.json' | ||
import { TransportRoutes } from '@chainlink/external-adapter-framework/transports' | ||
import { buildCryptoHttpTransport, buildWebsocketTransport } from '../transport/utils' | ||
import { BaseEndpointTypes, cryptoInputParameters, customInputValidation } from './utils' | ||
|
||
export const endpoint = new PriceEndpoint({ | ||
name: 'marketcap', | ||
transportRoutes: new TransportRoutes<BaseEndpointTypes>() | ||
.register('ws', buildWebsocketTransport('m')) | ||
.register('rest', buildCryptoHttpTransport('market_cap')), | ||
defaultTransport: 'rest', | ||
inputParameters: cryptoInputParameters, | ||
overrides: overrides.coinpaprika, | ||
customInputValidation, | ||
}) |
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,83 @@ | ||
import { InputParameters } from '@chainlink/external-adapter-framework/validation' | ||
import { | ||
AdapterRequest, | ||
SingleNumberResultResponse, | ||
} from '@chainlink/external-adapter-framework/util' | ||
|
||
import { AVAILABLE_WS_QUOTES, config } from '../config' | ||
import { | ||
AdapterError, | ||
AdapterInputError, | ||
} from '@chainlink/external-adapter-framework/validation/error' | ||
|
||
export const cryptoInputParameters = new InputParameters( | ||
{ | ||
base: { | ||
aliases: ['from', 'coin'], | ||
description: 'The symbol of symbols of the currency to query', | ||
required: true, | ||
type: 'string', | ||
}, | ||
quote: { | ||
aliases: ['to', 'market'], | ||
description: 'The symbol of the currency to convert to', | ||
required: true, | ||
type: 'string', | ||
}, | ||
coinid: { | ||
description: 'The coin ID (optional to use in place of `base`)', | ||
required: false, | ||
type: 'string', | ||
}, | ||
resultPath: { | ||
description: | ||
'The path to the result within the asset quote in the provider response (only for REST)', | ||
required: false, | ||
type: 'string', | ||
options: ['price', 'volume_24h', 'market_cap'], | ||
}, | ||
}, | ||
[ | ||
{ | ||
base: 'AAAA', | ||
coinid: 'eth-ethereum', | ||
quote: 'USD', | ||
resultPath: 'price', | ||
}, | ||
{ | ||
base: 'ETH', | ||
quote: 'USD', | ||
resultPath: 'volume_24h', | ||
}, | ||
], | ||
) | ||
|
||
export type BaseEndpointTypes = { | ||
Parameters: typeof cryptoInputParameters.definition | ||
Settings: typeof config.settings | ||
Response: SingleNumberResultResponse | ||
} | ||
|
||
export function customInputValidation( | ||
req: AdapterRequest<typeof cryptoInputParameters.validated>, | ||
settings: typeof config.settings, | ||
): AdapterError | undefined { | ||
if (req.requestContext.transportName === 'ws' && !settings.WS_API_ENDPOINT) { | ||
return new AdapterInputError({ | ||
statusCode: 400, | ||
message: 'WS_API_ENDPOINT is required for streaming data', | ||
}) | ||
} | ||
if ( | ||
req.requestContext.transportName === 'ws' && | ||
!AVAILABLE_WS_QUOTES.includes( | ||
req.requestContext.data.quote as (typeof AVAILABLE_WS_QUOTES)[number], | ||
) | ||
) { | ||
return new AdapterInputError({ | ||
statusCode: 400, | ||
message: `Invalid quote. Available quotes for websocket are - ${AVAILABLE_WS_QUOTES}`, | ||
}) | ||
} | ||
return | ||
} |
Oops, something went wrong.