
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
fyers-api-v3
Advanced tools
The official Javascript node client for communicating with the Fyers API
Install via npm
npm install fyers-api-v3@latest
v3
is a breaking major release with multiple internal modification to improve user experience.
Below are the breaking changes:
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)
})
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
});
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()
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()
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);
FAQs
connect to fyers API
The npm package fyers-api-v3 receives a total of 190 weekly downloads. As such, fyers-api-v3 popularity was classified as not popular.
We found that fyers-api-v3 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.