Convert from coin price data to Binance API response format:
Supported chart type
- H1
- H4
- D1
Prerequisites:
- Node.js version 18
- Redis server is running locally with port 6379
Steps:
- Cloning the source code
- Run
npm i
- Run
npm run dev
to serve the web server locally. The server will listen on port 3000
There is 1 API to retrieve hotel data: GET /price
. This API accept following parameters
- chart: Chart type - ex: chart=d1
The response format is like below:
[
[
1683950400000,
"0.1",
"0.11145351235999998",
"0.1",
"0.11145351235999998"
],
[
1683964800000,
"0.11145351235999998",
"0.11163295936999997",
"0.11145351235999998",
"0.11163295936999997"
],
[
1683979200000,
"0.11163295936999997",
"0.11163295936999997",
"0.11163295936999997",
"0.11163295936999997"
],
[
1683993600000,
"0.11163295936999997",
"0.11163295936999997",
"0.11163295936999997",
"0.11163295936999997"
],
]
- For faster reading, I utilize Redis for caching data, resulting in a reduction of 200 times in read times (on my local machine).
- At the beginning, running
npm run migration
- When it is finished, start running project:
npm run dev
-
Init MongoDB Client and check the last read index data in
h1.json
whether or not has old data. -
If already had old data, we query from
chartLogs
start atlastReadIdx
that we saved before. -
If there are new data after
lastReadIdx
, we start update new data toh1
,h4
,d1
,m1
,m5
,m15
json files. -
Start
setInterval
to read new data (from newlastReadIdx
) every2s
and update to json files.
- Can init
10^6
with chart logs records only.