npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fyers-api-v3

v1.3.1

Published

connect to fyers API

Downloads

959

Readme

The Fyers API Javascript client - v3

The official Javascript node client for communicating with the Fyers API

Documentation

Requirements

  • NodeJS v12.0.0+

Installation

Install via npm

npm install fyers-api-v3@latest

Breaking changes - v3

v3 is a breaking major release with multiple internal modification to improve user experience.

Below are the breaking changes:

  • websocket output format have changed completely

Getting started with API

var fyersModel= require("fyers-api-v3").fyersModel

var fyers= new fyersModel({"path":"path where you want to save logs","enableLogging":true})

fyers.setAppId("xxxxx-xxx")

fyers.setRedirectUrl("Redirect URL here")

var URL=fyers.generateAuthCode()

//use url to generate auth code
console.log(URL) 

var authcode="authcode generated above"

fyers.generate_access_token({"client_id":"APPID","secret_key":"secret","auth_code":authcode}).then((response)=>{
    if(response.s=='ok'){
        fyers.setAccessToken(response.access_token)
    }else{
        console.log("error generating access token",response)
    }
})

fyers.get_profile().then((response)=>{
        console.log(response)
    }).catch((err)=>{
        console.log(err)
    })
    
fyers.getQuotes(["NSE:SBIN-EQ","NSE:TCS-EQ"]).then((response)=>{
    console.log(response)
}).catch((err)=>{
    console.log(err)
})

fyers.getMarketDepth({"symbol":["NSE:SBIN-EQ","NSE:TCS-EQ"],"ohlcv_flag":1}).then((response)=>{
    console.log(response)
}).catch((err)=>{
    console.log(err)
})

API promises

All API calls returns a promise which you can use to call methods like .then(...) and .catch(...).

FyersApiCall
  .then(function (v) {
    // On success
  })
  .catch(function (e) {
    // On rejected
  });

Getting started order WebSocket

var fyersOrderSocket= require("fyers-api-v3").fyersOrderSocket

var skt=new fyersOrderSocket("Acesstoken in format APPID:Accesstoken",
"path to where you want to save logs",
true/*flag to enable disable logging*/)

skt.on("error",function (errmsg) {
    console.log(errmsg)
})

skt.on('others',function (msg) {
    console.log(msg)
})

skt.on('connect',function () {
    skt.subscribe([skt.orderUpdates,skt.tradeUpdates,skt.positionUpdates,
    skt.edis,skt.pricealerts])
    console.log(skt.isConnected())
})

skt.on('close',function () {
    console.log('closed')
})

skt.on('orders',function (msg) {
    console.log("orders",msg)
    skt.close()
})

skt.on('trades',function (msg) {
    console.log('trades',msg)
})

skt.on('positions',function (msg) {
    console.log('positions',msg)
})

skt.connect()

Getting started data WebSocket

let DataSocket = require("fyers-api-v3").fyersDataSocket;

var skt= DataSocket.getInstance("Accesstoken in format APPID:AccessToken",
"path where to save logs",true/*flag to enable disable logging*/)

skt.on("connect",function(){
skt.subscribe(['NSE:IDEA-EQ',"NSE:SBIN-EQ"]) 
//subscribing for market depth data if need of market depth comes as a diffrent tick
skt.subscribe(['NSE:IDEA-EQ',"NSE:SBIN-EQ"],true) 
//to start lite mode to get fewer data like ltp change
skt.mode(skt.LiteMode) 
//to revert back to full mode
// skt.mode(skt.FullMode) 
})

skt.on("message",function(message){
	console.log({"TEST":message})
})

skt.on("error",function(message){
	console.log("erroris",message)
})

skt.on("close",function(){
    console.log("socket closed")
})
skt.connect()

Auto re-connect WebSocket client

Optionally you can enable client side auto re-connection to automatically reconnect if the connection is dropped.

All you need to do is enable auto re-connection. For example

// Enable auto reconnect mechanism with retry count as passed with max allowed upto 50.
skt.autoReconnect(6);