Skip to content

Commit

Permalink
fixes #19 missing csv headers issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ivoputzer committed Oct 17, 2023
1 parent b9d47dc commit 36c9d19
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions bin/build-coinbase.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ for (const file of await readCache(byExchange('coinbase'))) {
console.log('bin/build-coinbase @load readCache:', file)

await mkdir(`www/api/${id}`, { recursive: true })
await convertJsonl(writeCsv, source, `www/api/${id}/${interval}.csv`, shortDateFor(interval))
await convertJsonl(writeJson, source, `www/api/${id}/${interval}.json`, shortDateFor(interval))
}

function convertJsonl (write, src, dst, replacer) { // todo: this could be maybe better placed in lib/jsonl.mjs or lib/cache.mjs
console.time(`bin/build-coinbase @async ${write.name}: ${dst} time`)
return src
.pipe(parseJsonl({ objectMode: true }))
.pipe(write({ objectMode: true, replacer }))
.pipe(createWriteStream(dst))
.on('close', console.timeEnd.bind(console, `bin/build-coinbase @async ${write.name}: ${dst} time`))
;(function (write, src, dst, replacer) { // todo: this could be maybe better placed in lib/jsonl.mjs or lib/cache.mjs
console.time(`bin/build-coinbase @async ${write.name}: ${dst} time`)
return src
.pipe(parseJsonl({ objectMode: true }))
.pipe(write(['date', 'open', 'high', 'low', 'close', 'volume'], { objectMode: true, replacer }))
.pipe(createWriteStream(dst))
.on('close', console.timeEnd.bind(console, `bin/build-coinbase @async ${write.name}: ${dst} time`))
})(writeCsv, source, `www/api/${id}/${interval}.csv`, shortDateFor(interval))

;(function convertJsonl (write, src, dst, replacer) { // todo: this could be maybe better placed in lib/jsonl.mjs or lib/cache.mjs
console.time(`bin/build-coinbase @async ${write.name}: ${dst} time`)
return src
.pipe(parseJsonl({ objectMode: true }))
.pipe(write({ objectMode: true, replacer }))
.pipe(createWriteStream(dst))
.on('close', console.timeEnd.bind(console, `bin/build-coinbase @async ${write.name}: ${dst} time`))
})(writeJson, source, `www/api/${id}/${interval}.json`, shortDateFor(interval))
}

0 comments on commit 36c9d19

Please sign in to comment.