This module is installed via npm:

npm install fyers-api

Overview
There is only one class in the package: clientApi. This class is used to retrieve an authorization_code from the server. An authorization_code is valid for 24 hours. With an authorization_code, you can request for user access token. Ideally you only need to create a Session object once every day.
With an access token, you can instantiate rest of the functions in the class.. 

Sample Program

const fyers = require(fyers-api)

For Authentication Process
app_id = 'your_app_id'

app_secret = 'your_app_secret'

let reqBody = { "app_id": app_id, "secret_key": app_secret };

let result = fyers.auth(reqBody)

	The above command returns JSON structured like this:

    {
	'code': 200,
	 'data': {
		'authorization_code':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqaGdqZzg3NiQ3ODVidjVANj Q3NTZ2NSZnNyM2OTg3Njc5OHhkIjoiWElHVFVYVjBSSSIsImV4cCI6MTU2MTU5NzM5Ny41NjQxNTV9.Agl-Uus63NforrUEdbG7YUlPcbFXu9hLYm4akGuIBkU'
		},
	 'message': ''
    }
	authorization_code = “your_autherization_code”

	To get the URI

        If he is new user

        url = fyers.generateToken()

        Existing User

		url = fyers.generateToken('user_id') # to get login url for user 

        The Aboove function will return url like this:
        https://api.fyers.in/api/v1/genrateToken?authorization_code=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqaGdqZzg3NiQ3ODVidjVANjQ3NTZ2NSZnNyM2OTg3Njc5OHhkIjoiWElHVFVYVjBSSSIsImV4cCI6MTU2MTU5NzM5Ny41NjQxNTV9.Agl-UUs63NforrUEdbG7YUlPcbFXu9hLYm4akGuIBkU&appId=Your_app_id"

        Redirect the user to this url.
        After user approve the request access_token will be send to redirect_url given by the client while registering the application. 
      
      Sample result after user approve the request:   

      http://localhost:5000?access_token=gAAAAABc3Sh9QpE5mNx2mSz6vvvT29SAsELqkfbKQKa2977zHw3NdPBhe6jAZCBumHvYUum87j53-AzMEPXMjQw31wkRviZ1TdM5OimgTYWEEorWDmWuHnY=&user_id=FYXXXX


let token = 'your_access_token'

Order history

fyers.orders({token:token})
## sample Output ##
{
	"code": 200,
	 "data": 
		{
   		 "orderBook": []
		},
    "message":""
}

Place order

fyers.place_orders({token:token,data:{
	"symbol":"NSE:TCS-EQ",
	"qty":"1",
	"type":"2",
	"side":"1",
	"productType":"CNC",
	"limitPrice":"2155",
	"stopPrice":"0",
	"disclosedQty":"5",
	"validity":"IOC",
	"offlineOrder":"False",
	"stopLoss":"5",
	"takeProfit":"5"
}})


Modify order

fyers.update_orders({token:token,data:{
	"id":"119031547242",
	"type":"2"
}})


Get order Status

fyers.orderStatus({token:token,data:{"id":51902277136}})

Get order details

fyers.orderId({token:token,data:{"orderId":51902277136,
"symbol":"NSE:TCS-EQ",
"segment":"CM"}})


Delete Order


fyers.delete_orders({token:token,data:{
	"id":"119031547242"
}})

Tradebook

fyers.tradebook({token:token})

sample output - 
{
	"code": 200,
	 "data": 
		{
   		 "tradeBook": []
    	
		},
        "message":""
}




User

Get funds 

fyers.funds({token : token})

### sample output ###


{
	"code": 200,
	 "data":
	 	{
		 "fund_limit":[],
		 },
    "message": ""
}

Get holdings

fyers.holdings({token : token})

##sample output###

{
	"code": 200,
	"holdings": [
        {
            "remainingQuantity": 5,
            "symbolLtp": 2805.05,
            "symbol": "NSE:GOLDBEES-EQ",
            "holdingType": "HLD",
            "fyToken": "101000000014428",
            "costPrice": 2820.85,
            "id": 1,
            "quantity": 5
        },
        {
            "remainingQuantity": 30,
            "symbolLtp": 500.98,
            "symbol": "NSE:N100-EQ",
            "holdingType": "HLD",
            "fyToken": "101000000022739",
            "costPrice": 495.1,
            "id": 2,
            "quantity": 30
        },
        {
            "remainingQuantity": 50,
            "symbolLtp": 290.1,
            "symbol": "NSE:SETFNN50-EQ",
            "holdingType": "HLD",
            "fyToken": "10100000007353",
            "costPrice": 285.53,
            "id": 3,
            "quantity": 50
        },
        {
            "remainingQuantity": 2,
            "symbolLtp": 5.45,
            "symbol": "NSE:JPASSOCIAT-EQ",
            "holdingType": "HLD",
            "fyToken": "101000000011460",
            "costPrice": 14.83,
            "id": 4,
            "quantity": 2
        },
        {
            "remainingQuantity": 21,
            "symbolLtp": 1000,
            "symbol": "NSE:LIQUIDBEES-EQ",
            "holdingType": "HLD",
            "fyToken": "101000000011006",
            "costPrice": 1004.94,
            "id": 5,
            "quantity": 21
        },
        {
            "remainingQuantity": 1000,
            "symbolLtp": 18.99,
            "symbol": "NSE:M100-EQ",
            "holdingType": "HLD",
            "fyToken": "101000000021423",
            "costPrice": 18.65,
            "id": 6,
            "quantity": 1000
        },
        {
            "remainingQuantity": 80,
            "symbolLtp": 312,
            "symbol": "NSE:KOTAKBKETF-EQ",
            "holdingType": "HLD",
            "fyToken": "10100000005851",
            "costPrice": 298.95,
            "id": 7,
            "quantity": 80
        },
        {
            "remainingQuantity": 50,
            "symbolLtp": 521,
            "symbol": "NSE:TATASTEEL-EQ",
            "holdingType": "HLD",
            "fyToken": "10100000003499",
            "costPrice": 492.75,
            "id": 8,
            "quantity": 50
        }
    ],
}


Get positions

    fyers.positions({token : token})

sample output - 

{
	"code": 200,
	 "data": 
		{
    		"netPositions": []
		},
        "message":""
}



convertPosition

    fyers.convertPosition({token : token,data:{
        "symbol":"NSE:TCS-EQ",
        "positionSide":"1",
        "convertQty":"1",
        "convertFrom":"INTRADAY",
        "convertTo":"CNC"
    }})


Historical

OHLCV
fyers.getHistoricalOHLCV({token : token,data:{"symbol":"MCX:GOLDM18OCTFUT",
	"resolution":"D",
	"From":"1514124636",
	"to":"1547820696"}})



Data

marketStatus

fyers.marketStatus({token : token})

minquantity

fyers.minquantity({token : token})

level2data

fyers.level2data({token : token,data:{"symbol_id":"NSE:BOSCHLTD19FEB11000PE"}})

getQuotes

fyers.getQuotes({token : token,data:{"symbols":"NSE:BOSCHLTD19FEB11000PE"}})


getQuickQuote

fyers.getQuickQuote({token : token,data:{"symbols":"NSE:BOSCHLTD19FEB11000PE"}})

symbolsinfo

fyers.symbolsinfo({token : token,data:{"symbol_id":"NSE:BOSCHLTD19FEB11000PE"}})

searchSymbols

fyers.searchSymbols({token : token,data:{"query":11000,
	"limit":30}})


