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

Support Pro API keys on Coingecko #602

Merged
merged 1 commit into from
Jun 9, 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
5 changes: 4 additions & 1 deletion coingecko/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ export const NAME = 'COINGECKO'

export const DEFAULT_ENDPOINT = 'price'
export const DEFAULT_API_ENDPOINT = 'https://api.coingecko.com/api/v3'
export const PRO_API_ENDPOINT = 'https://pro-api.coingecko.com/api/v3'

export const makeConfig = (prefix?: string): Config => {
const config = Requester.getDefaultConfig(prefix)
config.api.baseURL = config.api.baseUrl || DEFAULT_API_ENDPOINT
if (!config.api.baseURL) {
config.api.baseURL = config.apiKey !== undefined ? PRO_API_ENDPOINT : DEFAULT_API_ENDPOINT
}
return config
}
3 changes: 3 additions & 0 deletions coingecko/src/endpoint/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const execute: ExecuteWithConfig<Config> = async (request, config) => {
const options = {
...config.api,
url,
params: {
x_cg_pro_api_key: config.apiKey,
},
}

const response = await Requester.request(options, customError)
Expand Down
4 changes: 4 additions & 0 deletions coingecko/src/endpoint/price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const getCoinId = async (config: Config, symbol: string): Promise<string> => {
const options = {
...config.api,
url,
params: {
x_cg_pro_api_key: config.apiKey,
},
}

const response = await Requester.request(options, customError)
Expand Down Expand Up @@ -56,6 +59,7 @@ export const execute: ExecuteWithConfig<Config> = async (request, config) => {
const params = {
ids: coin,
vs_currencies: quote,
x_cg_pro_api_key: config.apiKey,
}

const options = {
Expand Down