-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in regards to #16: still needs to be documented on openapi.json
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env node --experimental-modules | ||
|
||
import { createReadStream, createWriteStream } from 'node:fs' | ||
import { mkdir } from 'node:fs/promises' | ||
import { EOL } from 'node:os' | ||
|
||
import { readCache, byExchange, readLastCachedJsonLineOf } from '../lib/cache.mjs' | ||
import { csvDateReplacer, jsonDateReviver } from '../lib/date.mjs' | ||
|
||
console.log('bin/build-coinbase-latest load: data/* ') | ||
|
||
try { | ||
console.time('bin/build-coinbase-latest create: @api/latest.{format:json,csv} time') | ||
|
||
await mkdir('www/api', { recursive: true }) | ||
console.log('bin/build-coinbase-latest exists: www/api/') | ||
|
||
const latestJson = createWriteStream('www/api/latest.json') | ||
latestJson.write('[') | ||
|
||
const latestCsv = createWriteStream('www/api/latest.csv') | ||
latestCsv.write('id,interval,date,open,high,low,close,volume' + EOL) | ||
|
||
let isFirstLine = true | ||
for (const file of await readCache(byExchange('coinbase'))) { | ||
console.time(`→ load: ${file} appendLine: @api/latest.{format:json,csv} time`) | ||
const lastCachedCandle = await readLastCachedJsonLineOf(createReadStream(file), jsonDateReviver) | ||
const [, , id, interval] = file.split(/[/,.]/) | ||
if (isFirstLine) { | ||
isFirstLine = false | ||
latestJson.write(JSON.stringify([id, interval, ...lastCachedCandle])) | ||
} else { | ||
latestJson.write(`,${JSON.stringify([id, interval, ...lastCachedCandle])}`) | ||
} | ||
latestCsv.write(`${id},${interval},${JSON.stringify(lastCachedCandle, csvDateReplacer).slice(1, -1).replaceAll('"', '')}${EOL}`) | ||
console.timeEnd(`→ load: ${file} appendLine: @api/latest.{format:json,csv} time`) | ||
} | ||
latestJson.write(']' + EOL) | ||
} catch (error) { | ||
console.error(error) | ||
} finally { | ||
console.timeEnd('bin/build-coinbase-latest create: @api/latest.{format:json,csv} time') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
"build-sitemap": "node --experimental-modules bin/build-sitemap.mjs", | ||
"build-coinbase": "node --experimental-modules bin/build-coinbase.mjs", | ||
"build-coinbase-history": "node --experimental-modules bin/build-coinbase-history.mjs", | ||
"test": "NODE_V8_COVERAGE=coverage node --experimental-modules --test --test-reporter spec --experimental-test-coverage test", | ||
"build-coinbase-latest": "node --experimental-modules bin/build-coinbase-latest.mjs", | ||
"watch": "serve www & node --experimental-modules --test --test-reporter dot --watch test & wait" | ||
}, | ||
"author": "Ivo von Putzer Reibegg <[email protected]> (https://github.com/ivoputzer)", | ||
|