I have simple websocket API from api.bitfinex.com/ws that stream changes on BTC/USD market. I'm struggle how to make this to update simple csv file, so when receive new data from ws to update csv. I try to use fast-csv, but without success. Here is my node js code:
const WebSocket = require('ws');
const ws = new WebSocket("wss://api.bitfinex.com/ws");
const fs = require('fs');
ws.onopen = function(){
ws.send(JSON.stringify({'event':'subscribe', 'channel':'ticker', 'pair':'btcusd'}))
};
ws.onmessage = function(msg){
var response = JSON.parse(msg.data);
if (response[1] !="hb"){
console.log("Bitfin " + response[7]);
//HERE I need to update existing CSV file,
//for example
//BTC,xxxx
//ETH,xxxx
//two columns, and n rows..
}
};
So, any idea how to stream into csv (BTCUSD in row 1 column 2; ETH in row 2 column 2 etc)