Skip to content

websocket

Subhajit Sahu edited this page Sep 22, 2022 · 2 revisions

A Javascript interface for FYERS API {websocket}.
📦 Node.js, 🌐 Web, 📜 Files, 📰 Docs.

[FYERS] is one of the cheapest online stock brokers in India, that offers trading in the equity (NSE, BSE), currency (NSE), and commodity segments (MCX). The objective of this package is to provide a cleaner interface to FYERS API. This websocket namespace provides the same interface as FYERS WebSocket API, along with parsing of binary market data. This allows you to recieve instant notifications of order update and market data.

Global functions such as connectOrderUpdate() are stateless and accept Authorization as the first parameter. This authorization can be obtained be performing login with loginStep1() and loginStep2() in the http interface. On the other hand, global functions such as subscribeOrderUpdate() accept Connection as the first parameter, which is returned by the connect functions.

This package is available in both Node.js and Web formats. The web format is exposed as extra_fyers_websocket standalone variable and can be loaded from jsDelivr CDN.

This is part of package extra-fyers.
Stability: Experimental.


const {http} = require('extra-fyers');

async function main() {
  var app_id       = '****';  // app_id recieved after creating app
  var access_token = '****';  // access_token recieved after login
  var auth = {app_id, access_token};

  // List equity and commodity fund limits.
  console.log(await http.getFunds(auth));

  // List holdings.
  console.log(await http.getHoldings(auth));

  // Place CNC market order for SBIN (equity) on NSE for 5 shares
  var id = await http.placeOrder(auth, {
    symbol: 'NSE:SBIN-EQ',
    productType: "CNC",
    qty: 5,
    side: 1, // BUY
    type: 2, // MARKET
    offlineOrder: "False"
  });

  // List postions for today (should list NSE:SBIN-EQ-CNC).
  console.log(await http.getPositions(auth));
}
main();


Index

Property Description
MARKET_DATA_URL Root URL for Market data notifications.
ORDER_UPDATE_URL Root URL for Order update notifications.
Connection Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
connectOrderUpdate Connect to Order update URL with WebSocket.
subscribeOrderUpdate Subscribe to order update.
unsubscribeOrderUpdate Unsubscribe to order update.
connectMarketData Connect to Market data URL with WebSocket.
subscribeMarketQuote Subscribe to market quote.
subscribeMarketDepth Subscribe to market depth.
unsubscribeMarketQuote Unsubscribe to market quote.
unsubscribeMarketDepth Unsubscribe to market depth.


References



Clone this wiki locally