Created
May 23, 2021 19:41
Star
You must be signed in to star a gist
Code to test out-of-order ingestion via InfluxDB line protocol to QuestDB
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 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