Hello,

I am trying to execute and retrive data using Fyers API V2 but getting this error again and again.

The documentation is also not yet extensive and hence unable to get the clear idea of session creation and login.

 

Below is my sample code for reference -

 

import requests
from fyers_api import fyersModel
from fyers_api import accessToken
import sys
sys.path.insert(0, "/home/pranavshinde/Desktop")


def login():

    session = accessToken.SessionModel(client_id='DBKDUMMY-100',
    secret_key='S2W3DUMMY', redirect_uri='http://awebsite.in/',
    response_type='code',grant_type='authorization_code')

    url = session.generate_authcode()
    response = requests.get(url)
    print(response.url)

    auth_code='eyJ0eXAiOiJKV1QiLCJhbGTYxMjc0NTE3MiwibmJmIjoxNjEyNz5X25hbWUiOiJGUzIxNzYiLCJub25jZSI6IiIsImFwcF9pZCI6IkRCS1VVN1RaTVMiLCJ1dWlkIjoiY2MxMjQ0OTA0ZDAzNDkwNmE3OWMwNTMxMTNkNjBlMDYiLCJpcEFkZHIiOiIxMDMuMjA4LjcxLjMyIiwic2NvcGUiOiIifQ.1D2jqhHI5ooljC8skmlwXr1nU1XCy_DvzUvZVZaPimk'
    session.set_token(auth_code)
    response = session.generate_token()
    print(response)
    return response["access_token"]


def retrive(access_token):
    fyers = fyersModel.FyersModel(token=access_token, log_path="/Users/pranavshinde/Desktop")
    print(fyers.positions())

if __name__ == '__main__':
    access_token = login()
    retrive(access_token)
 

 

Below is the error I am getting for above simple code execution -

 

fyers.positions()

{'s': 'error', 'code': 500, 'message': 'Looks like you are passing an invalid entry'}