-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update websocket examples and add one for Polygon Business * Fix double tabs
- Loading branch information
1 parent
8df7988
commit e0b8a5f
Showing
4 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { websocketClient } from "@polygon.io/client-js"; | ||
|
||
/* | ||
This example uses polygon client-js library to connect to the polygon stocks for business | ||
websocket to subscribe to the fair market value channel for the ticker AAPL. | ||
*/ | ||
|
||
// create a websocket client using the polygon client-js library | ||
const ws = websocketClient('API KEY', 'wss://business.polygon.io').stocks(); | ||
|
||
// register a handler to log errors | ||
ws.onerror = (err) => console.log('Failed to connect', err); | ||
|
||
// register a handler to log info if websocket closes | ||
ws.onclose = (code, reason) => console.log('Connection closed', code, reason); | ||
|
||
// register a handler when messages are received | ||
ws.onmessage = (msg) => { | ||
// parse the data from the message | ||
const parsedMessage = JSON.parse(msg.data); | ||
|
||
// wait until the message saying authentication was successful, then subscribe to a channel | ||
if (parsedMessage[0].ev === 'status' && parsedMessage[0].status === 'auth_success') { | ||
console.log('Subscribing to Fair Market Value channel for ticker AAPL'); | ||
ws.send(JSON.stringify({"action":"subscribe", "params":"FMV.AAPL"})); | ||
} | ||
|
||
console.log('Message received:', parsedMessage); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
This example uses polygon client-js library to connect to the delayed stocks polygon | ||
websocket to subscribe to minute ohlc values for the ticker AAPL. | ||
*/ | ||
|
||
import { websocketClient } from "@polygon.io/client-js"; | ||
|
||
// create a websocket client using the polygon client-js library | ||
const ws = websocketClient('API KEY', 'wss://delayed.polygon.io').stocks(); // 15-min delay websocket | ||
// const ws = websocketClient('API KEY', 'wss://socket.polygon.io').stocks(); // real-time webscoket | ||
|
||
// register a handler to log errors | ||
ws.onerror = (err) => console.log('Failed to connect', err); | ||
|
||
// register a handler to log info if websocket closes | ||
ws.onclose = (code, reason) => console.log('Connection closed', code, reason); | ||
|
||
// register a handler when messages are received | ||
ws.onmessage = (msg) => { | ||
// parse the data from the message | ||
const parsedMessage = JSON.parse(msg.data); | ||
|
||
// wait until the message saying authentication was successful, then subscribe to a channel | ||
if (parsedMessage[0].ev === 'status' && parsedMessage[0].status === 'auth_success') { | ||
console.log('Subscribing to the minute aggregates channel for ticker AAPL'); | ||
ws.send(JSON.stringify({"action":"subscribe", "params":"AM.AAPL"})); | ||
} | ||
|
||
console.log('Message received:', parsedMessage); | ||
} |
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
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