Skip to content

Instantly share code, notes, and snippets.

@Yitaek
Created May 23, 2021 19:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Yitaek/9282429c23f228deff38c6c8426e1c62 to your computer and use it in GitHub Desktop.
Code to test out-of-order ingestion via InfluxDB line protocol to QuestDB
const axios = require ('axios')
const net = require("net")
const client = new Client({
user: "admin",
host: "localhost",
database: "qdb",
password: "quest",
port: "8812"
})
const influxClient = new net.Socket()
const HOST = "localhost"
const PORT = 9009
function randomInt(low, high) {
return Math.floor(Math.random() * (high - low) + low)
}
async function main() {
await influxClient.connect(PORT, HOST)
async function getBinanceData(){
const { data } = await axios.get('https://api.binance.us/api/v3/avgPrice?symbol=BTCUSD')
const row = `crypto,currency=BTC exchange="Binance",price=${data.price} ${Date.now() * 1e6}`
await influxClient.write(`${row}\n`)
setTimeout(getBinanceData, 1000);
}
async function getGeminiData(){
const { data } = await axios.get('https://api.gemini.com/v1/pricefeed')
const { price } = data.find(i => i.pair === 'BTCUSD')
const row = `crypto,currency=BTC exchange="Gemini",price=${price} ${Date.now() * 1e6}`
setTimeout( async () => {
await influxClient.write(`${row}\n`)
}, randomInt(1000, 5000) )
setTimeout( getGeminiData, 1000)
}
getBinanceData()
getGeminiData()
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment