Skip to content

Instantly share code, notes, and snippets.

@qrpike
Last active September 17, 2018 02:37
Show Gist options
  • Save qrpike/19742081e35b60c850363276c01c26e1 to your computer and use it in GitHub Desktop.
Save qrpike/19742081e35b60c850363276c01c26e1 to your computer and use it in GitHub Desktop.
const WebSocket = require('ws')
const ws = new WebSocket('wss://socket.polygon.io/forex')
// Connection Opened:
ws.on('open', () => {
ws.send(`{"action":"auth","params":"APIKEY"}`)
ws.send(`{"action":"subscribe","params":"C.AUD/USD,C.USD/EUR,C.USD/JPY"}`)
})
// Per message packet:
ws.on('message', ( data ) => {
(JSON.parse( data )).map(( msg ) => {
if( msg.ev === 'status' )
return console.log('Status Update:', msg.message)
console.log('Tick:', msg)
})
})
ws.on('error', console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment