aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/src/scripts
diff options
context:
space:
mode:
authorXianny <8582774+xianny@users.noreply.github.com>2018-12-06 08:05:06 +0800
committerGitHub <noreply@github.com>2018-12-06 08:05:06 +0800
commit78d0ab1aa2393b7a0b21108b9811e0b0a4406faf (patch)
tree35fdf1e88cda45c4e99da4ea4f06dc1b4451b629 /packages/pipeline/src/scripts
parent21122f0137c39835e5cf15e1a5c2bdbd20030611 (diff)
downloaddexon-sol-tools-78d0ab1aa2393b7a0b21108b9811e0b0a4406faf.tar
dexon-sol-tools-78d0ab1aa2393b7a0b21108b9811e0b0a4406faf.tar.gz
dexon-sol-tools-78d0ab1aa2393b7a0b21108b9811e0b0a4406faf.tar.bz2
dexon-sol-tools-78d0ab1aa2393b7a0b21108b9811e0b0a4406faf.tar.lz
dexon-sol-tools-78d0ab1aa2393b7a0b21108b9811e0b0a4406faf.tar.xz
dexon-sol-tools-78d0ab1aa2393b7a0b21108b9811e0b0a4406faf.tar.zst
dexon-sol-tools-78d0ab1aa2393b7a0b21108b9811e0b0a4406faf.zip
Fix/pipeline/ohlcv (#1393)
The OHLCV script in data pipeline quits early when we get no data from Crypto Compare. Sometimes Crypto Compare gives us a valid empty response (e.g. when we query for way back in time) and we need to just continue. This adds better filtering for the types of Crypto Compare responses to detect when we should continue and when we should really quit.
Diffstat (limited to 'packages/pipeline/src/scripts')
-rw-r--r--packages/pipeline/src/scripts/pull_ohlcv_cryptocompare.ts38
1 files changed, 16 insertions, 22 deletions
diff --git a/packages/pipeline/src/scripts/pull_ohlcv_cryptocompare.ts b/packages/pipeline/src/scripts/pull_ohlcv_cryptocompare.ts
index 6979cd10e..7377a64d8 100644
--- a/packages/pipeline/src/scripts/pull_ohlcv_cryptocompare.ts
+++ b/packages/pipeline/src/scripts/pull_ohlcv_cryptocompare.ts
@@ -10,11 +10,9 @@ import { fetchOHLCVTradingPairsAsync, TradingPair } from '../utils/get_ohlcv_tra
const SOURCE_NAME = 'CryptoCompare';
const TWO_HOURS_AGO = new Date().getTime() - 2 * 60 * 60 * 1000; // tslint:disable-line:custom-no-magic-numbers
-const ONE_HOUR_AGO = new Date().getTime() - 60 * 60 * 1000; // tslint:disable-line:custom-no-magic-numbers
-const ONE_SECOND = 1000;
const MAX_CONCURRENT_REQUESTS = parseInt(process.env.CRYPTOCOMPARE_MAX_CONCURRENT_REQUESTS || '14', 10); // tslint:disable-line:custom-no-magic-numbers
-const EARLIEST_BACKFILL_DATE = process.env.OHLCV_EARLIEST_BACKFILL_DATE || '2010-09-01'; // the time when BTC/USD info starts appearing on Crypto Compare
+const EARLIEST_BACKFILL_DATE = process.env.OHLCV_EARLIEST_BACKFILL_DATE || '2014-06-01';
const EARLIEST_BACKFILL_TIME = new Date(EARLIEST_BACKFILL_DATE).getTime();
let connection: Connection;
@@ -60,28 +58,24 @@ async function fetchAndSaveAsync(
if (pair.latestSavedTime > TWO_HOURS_AGO) {
break;
}
- const rawRecords = await source.getHourlyOHLCVAsync(pair);
- const records = rawRecords.filter(rec => {
- return rec.time * ONE_SECOND < ONE_HOUR_AGO && rec.time * ONE_SECOND > pair.latestSavedTime;
- }); // Crypto Compare can take ~30mins to finalise records
- if (records.length === 0) {
- console.log(`No more records, stopping task for ${JSON.stringify(pair)}`);
- break;
- }
- const metadata: OHLCVMetadata = {
- exchange: source.default_exchange,
- fromSymbol: pair.fromSymbol,
- toSymbol: pair.toSymbol,
- source: SOURCE_NAME,
- observedTimestamp: jobTime,
- interval: source.intervalBetweenRecords,
- };
- const parsedRecords = parseRecords(records, metadata);
try {
- await saveRecordsAsync(repository, parsedRecords);
+ const records = await source.getHourlyOHLCVAsync(pair);
+ console.log(`Retrieved ${records.length} records for ${JSON.stringify(pair)}`);
+ if (records.length > 0) {
+ const metadata: OHLCVMetadata = {
+ exchange: source.default_exchange,
+ fromSymbol: pair.fromSymbol,
+ toSymbol: pair.toSymbol,
+ source: SOURCE_NAME,
+ observedTimestamp: jobTime,
+ interval: source.intervalBetweenRecords,
+ };
+ const parsedRecords = parseRecords(records, metadata);
+ await saveRecordsAsync(repository, parsedRecords);
+ }
i++;
} catch (err) {
- console.log(`Error saving OHLCVRecords, stopping task for ${JSON.stringify(pair)} [${err}]`);
+ console.log(`Error scraping OHLCVRecords, stopping task for ${JSON.stringify(pair)} [${err}]`);
break;
}
}