Friday, April 21, 2023

Algotrading: Exit Positions in Fyers API

Example code snippet for exiting positions in Fyers API


Code:


if __name__ == '__main__':
    token = get_auth_code()
    fyers = fyersModel.FyersModel(client_id=client_id, token=token, log_path='/tmp/')
    print(fyers.positions())

    data = [{"id": "NSE:BANKNIFTY23APR42900CE-MARGIN"}, {"id": "NSE:BANKNIFTY23APR41300PE-MARGIN"}]
    pos_res = fyers.exit_positions(data)

    print(pos_res)

    pos_res = fyers.exit_positions()

    print(pos_res)
  

Please copy the code for get_auth_code() from previous blogpost for Fyers V2 login

 

Happy trading. Enjoy.

No comments:

Post a Comment