|
|
@ -105,7 +105,10 @@ export class ManualService implements DataProviderInterface { |
|
|
return {}; |
|
|
return {}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const value = await this.scrape(symbolProfile.scraperConfiguration); |
|
|
const value = await this.scrape({ |
|
|
|
|
|
symbol, |
|
|
|
|
|
scraperConfiguration: symbolProfile.scraperConfiguration |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
[symbol]: { |
|
|
[symbol]: { |
|
|
@ -170,7 +173,10 @@ export class ManualService implements DataProviderInterface { |
|
|
symbolProfilesWithScraperConfigurationAndInstantMode.map( |
|
|
symbolProfilesWithScraperConfigurationAndInstantMode.map( |
|
|
async ({ scraperConfiguration, symbol }) => { |
|
|
async ({ scraperConfiguration, symbol }) => { |
|
|
try { |
|
|
try { |
|
|
const marketPrice = await this.scrape(scraperConfiguration); |
|
|
const marketPrice = await this.scrape({ |
|
|
|
|
|
scraperConfiguration, |
|
|
|
|
|
symbol |
|
|
|
|
|
}); |
|
|
return { marketPrice, symbol }; |
|
|
return { marketPrice, symbol }; |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
Logger.error( |
|
|
Logger.error( |
|
|
@ -267,13 +273,23 @@ export class ManualService implements DataProviderInterface { |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async test(scraperConfiguration: ScraperConfiguration) { |
|
|
public async test({ |
|
|
return this.scrape(scraperConfiguration); |
|
|
scraperConfiguration, |
|
|
|
|
|
symbol |
|
|
|
|
|
}: { |
|
|
|
|
|
scraperConfiguration: ScraperConfiguration; |
|
|
|
|
|
symbol: string; |
|
|
|
|
|
}) { |
|
|
|
|
|
return this.scrape({ scraperConfiguration, symbol }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private async scrape( |
|
|
private async scrape({ |
|
|
scraperConfiguration: ScraperConfiguration |
|
|
scraperConfiguration, |
|
|
): Promise<number> { |
|
|
symbol |
|
|
|
|
|
}: { |
|
|
|
|
|
scraperConfiguration: ScraperConfiguration; |
|
|
|
|
|
symbol: string; |
|
|
|
|
|
}): Promise<number> { |
|
|
let locale = scraperConfiguration.locale; |
|
|
let locale = scraperConfiguration.locale; |
|
|
|
|
|
|
|
|
const response = await fetch(scraperConfiguration.url, { |
|
|
const response = await fetch(scraperConfiguration.url, { |
|
|
@ -283,6 +299,12 @@ export class ManualService implements DataProviderInterface { |
|
|
) |
|
|
) |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (!response.ok) { |
|
|
|
|
|
throw new Error( |
|
|
|
|
|
`Failed to scrape the market price for ${symbol} (${this.getName()}): ${response.status} ${response.statusText} at ${scraperConfiguration.url}` |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let value: string; |
|
|
let value: string; |
|
|
|
|
|
|
|
|
if (response.headers.get('content-type')?.includes('application/json')) { |
|
|
if (response.headers.get('content-type')?.includes('application/json')) { |
|
|
|