Browse Source

Submit the changes requested on the pull requests #1736 revision 2

pull/1736/head
Mirio 3 years ago
parent
commit
5f7e1976f6
  1. 15
      apps/api/src/services/data-provider/coingecko/coingecko.service.ts
  2. 4
      apps/api/src/services/data-provider/data-provider.module.ts

15
apps/api/src/services/data-provider/coingecko/coingecko.service.ts

@ -20,7 +20,6 @@ import { format, differenceInDays, addDays, subDays } from 'date-fns';
@Injectable() @Injectable()
export class CoinGeckoService implements DataProviderInterface { export class CoinGeckoService implements DataProviderInterface {
private readonly URL = 'https://api.coingecko.com/api/v3'; private readonly URL = 'https://api.coingecko.com/api/v3';
private COINLIST = [];
private baseCurrency: string; private baseCurrency: string;
private DB = {}; private DB = {};
@ -51,15 +50,6 @@ export class CoinGeckoService implements DataProviderInterface {
return {}; return {};
} }
private async getCoinList() {
// TODO: Some caching refresh after X?
if (this.COINLIST.length == 0) {
const req = bent(`${this.URL}/coins/list`, 'GET', 'json', 200);
const response = await req();
this.COINLIST = response;
}
}
public async getAssetProfile( public async getAssetProfile(
aSymbol: string aSymbol: string
): Promise<Partial<SymbolProfile>> { ): Promise<Partial<SymbolProfile>> {
@ -177,11 +167,12 @@ export class CoinGeckoService implements DataProviderInterface {
public async search(aQuery: string): Promise<{ items: LookupItem[] }> { public async search(aQuery: string): Promise<{ items: LookupItem[] }> {
const items: LookupItem[] = []; const items: LookupItem[] = [];
await this.getCoinList();
if (aQuery.length <= 2) { if (aQuery.length <= 2) {
return { items }; return { items };
} }
for (const coiniter of this.COINLIST) { const req = bent(`${this.URL}/search?query=${aQuery}`, 'GET', 'json', 200);
const response = await req();
for (const coiniter of response.coins) {
if (coiniter.id.toLowerCase().includes(aQuery)) { if (coiniter.id.toLowerCase().includes(aQuery)) {
items.push({ items.push({
symbol: coiniter.id.toUpperCase(), symbol: coiniter.id.toUpperCase(),

4
apps/api/src/services/data-provider/data-provider.module.ts

@ -42,7 +42,7 @@ import { DataProviderService } from './data-provider.service';
provide: 'DataProviderInterfaces', provide: 'DataProviderInterfaces',
useFactory: ( useFactory: (
alphaVantageService, alphaVantageService,
CoinGeckoService, coinGeckoService,
eodHistoricalDataService, eodHistoricalDataService,
googleSheetsService, googleSheetsService,
manualService, manualService,
@ -50,7 +50,7 @@ import { DataProviderService } from './data-provider.service';
yahooFinanceService yahooFinanceService
) => [ ) => [
alphaVantageService, alphaVantageService,
CoinGeckoService, coinGeckoService,
eodHistoricalDataService, eodHistoricalDataService,
googleSheetsService, googleSheetsService,
manualService, manualService,

Loading…
Cancel
Save