8000 [WIP] Adds Futures support (alpha) by justinpolygon · Pull Request #212 · polygon-io/client-js · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Adds Futures support (alpha) #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
from

Conversation

justinpolygon
Copy link
Contributor
@justinpolygon justinpolygon commented Feb 28, 2025

Added futures REST and WebSocket support (alpha). Includes new REST endpoints for futures data (e.g., aggregates, contracts, market statuses, etc) and WebSocket event parsing (e.g. trades, quotes, and aggregates).

REST examples:

import { restClient } from '@polygon.io/client-js';
const rest = restClient("XXXX");

rest.futures.aggregates("ESZ4", 1, "day", "2023-01-01", "2023-01-02")).then((data) => {
	console.log(data);
}).catch(e => {
	console.error('An error happened:', e);
});

Websocket examples:

import { websocketClient } from
8D3C
 "@polygon.io/client-js";

// create a websocket client using the polygon client-js library
const ws  = websocketClient('XXXX', 'wss://socket.polygon.io').futures();

// 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 *');
		ws.send(JSON.stringify({"action":"subscribe", "params":"AM.*"}));
	}

	console.log('Message received:', parsedMessage);
}

This is a work in progress PR and will get updates as things evolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0