Skip to content

Instantly share code, notes, and snippets.

@http91
Last active May 31, 2023 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save http91/6d2a04c76201a2d5d2894973ddf2aa43 to your computer and use it in GitHub Desktop.
Save http91/6d2a04c76201a2d5d2894973ddf2aa43 to your computer and use it in GitHub Desktop.
import WebSocket from 'ws'
const APIKEY = 'myapiKeyIsHere'
// Connection Type:
const ws = new WebSocket('wss://delayed.polygon.io/stocks') // stocks 15-min delay
// Connection Opened:
ws.on('open', () => {
console.log('Connected!')
ws.send(`{"action":"auth","params":"${APIKEY}"}`)
ws.send(`{"action":"subscribe","params":"AM.*"}`) // min
})
// Per message packet:
ws.on('message', (data) => {
data = JSON.parse(data)
data.map((msg) => {
if (msg.ev === 'status') {
return console.log('Status Update:', msg.message)
}
console.log(msg)
})
})
ws.on('error', console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment