@chainlink/external-adapter-framework 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapter.js +128 -0
- package/background-executor.js +45 -0
- package/cache/factory.js +58 -0
- package/cache/index.js +173 -0
- package/cache/local.js +83 -0
- package/cache/metrics.js +120 -0
- package/cache/redis.js +100 -0
- package/chainlink-external-adapter-framework-v0.0.6.tgz +0 -0
- package/config/index.js +366 -0
- package/config/provider-limits.js +74 -0
- package/examples/bank-frick/accounts.js +192 -0
- package/examples/bank-frick/config/index.js +54 -0
- package/examples/bank-frick/index.js +15 -0
- package/examples/bank-frick/util.js +39 -0
- package/examples/coingecko/batch-warming.js +53 -0
- package/examples/coingecko/index.js +11 -0
- package/examples/coingecko/rest.js +51 -0
- package/examples/coingecko/src/config/index.js +13 -0
- package/examples/coingecko/src/config/overrides.json +10826 -0
- package/examples/coingecko/src/cryptoUtils.js +41 -0
- package/examples/coingecko/src/endpoint/coins.js +33 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +46 -0
- package/examples/coingecko/src/endpoint/crypto-volume.js +46 -0
- package/examples/coingecko/src/endpoint/crypto.js +47 -0
- package/examples/coingecko/src/endpoint/dominance.js +26 -0
- package/examples/coingecko/src/endpoint/global-marketcap.js +26 -0
- package/examples/coingecko/src/endpoint/index.js +15 -0
- package/examples/coingecko/src/globalUtils.js +48 -0
- package/examples/coingecko/src/index.js +14 -0
- package/examples/coingecko/test/e2e/adapter.test.js +262 -0
- package/examples/coingecko/test/integration/adapter.test.js +264 -0
- package/examples/coingecko/test/integration/capturedRequests.json +1 -0
- package/examples/coingecko/test/integration/fixtures.js +41 -0
- package/examples/coingecko-old/batch-warming.js +53 -0
- package/examples/coingecko-old/index.js +11 -0
- package/examples/coingecko-old/rest.js +51 -0
- package/examples/ncfx/config/index.js +15 -0
- package/examples/ncfx/index.js +11 -0
- package/examples/ncfx/websocket.js +73 -0
- package/index.js +127 -0
- package/metrics/constants.js +25 -0
- package/metrics/index.js +122 -0
- package/metrics/util.js +9 -0
- package/package.json +5 -15
- package/rate-limiting/background/fixed-frequency.js +35 -0
- package/rate-limiting/index.js +84 -0
- package/rate-limiting/metrics.js +44 -0
- package/rate-limiting/request/simple-counting.js +62 -0
- package/test.js +6 -0
- package/transports/batch-warming.js +101 -0
- package/transports/index.js +87 -0
- package/transports/metrics.js +105 -0
- package/transports/rest.js +138 -0
- package/transports/util.js +86 -0
- package/transports/websocket.js +166 -0
- package/util/index.js +35 -0
- package/util/logger.js +62 -0
- package/util/recordRequests.js +45 -0
- package/util/request.js +2 -0
- package/util/subscription-set/expiring-sorted-set.js +47 -0
- package/util/subscription-set/subscription-set.js +19 -0
- package/util/test-payload-loader.js +83 -0
- package/validation/error.js +79 -0
- package/validation/index.js +91 -0
- package/validation/input-params.js +30 -0
- package/validation/override-functions.js +40 -0
- package/validation/overrideFunctions.js +40 -0
- package/validation/preset-tokens.json +23 -0
- package/validation/validator.js +303 -0
- package/.c8rc.json +0 -3
- package/.eslintignore +0 -10
- package/.eslintrc.js +0 -96
- package/.github/README.MD +0 -42
- package/.github/actions/setup/action.yaml +0 -13
- package/.github/workflows/label.yaml +0 -39
- package/.github/workflows/main.yaml +0 -39
- package/.github/workflows/publish.yaml +0 -17
- package/.prettierignore +0 -13
- package/.yarnrc +0 -0
- package/README.md +0 -103
- package/dist/examples/coingecko/test/e2e/adapter.test.ts.js +0 -82953
- package/dist/examples/coingecko/test/integration/adapter.test.ts.js +0 -91672
- package/dist/main.js +0 -72703
- package/docker-compose.yaml +0 -35
- package/env.sh +0 -54
- package/env2.sh +0 -55
- package/jest.config.js +0 -5
- package/publish.sh +0 -0
- package/src/adapter.ts +0 -263
- package/src/background-executor.ts +0 -52
- package/src/cache/factory.ts +0 -26
- package/src/cache/index.ts +0 -258
- package/src/cache/local.ts +0 -73
- package/src/cache/metrics.ts +0 -112
- package/src/cache/redis.ts +0 -93
- package/src/config/index.ts +0 -517
- package/src/config/provider-limits.ts +0 -127
- package/src/examples/bank-frick/README.MD +0 -10
- package/src/examples/bank-frick/accounts.ts +0 -246
- package/src/examples/bank-frick/config/index.ts +0 -53
- package/src/examples/bank-frick/index.ts +0 -13
- package/src/examples/bank-frick/types.d.ts +0 -38
- package/src/examples/bank-frick/util.ts +0 -55
- package/src/examples/coingecko/src/config/index.ts +0 -12
- package/src/examples/coingecko/src/config/overrides.json +0 -10826
- package/src/examples/coingecko/src/cryptoUtils.ts +0 -88
- package/src/examples/coingecko/src/endpoint/coins.ts +0 -54
- package/src/examples/coingecko/src/endpoint/crypto-marketcap.ts +0 -66
- package/src/examples/coingecko/src/endpoint/crypto-volume.ts +0 -66
- package/src/examples/coingecko/src/endpoint/crypto.ts +0 -63
- package/src/examples/coingecko/src/endpoint/dominance.ts +0 -40
- package/src/examples/coingecko/src/endpoint/global-marketcap.ts +0 -40
- package/src/examples/coingecko/src/endpoint/index.ts +0 -6
- package/src/examples/coingecko/src/globalUtils.ts +0 -78
- package/src/examples/coingecko/src/index.ts +0 -17
- package/src/examples/coingecko/test/e2e/adapter.test.ts +0 -278
- package/src/examples/coingecko/test/integration/__snapshots__/adapter.test.ts.snap +0 -15
- package/src/examples/coingecko/test/integration/adapter.test.ts +0 -281
- package/src/examples/coingecko/test/integration/capturedRequests.json +0 -1
- package/src/examples/coingecko/test/integration/fixtures.ts +0 -42
- package/src/examples/coingecko-old/batch-warming.ts +0 -79
- package/src/examples/coingecko-old/index.ts +0 -9
- package/src/examples/coingecko-old/rest.ts +0 -77
- package/src/examples/ncfx/config/index.ts +0 -12
- package/src/examples/ncfx/index.ts +0 -9
- package/src/examples/ncfx/websocket.ts +0 -99
- package/src/index.ts +0 -149
- package/src/metrics/constants.ts +0 -23
- package/src/metrics/index.ts +0 -115
- package/src/metrics/util.ts +0 -18
- package/src/rate-limiting/background/fixed-frequency.ts +0 -45
- package/src/rate-limiting/index.ts +0 -100
- package/src/rate-limiting/metrics.ts +0 -18
- package/src/rate-limiting/request/simple-counting.ts +0 -76
- package/src/transports/batch-warming.ts +0 -127
- package/src/transports/index.ts +0 -152
- package/src/transports/metrics.ts +0 -95
- package/src/transports/rest.ts +0 -168
- package/src/transports/util.ts +0 -63
- package/src/transports/websocket.ts +0 -245
- package/src/util/index.ts +0 -23
- package/src/util/logger.ts +0 -69
- package/src/util/recordRequests.ts +0 -47
- package/src/util/request.ts +0 -117
- package/src/util/subscription-set/expiring-sorted-set.ts +0 -54
- package/src/util/subscription-set/subscription-set.ts +0 -35
- package/src/util/test-payload-loader.ts +0 -87
- package/src/validation/error.ts +0 -116
- package/src/validation/index.ts +0 -110
- package/src/validation/input-params.ts +0 -45
- package/src/validation/override-functions.ts +0 -44
- package/src/validation/overrideFunctions.ts +0 -44
- package/src/validation/preset-tokens.json +0 -23
- package/src/validation/validator.ts +0 -384
- package/test/adapter.test.ts +0 -27
- package/test/background-executor.test.ts +0 -108
- package/test/cache/cache-key.test.ts +0 -114
- package/test/cache/helper.ts +0 -100
- package/test/cache/local.test.ts +0 -54
- package/test/cache/redis.test.ts +0 -89
- package/test/correlation.test.ts +0 -114
- package/test/index.test.ts +0 -37
- package/test/metrics/feed-id.test.ts +0 -38
- package/test/metrics/helper.ts +0 -14
- package/test/metrics/labels.test.ts +0 -36
- package/test/metrics/metrics.test.ts +0 -267
- package/test/metrics/redis-metrics.test.ts +0 -113
- package/test/metrics/warmer-metrics.test.ts +0 -193
- package/test/metrics/ws-metrics.test.ts +0 -225
- package/test/rate-limit-config.test.ts +0 -242
- package/test/smoke/smoke.test.ts +0 -166
- package/test/smoke/test-payload-fail.json +0 -3
- package/test/smoke/test-payload.js +0 -22
- package/test/smoke/test-payload.json +0 -7
- package/test/transports/batch.test.ts +0 -466
- package/test/transports/rest.test.ts +0 -242
- package/test/transports/websocket.test.ts +0 -183
- package/test/tsconfig.json +0 -5
- package/test/util.ts +0 -77
- package/test/validation.test.ts +0 -178
- package/test.sh +0 -20
- package/test2.sh +0 -2
- package/tsconfig.json +0 -28
- package/typedoc.json +0 -6
- package/webpack.config.js +0 -57
- package/yarn-error.log +0 -3778
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios'
|
|
2
|
-
import { PRO_API_ENDPOINT, DEFAULT_API_ENDPOINT } from './config'
|
|
3
|
-
import { AdapterConfig } from '../../../config'
|
|
4
|
-
import { makeLogger } from '../../../util/logger'
|
|
5
|
-
|
|
6
|
-
type Overrides = Record<string, Record<string, string>>
|
|
7
|
-
|
|
8
|
-
export interface AdapterRequestParams {
|
|
9
|
-
coinid?: string
|
|
10
|
-
base?: string
|
|
11
|
-
quote: string
|
|
12
|
-
overrides?: Overrides
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface ProviderRequestBody {
|
|
16
|
-
ids: string
|
|
17
|
-
vs_currencies: string
|
|
18
|
-
include_market_cap?: boolean
|
|
19
|
-
include_24hr_vol?: boolean
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface ProviderResponseBody {
|
|
23
|
-
[base: string]: {
|
|
24
|
-
[quote: string]: number
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface ResultEntry {
|
|
29
|
-
value: number
|
|
30
|
-
params: {
|
|
31
|
-
quote: string
|
|
32
|
-
base?: string
|
|
33
|
-
coinid?: string
|
|
34
|
-
overrides?: Overrides
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
interface ResultEntryWithoutOverrides {
|
|
39
|
-
value: number
|
|
40
|
-
params: {
|
|
41
|
-
quote: string
|
|
42
|
-
base?: string
|
|
43
|
-
coinid?: string
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const buildBatchedRequestBody = (
|
|
48
|
-
params: AdapterRequestParams[],
|
|
49
|
-
config: AdapterConfig,
|
|
50
|
-
): AxiosRequestConfig<ProviderRequestBody> => {
|
|
51
|
-
return {
|
|
52
|
-
baseURL: config.API_KEY ? PRO_API_ENDPOINT : DEFAULT_API_ENDPOINT,
|
|
53
|
-
url: '/simple/price',
|
|
54
|
-
method: 'GET',
|
|
55
|
-
params: {
|
|
56
|
-
ids: [...new Set(params.map((p) => p.coinid ?? p.base))].join(','),
|
|
57
|
-
vs_currencies: [...new Set(params.map((p) => p.quote))].join(','),
|
|
58
|
-
x_cg_pro_api_key: config.API_KEY,
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const logger = makeLogger('CoinGecko Crypto Batched')
|
|
64
|
-
|
|
65
|
-
export const constructEntry = (
|
|
66
|
-
res: AxiosResponse<ProviderResponseBody>,
|
|
67
|
-
requestPayload: AdapterRequestParams,
|
|
68
|
-
resultPath: string,
|
|
69
|
-
): ResultEntryWithoutOverrides | undefined => {
|
|
70
|
-
const coinId = requestPayload.coinid ?? (requestPayload.base as string)
|
|
71
|
-
const dataForCoin = res.data[coinId]
|
|
72
|
-
const dataForQuote = dataForCoin ? dataForCoin[resultPath] : undefined
|
|
73
|
-
if (!dataForQuote) {
|
|
74
|
-
logger.warn(`Data for "${requestPayload.quote}" not found for token "${coinId}".`)
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
const entry = {
|
|
78
|
-
params: requestPayload,
|
|
79
|
-
value: dataForQuote,
|
|
80
|
-
} as ResultEntry
|
|
81
|
-
if (requestPayload.coinid) {
|
|
82
|
-
entry.params.coinid = requestPayload.coinid
|
|
83
|
-
} else {
|
|
84
|
-
entry.params.base = requestPayload.base
|
|
85
|
-
}
|
|
86
|
-
delete entry.params.overrides
|
|
87
|
-
return entry
|
|
88
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { AxiosResponse, AxiosRequestConfig } from 'axios'
|
|
2
|
-
import { AdapterConfig } from '../../../../config'
|
|
3
|
-
import { AdapterEndpoint } from '../../../../../src/adapter'
|
|
4
|
-
import { RestTransport } from '../../../../../src/transports'
|
|
5
|
-
import { AdapterRequest, AdapterResponse } from '../../../../../src/util'
|
|
6
|
-
import { InputParameters } from '../../../../../src/validation'
|
|
7
|
-
import { DEFAULT_API_ENDPOINT, PRO_API_ENDPOINT, customSettings } from '../config'
|
|
8
|
-
|
|
9
|
-
export const inputParameters: InputParameters = {}
|
|
10
|
-
|
|
11
|
-
export interface AdapterRequestParams {
|
|
12
|
-
id: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface CoinsResponse {
|
|
16
|
-
id: string
|
|
17
|
-
symbol: string
|
|
18
|
-
name: string
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const restEndpointTransport = new RestTransport({
|
|
22
|
-
prepareRequest: (
|
|
23
|
-
_: AdapterRequest<AdapterRequestParams>,
|
|
24
|
-
config: AdapterConfig<typeof customSettings>,
|
|
25
|
-
): AxiosRequestConfig<CoinsResponse> => {
|
|
26
|
-
const baseURL = config.API_KEY ? PRO_API_ENDPOINT : DEFAULT_API_ENDPOINT
|
|
27
|
-
const params = config.API_KEY ? { x_cg_pro_api_key: config.API_KEY } : undefined
|
|
28
|
-
return {
|
|
29
|
-
baseURL,
|
|
30
|
-
url: '/coins/list',
|
|
31
|
-
method: 'GET',
|
|
32
|
-
params,
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
parseResponse: (
|
|
36
|
-
req: AdapterRequest<AdapterRequestParams>,
|
|
37
|
-
res: AxiosResponse<CoinsResponse[]>,
|
|
38
|
-
): AdapterResponse<CoinsResponse[]> => {
|
|
39
|
-
return {
|
|
40
|
-
data: res.data,
|
|
41
|
-
statusCode: 200,
|
|
42
|
-
result: res.data,
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
options: {
|
|
46
|
-
coalescing: true,
|
|
47
|
-
},
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
export const endpoint: AdapterEndpoint = {
|
|
51
|
-
name: 'coins',
|
|
52
|
-
transport: restEndpointTransport,
|
|
53
|
-
inputParameters,
|
|
54
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios'
|
|
2
|
-
import { AdapterEndpoint, AdapterContext } from '../../../../adapter'
|
|
3
|
-
import { BatchWarmingTransport } from '../../../../transports/batch-warming'
|
|
4
|
-
import { ProviderResult } from '../../../../util'
|
|
5
|
-
import { InputParameters } from '../../../../validation'
|
|
6
|
-
import { baseInputParameters } from '../../../../validation/input-params'
|
|
7
|
-
import {
|
|
8
|
-
AdapterRequestParams,
|
|
9
|
-
ProviderRequestBody,
|
|
10
|
-
buildBatchedRequestBody,
|
|
11
|
-
constructEntry,
|
|
12
|
-
ProviderResponseBody,
|
|
13
|
-
} from '../cryptoUtils'
|
|
14
|
-
|
|
15
|
-
export const inputParameters: InputParameters = {
|
|
16
|
-
overrides: baseInputParameters['overrides'],
|
|
17
|
-
coinid: {
|
|
18
|
-
description: 'The CoinGecko id or to query',
|
|
19
|
-
required: false,
|
|
20
|
-
},
|
|
21
|
-
base: {
|
|
22
|
-
aliases: ['from', 'coin'],
|
|
23
|
-
description: 'The symbol of symbols of the currency to query',
|
|
24
|
-
required: false,
|
|
25
|
-
},
|
|
26
|
-
quote: {
|
|
27
|
-
aliases: ['to', 'market'],
|
|
28
|
-
description: 'The symbol of the currency to convert to',
|
|
29
|
-
required: true,
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const batchEndpointTransport = new BatchWarmingTransport({
|
|
34
|
-
prepareRequest: (
|
|
35
|
-
params: AdapterRequestParams[],
|
|
36
|
-
context: AdapterContext,
|
|
37
|
-
): AxiosRequestConfig<ProviderRequestBody> => {
|
|
38
|
-
const requestBody = buildBatchedRequestBody(params, context.adapterConfig)
|
|
39
|
-
requestBody.params.include_market_cap = true
|
|
40
|
-
return requestBody
|
|
41
|
-
},
|
|
42
|
-
parseResponse: (
|
|
43
|
-
params: AdapterRequestParams[],
|
|
44
|
-
res: AxiosResponse<ProviderResponseBody>,
|
|
45
|
-
): ProviderResult<AdapterRequestParams>[] => {
|
|
46
|
-
const entries = [] as ProviderResult<AdapterRequestParams>[]
|
|
47
|
-
for (const requestPayload of params) {
|
|
48
|
-
const entry = constructEntry(
|
|
49
|
-
res,
|
|
50
|
-
requestPayload,
|
|
51
|
-
`${requestPayload.quote.toLowerCase()}_market_cap`,
|
|
52
|
-
)
|
|
53
|
-
if (entry) {
|
|
54
|
-
entries.push(entry)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return entries
|
|
58
|
-
},
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
export const endpoint: AdapterEndpoint = {
|
|
62
|
-
name: 'marketcap',
|
|
63
|
-
aliases: ['crypto-marketcap'],
|
|
64
|
-
transport: batchEndpointTransport,
|
|
65
|
-
inputParameters,
|
|
66
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios'
|
|
2
|
-
import { AdapterEndpoint, AdapterContext } from '../../../../adapter'
|
|
3
|
-
import { BatchWarmingTransport } from '../../../../transports/batch-warming'
|
|
4
|
-
import { ProviderResult } from '../../../../util'
|
|
5
|
-
import { InputParameters } from '../../../../validation'
|
|
6
|
-
import { baseInputParameters } from '../../../../validation/input-params'
|
|
7
|
-
import {
|
|
8
|
-
AdapterRequestParams,
|
|
9
|
-
ProviderRequestBody,
|
|
10
|
-
buildBatchedRequestBody,
|
|
11
|
-
constructEntry,
|
|
12
|
-
ProviderResponseBody,
|
|
13
|
-
} from '../cryptoUtils'
|
|
14
|
-
|
|
15
|
-
export const inputParameters: InputParameters = {
|
|
16
|
-
overrides: baseInputParameters['overrides'],
|
|
17
|
-
coinid: {
|
|
18
|
-
description: 'The CoinGecko id or to query',
|
|
19
|
-
required: false,
|
|
20
|
-
},
|
|
21
|
-
base: {
|
|
22
|
-
aliases: ['from', 'coin'],
|
|
23
|
-
description: 'The symbol of symbols of the currency to query',
|
|
24
|
-
required: false,
|
|
25
|
-
},
|
|
26
|
-
quote: {
|
|
27
|
-
aliases: ['to', 'market'],
|
|
28
|
-
description: 'The symbol of the currency to convert to',
|
|
29
|
-
required: true,
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const batchEndpointTransport = new BatchWarmingTransport({
|
|
34
|
-
prepareRequest: (
|
|
35
|
-
params: AdapterRequestParams[],
|
|
36
|
-
context: AdapterContext,
|
|
37
|
-
): AxiosRequestConfig<ProviderRequestBody> => {
|
|
38
|
-
const requestBody = buildBatchedRequestBody(params, context.adapterConfig)
|
|
39
|
-
requestBody.params.include_24hr_vol = true
|
|
40
|
-
return requestBody
|
|
41
|
-
},
|
|
42
|
-
parseResponse: (
|
|
43
|
-
params: AdapterRequestParams[],
|
|
44
|
-
res: AxiosResponse<ProviderResponseBody>,
|
|
45
|
-
): ProviderResult<AdapterRequestParams>[] => {
|
|
46
|
-
const entries = [] as ProviderResult<AdapterRequestParams>[]
|
|
47
|
-
for (const requestPayload of params) {
|
|
48
|
-
const entry = constructEntry(
|
|
49
|
-
res,
|
|
50
|
-
requestPayload,
|
|
51
|
-
`${requestPayload.quote.toLowerCase()}_24h_vol`,
|
|
52
|
-
)
|
|
53
|
-
if (entry) {
|
|
54
|
-
entries.push(entry)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return entries
|
|
58
|
-
},
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
export const endpoint: AdapterEndpoint = {
|
|
62
|
-
name: 'volume',
|
|
63
|
-
aliases: ['crypto-volume'],
|
|
64
|
-
transport: batchEndpointTransport,
|
|
65
|
-
inputParameters,
|
|
66
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios'
|
|
2
|
-
import { AdapterEndpoint, AdapterContext } from '../../../../adapter'
|
|
3
|
-
import { BatchWarmingTransport } from '../../../../transports/batch-warming'
|
|
4
|
-
import { ProviderResult } from '../../../../util'
|
|
5
|
-
import { InputParameters } from '../../../../validation'
|
|
6
|
-
import { baseInputParameters } from '../../../../validation/input-params'
|
|
7
|
-
import {
|
|
8
|
-
AdapterRequestParams,
|
|
9
|
-
ProviderRequestBody,
|
|
10
|
-
buildBatchedRequestBody,
|
|
11
|
-
constructEntry,
|
|
12
|
-
ProviderResponseBody,
|
|
13
|
-
} from '../cryptoUtils'
|
|
14
|
-
|
|
15
|
-
export const inputParameters: InputParameters = {
|
|
16
|
-
overrides: baseInputParameters['overrides'],
|
|
17
|
-
coinid: {
|
|
18
|
-
description: 'The CoinGecko id or to query',
|
|
19
|
-
required: false,
|
|
20
|
-
},
|
|
21
|
-
base: {
|
|
22
|
-
aliases: ['from', 'coin'],
|
|
23
|
-
description: 'The symbol of symbols of the currency to query',
|
|
24
|
-
required: false,
|
|
25
|
-
},
|
|
26
|
-
quote: {
|
|
27
|
-
aliases: ['to', 'market'],
|
|
28
|
-
description: 'The symbol of the currency to convert to',
|
|
29
|
-
required: true,
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const batchEndpointTransport = new BatchWarmingTransport({
|
|
34
|
-
prepareRequest: (
|
|
35
|
-
params: AdapterRequestParams[],
|
|
36
|
-
context: AdapterContext,
|
|
37
|
-
): AxiosRequestConfig<ProviderRequestBody> => {
|
|
38
|
-
return buildBatchedRequestBody(params, context.adapterConfig)
|
|
39
|
-
},
|
|
40
|
-
parseResponse: (
|
|
41
|
-
params: AdapterRequestParams[],
|
|
42
|
-
res: AxiosResponse<ProviderResponseBody>,
|
|
43
|
-
): ProviderResult<AdapterRequestParams>[] => {
|
|
44
|
-
const entries = [] as ProviderResult<AdapterRequestParams>[]
|
|
45
|
-
for (const requestPayload of params) {
|
|
46
|
-
const entry = constructEntry(res, requestPayload, requestPayload.quote.toLowerCase())
|
|
47
|
-
// NOTE: the `entries` array is going to be shorter than the `params` array if one of the params has a bad token.
|
|
48
|
-
// Is that okay? I did this to avoid caching an invalid value for transient DP issues. Just want to make
|
|
49
|
-
// sure this works within the core framework
|
|
50
|
-
if (entry) {
|
|
51
|
-
entries.push(entry)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return entries
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
export const endpoint: AdapterEndpoint = {
|
|
59
|
-
name: 'crypto',
|
|
60
|
-
aliases: ['crypto-batched', 'batched', 'batch'],
|
|
61
|
-
transport: batchEndpointTransport,
|
|
62
|
-
inputParameters,
|
|
63
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios'
|
|
2
|
-
import { AdapterEndpoint, AdapterContext } from '../../../../adapter'
|
|
3
|
-
import { BatchWarmingTransport } from '../../../../transports/batch-warming'
|
|
4
|
-
import { ProviderResult } from '../../../../util'
|
|
5
|
-
import {
|
|
6
|
-
buildGlobalRequestBody,
|
|
7
|
-
AdapterRequestParams,
|
|
8
|
-
ProviderResponseBody,
|
|
9
|
-
constructEntry,
|
|
10
|
-
inputParameters,
|
|
11
|
-
} from '../globalUtils'
|
|
12
|
-
|
|
13
|
-
const batchEndpointTransport = new BatchWarmingTransport({
|
|
14
|
-
prepareRequest: (
|
|
15
|
-
params: AdapterRequestParams[],
|
|
16
|
-
context: AdapterContext,
|
|
17
|
-
): AxiosRequestConfig<never> => {
|
|
18
|
-
return buildGlobalRequestBody(context.adapterConfig)
|
|
19
|
-
},
|
|
20
|
-
parseResponse: (
|
|
21
|
-
params: AdapterRequestParams[],
|
|
22
|
-
res: AxiosResponse<ProviderResponseBody>,
|
|
23
|
-
): ProviderResult<AdapterRequestParams>[] => {
|
|
24
|
-
const entries = [] as ProviderResult<AdapterRequestParams>[]
|
|
25
|
-
for (const requestPayload of params) {
|
|
26
|
-
const entry = constructEntry(res, requestPayload, 'market_cap_percentage')
|
|
27
|
-
if (entry) {
|
|
28
|
-
entries.push(entry)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return entries
|
|
32
|
-
},
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
export const endpoint: AdapterEndpoint = {
|
|
36
|
-
name: 'dominance',
|
|
37
|
-
aliases: ['market_cap_percentage'],
|
|
38
|
-
transport: batchEndpointTransport,
|
|
39
|
-
inputParameters,
|
|
40
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios'
|
|
2
|
-
import { AdapterEndpoint, AdapterContext } from '../../../../adapter'
|
|
3
|
-
import { BatchWarmingTransport } from '../../../../transports/batch-warming'
|
|
4
|
-
import { ProviderResult } from '../../../../util'
|
|
5
|
-
import {
|
|
6
|
-
buildGlobalRequestBody,
|
|
7
|
-
AdapterRequestParams,
|
|
8
|
-
ProviderResponseBody,
|
|
9
|
-
constructEntry,
|
|
10
|
-
inputParameters,
|
|
11
|
-
} from '../globalUtils'
|
|
12
|
-
|
|
13
|
-
const batchEndpointTransport = new BatchWarmingTransport({
|
|
14
|
-
prepareRequest: (
|
|
15
|
-
params: AdapterRequestParams[],
|
|
16
|
-
context: AdapterContext,
|
|
17
|
-
): AxiosRequestConfig<never> => {
|
|
18
|
-
return buildGlobalRequestBody(context.adapterConfig)
|
|
19
|
-
},
|
|
20
|
-
parseResponse: (
|
|
21
|
-
params: AdapterRequestParams[],
|
|
22
|
-
res: AxiosResponse<ProviderResponseBody>,
|
|
23
|
-
): ProviderResult<AdapterRequestParams>[] => {
|
|
24
|
-
const entries = [] as ProviderResult<AdapterRequestParams>[]
|
|
25
|
-
for (const requestPayload of params) {
|
|
26
|
-
const entry = constructEntry(res, requestPayload, 'total_market_cap')
|
|
27
|
-
if (entry) {
|
|
28
|
-
entries.push(entry)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return entries
|
|
32
|
-
},
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
export const endpoint: AdapterEndpoint = {
|
|
36
|
-
name: 'globalmarketcap',
|
|
37
|
-
aliases: ['total_market_cap'],
|
|
38
|
-
transport: batchEndpointTransport,
|
|
39
|
-
inputParameters,
|
|
40
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { endpoint as coins } from './coins'
|
|
2
|
-
export { endpoint as crypto } from './crypto'
|
|
3
|
-
export { endpoint as cryptoMarketcap } from './crypto-marketcap'
|
|
4
|
-
export { endpoint as globalMarketcap } from './global-marketcap'
|
|
5
|
-
export { endpoint as dominance } from './dominance'
|
|
6
|
-
export { endpoint as cryptoVolume } from './crypto-volume'
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios'
|
|
2
|
-
import { PRO_API_ENDPOINT, DEFAULT_API_ENDPOINT } from './config'
|
|
3
|
-
import { AdapterConfig } from '../../../config'
|
|
4
|
-
import { makeLogger } from '../../../util/logger'
|
|
5
|
-
import { InputParameters } from '../../../validation'
|
|
6
|
-
|
|
7
|
-
const logger = makeLogger('CoinGecko Global Batched')
|
|
8
|
-
|
|
9
|
-
export const inputParameters: InputParameters = {
|
|
10
|
-
market: {
|
|
11
|
-
aliases: ['to', 'quote'],
|
|
12
|
-
description: 'The ticker of the coin to query',
|
|
13
|
-
required: true,
|
|
14
|
-
},
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface AdapterRequestParams {
|
|
18
|
-
market: string
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface ProviderResponseBody {
|
|
22
|
-
data: {
|
|
23
|
-
active_cryptocurrencies: number
|
|
24
|
-
upcoming_icos: number
|
|
25
|
-
ongoing_icos: number
|
|
26
|
-
ended_icos: number
|
|
27
|
-
markets: number
|
|
28
|
-
total_market_cap: Record<string, number>
|
|
29
|
-
total_volume: Record<string, number>
|
|
30
|
-
market_cap_percentage: Record<string, number>
|
|
31
|
-
market_cap_change_percentage_24h_usd: number
|
|
32
|
-
updated_at: number
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface ResultEntry {
|
|
37
|
-
value: number
|
|
38
|
-
params: AdapterRequestParams
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const buildGlobalRequestBody = (config: AdapterConfig): AxiosRequestConfig<never> => {
|
|
42
|
-
const apiKey = {
|
|
43
|
-
x_cg_pro_api_key: config.API_KEY,
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
baseURL: config.API_KEY ? PRO_API_ENDPOINT : DEFAULT_API_ENDPOINT,
|
|
47
|
-
url: '/global',
|
|
48
|
-
method: 'GET',
|
|
49
|
-
params: apiKey,
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const constructEntry = (
|
|
54
|
-
res: AxiosResponse<ProviderResponseBody>,
|
|
55
|
-
requestPayload: AdapterRequestParams,
|
|
56
|
-
resultPath: 'total_market_cap' | 'market_cap_percentage',
|
|
57
|
-
): ResultEntry | undefined => {
|
|
58
|
-
const resultData = res.data.data
|
|
59
|
-
if (!resultData) {
|
|
60
|
-
logger.warn(`Data not found".`)
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
const totalMarketcapData = resultData[resultPath]
|
|
64
|
-
if (!totalMarketcapData) {
|
|
65
|
-
logger.warn(`Data for "${resultPath}" not found".`)
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
const result = totalMarketcapData[requestPayload.market.toLowerCase()]
|
|
69
|
-
if (!result) {
|
|
70
|
-
logger.warn(`Data for "${requestPayload.market}" not found".`)
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
const entry = {
|
|
74
|
-
params: requestPayload,
|
|
75
|
-
value: result,
|
|
76
|
-
} as ResultEntry
|
|
77
|
-
return entry
|
|
78
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Adapter } from '../../../../src/adapter'
|
|
2
|
-
import overrides from './config/overrides.json'
|
|
3
|
-
import {
|
|
4
|
-
coins,
|
|
5
|
-
crypto,
|
|
6
|
-
cryptoVolume,
|
|
7
|
-
cryptoMarketcap,
|
|
8
|
-
dominance,
|
|
9
|
-
globalMarketcap,
|
|
10
|
-
} from './endpoint'
|
|
11
|
-
|
|
12
|
-
export const adapter: Adapter = {
|
|
13
|
-
defaultEndpoint: 'crypto',
|
|
14
|
-
name: 'coingecko',
|
|
15
|
-
endpoints: [crypto, coins, cryptoMarketcap, cryptoVolume, dominance, globalMarketcap],
|
|
16
|
-
overrides: (overrides as Record<string, Record<string, string>>)['coingecko'],
|
|
17
|
-
}
|