Even receiving a “subscription” message after connecting to alpaca’s web socket, it does not seem to be sending me bars. What is going on?
The code:
const ALPACA_WS_URL = 'wss://stream.data.alpaca.markets/v1beta2/crypto'
const ALPACA_WS_KEY_ID = ''
const ALPACA_WS_KEY_SECRET = ''
const alpacaWebSocket = new WebSocket(ALPACA_WS_URL, { perMessageDeflate: false })
function createJsonBuffer(json: any) {
return Buffer.from(JSON.stringify(json))
}
function authenticate() {
alpacaWebSocket.send(createJsonBuffer({
action: "auth",
key: ALPACA_WS_KEY_ID,
secret: ALPACA_WS_KEY_SECRET,
}))
}
function subscribe() {
alpacaWebSocket.send(createJsonBuffer({
action: 'subscribe',
trades: ['BCH/USD'],
}))
}
alpacaWebSocket.on('message', (dataBuffer: Buffer) => {
const [ data ] = JSON.parse(dataBuffer.toString())
if(data.T === 'success' && data.msg === 'connected') {
authenticate()
}
if(data.T === 'success' && data.msg === 'authenticated') {
subscribe()
}
console.log(data)
})
The logs I am getting:
{ T: 'success', msg: 'connected' }
{ T: 'success', msg: 'authenticated' }
{ T: 'subscription', trades: [ 'BCH/USD' ], quotes: [], orderbooks: [], bars: [], updatedBars: [], dailyBars: [] }