Created
May 16, 2024 14:49
-
-
Save hmpmarketing/b18ba2b6db4fb0af370fbfea1f49c366 to your computer and use it in GitHub Desktop.
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
const { Sender } = require('@questdb/nodejs-client'); | |
var moment = require("moment"); | |
const axios = require('axios'); | |
const marketname = process.env.MARKETNAME || 'US 2000 - Rolling Cash' | |
const marketid = parseInt(process.env.MARKETID) || 68744 | |
const quoteid = parseInt(process.env.QUOTEID) || 875464 | |
const bucket = process.env.BUCKET || 'minute' | |
const candle_length = process.env.CANDLE_LENGTH || 10000 | |
const run_once = process.env.RUN_ONCE || true | |
const sender = Sender.fromConfig('http::addr=localhost:9000;init_buf_size=4096'); | |
async function secondsLoop() { | |
var data = await getChartData(bucket,marketid,candle_length) | |
for(var d of data.data.data.reverse()){ | |
var dataArr = d.split(",") | |
var open = Number(dataArr[1]) | |
var high = Number(dataArr[2]) | |
var low = Number(dataArr[3]) | |
var close = Number(dataArr[4]) | |
var timestamp = moment(dataArr[0],moment.ISO_8601).valueOf() | |
await sender.table(`chartfeed_${bucket}`) | |
.symbol('name', marketname) | |
.intColumn('quoteid', quoteid) | |
.intColumn('marketid', marketid) | |
.floatColumn('open', open) | |
.floatColumn('high', high) | |
.floatColumn('low', low) | |
.floatColumn('close', close) | |
.at(timestamp, 'ms'); | |
await sender.flush(); | |
} | |
await sender.close(); | |
} | |
setInterval(async () => { | |
await secondsLoop() | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment