Last active
May 31, 2023 11:36
-
-
Save http91/6d2a04c76201a2d5d2894973ddf2aa43 to your computer and use it in GitHub Desktop.
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
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