Skip to content
This repository was archived by the owner on Aug 12, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e799a4c

Browse files
committedJul 18, 2020
Enhance error reporting
1 parent 58bf1a1 commit e799a4c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed
 

‎src/util/crypto-compare.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,21 @@ const getPrice = async (symbol, date) => {
3939
const timestamp = moment(date).unix();
4040
const method = moment().diff(date, 'day') >= 7 ? 'histohour' : 'histominute';
4141
const url = `${API_ENDPOINT}/${method}?fsym=${symbol}&tsym=USD&limit=1&toTs=${timestamp}&tryConversion=false&api_key=${apiKey}`;
42-
const result = await callApi(url);
43-
const price = _.get(result, 'Data.[1]', null);
42+
const responseData = await callApi(url);
43+
const price = _.get(responseData, 'Data.[1].close', null);
4444

4545
// The Cryptocompare API rate limits at 20 requests per second. We artificially
4646
// limit to 10 requests per second (one every one hundred milliseconds) to be safe.
4747
await bluebird.delay(100);
4848

4949
if (price === null) {
50+
logError(`Unable to get USD price of ${symbol} on ${date}`, {
51+
responseData,
52+
});
5053
return null;
5154
}
5255

53-
return { [symbol]: { USD: price.close } };
56+
return { [symbol]: { USD: price } };
5457
};
5558

5659
module.exports = {

0 commit comments

Comments
 (0)