|
|
@ -65,19 +65,13 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
const abortController = new AbortController(); |
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
abortController.abort(); |
|
|
|
|
|
}, this.configurationService.get('REQUEST_TIMEOUT')); |
|
|
|
|
|
|
|
|
|
|
|
let url = `${this.apiUrl}/coins/${symbol}`; |
|
|
let url = `${this.apiUrl}/coins/${symbol}`; |
|
|
if (symbol.startsWith('nft:')) { |
|
|
if (symbol.startsWith('nft:')) { |
|
|
response.assetSubClass = AssetSubClass.NFT; |
|
|
response.assetSubClass = AssetSubClass.NFT; |
|
|
url = `${this.apiUrl}/nfts/${symbol.replace('nft:', '')}`; |
|
|
url = `${this.apiUrl}/nfts/${symbol.replace('nft:', '')}`; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const { name } = await got(url, { |
|
|
const { name } = await fetch(url, { |
|
|
headers: this.headers, |
|
|
headers: this.headers, |
|
|
signal: AbortSignal.timeout( |
|
|
signal: AbortSignal.timeout( |
|
|
this.configurationService.get('REQUEST_TIMEOUT') |
|
|
this.configurationService.get('REQUEST_TIMEOUT') |
|
|
@ -122,39 +116,24 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
[symbol: string]: { [date: string]: DataProviderHistoricalResponse }; |
|
|
[symbol: string]: { [date: string]: DataProviderHistoricalResponse }; |
|
|
}> { |
|
|
}> { |
|
|
try { |
|
|
try { |
|
|
const abortController = new AbortController(); |
|
|
let url = `${this.apiUrl}/coins/${symbol}/market_chart/range?vs_currency=${DEFAULT_CURRENCY.toLowerCase()}&from=${getUnixTime( |
|
|
|
|
|
from |
|
|
setTimeout(() => { |
|
|
)}&to=${getUnixTime(to)}`;
|
|
|
abortController.abort(); |
|
|
|
|
|
}, requestTimeout); |
|
|
|
|
|
|
|
|
|
|
|
let url = `${this.apiUrl}/coins/${symbol}/market_chart/range?vs_currency=${DEFAULT_CURRENCY.toLowerCase()}&from=${getUnixTime(from)}&to=${getUnixTime(to)}`; |
|
|
|
|
|
let field = 'prices'; |
|
|
let field = 'prices'; |
|
|
|
|
|
|
|
|
if (symbol.startsWith('nft:')) { |
|
|
if (symbol.startsWith('nft:')) { |
|
|
// note: pro only
|
|
|
// note: pro only
|
|
|
url = `${this.apiUrl}/nfts/${symbol.replace('nft:', '')}/market_chart?days=max`; |
|
|
url = `${this.apiUrl}/nfts/${symbol.replace( |
|
|
|
|
|
'nft:', |
|
|
|
|
|
'' |
|
|
|
|
|
)}/market_chart?days=max`;
|
|
|
field = 'floor_prices_usd'; |
|
|
field = 'floor_prices_usd'; |
|
|
} |
|
|
} |
|
|
console.log(url); |
|
|
|
|
|
|
|
|
|
|
|
const res = await got(url, { |
|
|
const { error, status, ...data } = await fetch(url, { |
|
|
headers: this.headers, |
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
signal: abortController.signal |
|
|
|
|
|
}).json<any>(); |
|
|
|
|
|
|
|
|
|
|
|
const { error, prices, status } = await fetch( |
|
|
|
|
|
`${ |
|
|
|
|
|
this.apiUrl |
|
|
|
|
|
}/coins/${symbol}/market_chart/range?vs_currency=${DEFAULT_CURRENCY.toLowerCase()}&from=${getUnixTime( |
|
|
|
|
|
from |
|
|
|
|
|
)}&to=${getUnixTime(to)}`,
|
|
|
|
|
|
{ |
|
|
|
|
|
headers: this.headers, |
|
|
headers: this.headers, |
|
|
signal: AbortSignal.timeout(requestTimeout) |
|
|
signal: AbortSignal.timeout(requestTimeout) |
|
|
} |
|
|
}).then((res) => res.json()); |
|
|
).then((res) => res.json()); |
|
|
|
|
|
|
|
|
|
|
|
if (error?.status) { |
|
|
if (error?.status) { |
|
|
throw new Error(error.status.error_message); |
|
|
throw new Error(error.status.error_message); |
|
|
@ -164,7 +143,11 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
throw new Error(status.error_message); |
|
|
throw new Error(status.error_message); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const prices = res[field]; |
|
|
const prices = data[field]; |
|
|
|
|
|
|
|
|
|
|
|
if (!prices) { |
|
|
|
|
|
throw new Error(`No ${field} data available for ${symbol}`); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const result: { |
|
|
const result: { |
|
|
[symbol: string]: { [date: string]: DataProviderHistoricalResponse }; |
|
|
[symbol: string]: { [date: string]: DataProviderHistoricalResponse }; |
|
|
@ -208,21 +191,8 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
const abortController = new AbortController(); |
|
|
// note: simple price endpoint does not currently support nft ids
|
|
|
|
|
|
const quotes = await fetch( |
|
|
setTimeout(() => { |
|
|
|
|
|
abortController.abort(); |
|
|
|
|
|
}, requestTimeout); |
|
|
|
|
|
|
|
|
|
|
|
//const quotes = await fetch(
|
|
|
|
|
|
// `${this.apiUrl}/simple/price?ids=${symbols.join(
|
|
|
|
|
|
// ','
|
|
|
|
|
|
// )}&vs_currencies=${DEFAULT_CURRENCY.toLowerCase()}`,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// note: simple price endpoint currently does not support list of nfts
|
|
|
|
|
|
// (submitted a ticket with this request)
|
|
|
|
|
|
const quotes = await got( |
|
|
|
|
|
`${this.apiUrl}/simple/price?ids=${symbols |
|
|
`${this.apiUrl}/simple/price?ids=${symbols |
|
|
.filter((s) => !s.startsWith('nft:')) |
|
|
.filter((s) => !s.startsWith('nft:')) |
|
|
.join(',')}&vs_currencies=${DEFAULT_CURRENCY.toLowerCase()}`,
|
|
|
.join(',')}&vs_currencies=${DEFAULT_CURRENCY.toLowerCase()}`,
|
|
|
@ -245,12 +215,15 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
// nfts
|
|
|
// nfts
|
|
|
for (const symbol of symbols.filter((s) => s.startsWith('nft:'))) { |
|
|
for (const symbol of symbols.filter((s) => s.startsWith('nft:'))) { |
|
|
const s = symbol.replace('nft:', ''); |
|
|
const s = symbol.replace('nft:', ''); |
|
|
const { floor_price } = await got(`${this.apiUrl}/nfts/${s}`, { |
|
|
const { floor_price } = await fetch(`${this.apiUrl}/nfts/${s}`, { |
|
|
headers: this.headers, |
|
|
headers: this.headers, |
|
|
// @ts-ignore
|
|
|
signal: AbortSignal.timeout(requestTimeout) |
|
|
signal: abortController.signal |
|
|
}).then((res) => res.json()); |
|
|
}).json<any>(); |
|
|
|
|
|
console.log(floor_price); |
|
|
if (!floor_price) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
response[symbol] = { |
|
|
response[symbol] = { |
|
|
currency: DEFAULT_CURRENCY, |
|
|
currency: DEFAULT_CURRENCY, |
|
|
dataProviderInfo: this.getDataProviderInfo(), |
|
|
dataProviderInfo: this.getDataProviderInfo(), |
|
|
@ -287,26 +260,13 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
let items: LookupItem[] = []; |
|
|
let items: LookupItem[] = []; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
const abortController = new AbortController(); |
|
|
const { coins, nfts } = await fetch( |
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
abortController.abort(); |
|
|
|
|
|
}, this.configurationService.get('REQUEST_TIMEOUT')); |
|
|
|
|
|
|
|
|
|
|
|
const { coins } = await fetch(`${this.apiUrl}/search?query=${query}`, { |
|
|
|
|
|
headers: this.headers, |
|
|
|
|
|
signal: AbortSignal.timeout(requestTimeout) |
|
|
|
|
|
}).then((res) => res.json()); |
|
|
|
|
|
|
|
|
|
|
|
// note: this search does return nfts in a separate array
|
|
|
|
|
|
const { coins, nfts } = await got( |
|
|
|
|
|
`${this.apiUrl}/search?query=${query}`, |
|
|
`${this.apiUrl}/search?query=${query}`, |
|
|
{ |
|
|
{ |
|
|
headers: this.headers, |
|
|
headers: this.headers, |
|
|
// @ts-ignore
|
|
|
signal: AbortSignal.timeout(requestTimeout) |
|
|
signal: abortController.signal |
|
|
|
|
|
} |
|
|
} |
|
|
).json<any>(); |
|
|
).then((res) => res.json()); |
|
|
|
|
|
|
|
|
let itemsCoins = coins.map(({ id: symbol, name }) => { |
|
|
let itemsCoins = coins.map(({ id: symbol, name }) => { |
|
|
return { |
|
|
return { |
|
|
|