2.1.0 ā€¢ Published 3 months ago

@extra-fyers/websocket v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

A Javascript interface for FYERS API. šŸ“¦ 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. The http namespace provides the same interface as FYERS HTTP API. The 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. The top namespace (global functions, classes) provide a facade for the HTTP and the WebSocket APIs and provides additional utility functions, such as calculating charges.

Global functions associated with FYERS API, such as getPositions(), are stateless and accept Authorization as the first parameter. On the other hand, the Api class includes stateful functions which do not require the Authorization parameter (required while creating object). Note that this authorization can be obtained be performing login with loginStep1() and loginStep2().

The goals for the future include doing a thorough interface check, and possibly writing a CLI interface. Obtaining details of symbols, including images and more could be done as part of a separate package.

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

Stability: Experimental.

const fyers = require('extra-fyers');

async function main() {
  var appId       = '****';  // app_id recieved after creating app
  var accessToken = '****';  // access_token recieved after login
  var api = new fyers.Api(appId, accessToken);

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

  // List holdings.
  console.log(await api.getHoldings());

  // Place CNC market order for SBIN (equity) on NSE for 5 shares
  var id = await api.placeOrder({symbol: 'NSE:SBIN-EQ', quantity: 5});

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


  // Connect to Market data with WebSocket
  // and recieve real-time market quotes.
  await api.connectMarketData(quote => {
    console.log(quote);
  });
  // Choose which symbols you want to subscribe to.
  await api.subscribeMarketDepth(['NSE:SBIN-EQ']);

  // Connect to Order update with WebSocket
  // and recieve real-time order status updates.
  await api.connectOrderUpdate(order => {
    console.log(order);
  });
  // Subscribe to order status updates.
  await api.subscribeOrderUpdate();
}
main();

Index

PropertyDescription
exchangeDescriptionGet exchange description.
exchangeGet exchange code.
segmentDescriptionGet segment description.
segmentGet segment code.
positionSideDescriptionGet position side description.
positionSideGet position side code.
orderSideDescriptionGet order side description.
orderSideGet order side code.
orderSourceDescriptionGet order source description.
orderSourceGet order source code.
orderStatusDescriptionGet order status description.
orderStatusGet order status code.
orderTypeDescriptionGet order type description.
orderTypeGet order type code.
orderValidityDescriptionGet order validity description.
orderValidityGet order validity code.
optionTypeDescriptionGet option type description.
optionTypeGet option type code.
derivativeTypeDescriptionGet derivative type description.
derivativeTypeGet derivative type code.
holdingTypeDescriptionGet holding type description.
holdingTypeGet holding type code.
productTypeDescriptionGet product type description.
productTypeGet product type code.
instrumentTypeDescriptionGet instrument type description.
instrumentTypeGet instrument type code.
symbolNameGet symbol exchange, underlying, currency-pair, or commodity name.
symbolExchangeGet symbol exchange.
symbolSeriesGet symbol exchange series.
symbolOptionTypeGet symbol option type.
symbolDerivativeTypeGet symbol derivative type.
symbolStrikePriceGet symbol strike price.
symbolTokenGet symbol token, a unique identifier.
symbolDescriptionGet symbol description.
symbolIsinGet symbol ISIN.
symbolLotSizeGet symbol minimum lot size.
equityDeliveryChargesGet equity delivery charges.
equityIntradayChargesGet equity intraday charges.
equityFuturesChargesGet equity futures charges.
equityOptionsChargesGet equity options charges.
currencyFuturesChargesGet currency futures charges.
currencyOptionsChargesGet currency options charges.
commodityFuturesChargesGet commodity futures charges.
commodityOptionsChargesGet commodity options charges.
loginStep1Get request step 1 for authorization.
loginStep2Get request step 2 for authorization.
getProfileGet basic details of the client.
getFundsGet balance available for the user for capital as well as the commodity market.
getHoldingsGet the equity and mutual fund holdings which the user has in this demat account.
getOrderGet details of an order placed in the current trading day.
getOrdersGet details of all the orders placed in the current trading day.
getPositionsGet details of all the positions in the current trading day.
getTradesGet details of all the trades in the current trading day.
placeOrderPlace an order to any exchange via Fyers.
placeOrdersPlace multiple orders to any exchange via Fyers.
modifyOrderModifies an order placed on any exchange via Fyers.
modifyOrdersModifies orders placed on any exchange via Fyers.
cancelOrderCancels an order placed on any exchange via Fyers.
cancelOrdersCancels orders placed on any exchange via Fyers.
exitPositionExits a position on the current trading day.
exitAllPositionsExits all positions on the current trading day.
convertPositionConverts a position on the current trading day.
getMarketStatusGet the current market status of all the exchanges and their segments.
getMarketHistoryGet the market history for a particular symbol.
getMarketQuotesGet the current market quotes for a set of symbols.
getMarketDepthGet the current market depth for a particular symbol.
getSymbolMasterGet all the latest symbols of all the exchanges from the symbol master files.
processSymbolMasterGet details of symbols from the symbol master file text.
loadSymbolMasterGet details of symbols from the symbol master files.
generateEdisTpinGenerate e-DIS TPIN for validating/authorising transaction.
getEdisTransactionsGet the necessary information regarding the holdings you have on your and also the status of the holdings.
submitEdisHoldingsStepRedirect to CDSL page for login where you can submit your Holdings information and accordingly you can provide the same to exchange to Sell your holdings (browser only).
inquireEdisTransactionInquire the information/status of the provided transaction Id for the respective holdings you have on your end.
connectMarketDataConnect to Market data URL with WebSocket.
subscribeMarketQuoteSubscribe to market quote.
subscribeMarketDepthSubscribe to market depth.
unsubscribeMarketQuoteUnsubscribe to market quote.
unsubscribeMarketDepthUnsubscribe to market depth.
connectOrderUpdateConnect to Order update URL with WebSocket.
subscribeOrderUpdateSubscribe to order update.
unsubscribeOrderUpdateUnsubscribe to order update.
ApiStateful interface for FYERS API.

References

npm.io ORG DOI

2.1.0

3 months ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

2 years ago

1.3.10

2 years ago

1.3.13

2 years ago

1.3.14

2 years ago

1.3.12

2 years ago

1.3.17

2 years ago

1.3.18

2 years ago

1.3.15

2 years ago

2.0.0

2 years ago

1.3.16

2 years ago

1.3.19

2 years ago

1.3.20

2 years ago

1.3.21

2 years ago

1.3.24

2 years ago

1.3.25

2 years ago

1.3.22

2 years ago

1.3.23

2 years ago

1.3.26

2 years ago

1.3.27

2 years ago

1.3.7

2 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.2.0

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.12

3 years ago

1.2.13

3 years ago

1.2.10

3 years ago

1.2.11

3 years ago

1.2.16

3 years ago

1.2.17

3 years ago

1.2.14

3 years ago

1.2.15

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.2.18

3 years ago

1.2.19

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.3.3

3 years ago

1.1.5

3 years ago

1.3.2

3 years ago

1.1.4

3 years ago

1.3.1

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.2.20

3 years ago

1.2.23

3 years ago

1.2.24

3 years ago

1.2.21

3 years ago

1.2.22

3 years ago

1.2.27

3 years ago

1.1.16

3 years ago

1.2.28

3 years ago

1.1.15

3 years ago

1.2.25

3 years ago

1.1.14

3 years ago

1.2.26

3 years ago

1.1.19

3 years ago

1.2.29

3 years ago

1.1.18

3 years ago

1.1.17

3 years ago

1.2.30

3 years ago

1.2.31

3 years ago

1.2.9

3 years ago

1.2.34

3 years ago

1.1.23

3 years ago

1.2.35

3 years ago

1.1.22

3 years ago

1.2.32

3 years ago

1.1.21

3 years ago

1.2.33

3 years ago

1.1.20

3 years ago

1.1.24

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago