Posts

Showing posts from February, 2022

Algo Trading. How to place stop loss on NIFTY? Fyers , Python

Image
Placing stop loss  lossType=risk.get() if(lossType==1):             if(checkBank()):                 exitOrder()                 break         elif(lossType==2):             if((ltp-float(avgPrice.get()))<(-int(spin2.get()))):                 exitOrder()                 break def checkBank():     data = {"symbols":"NSE:NIFTY50-INDEX"}     out=fyers.quotes(data)     ltp=out["d"][0]["v"]["lp"]     if((strikeName.get().endswith("CE"))and(ltp<=int(spin1.get()))):         return 1     elif((strikeName.get().endswith("PE"))and(ltp>=int(spin1.get()))):         return 1 

Algo Trading. How to view profit Fyers?

Image
 Profit Update def profitUpdate():     data = {"symbols":strikeName.get()}     trailStarted=False     trailTarget=0     trailLoss=0     while(True):         if(stopThread==True):             stopThread==False             break         out=fyers.quotes(data)         ltp=out["d"][0]["v"]["lp"]         profitEarned=(ltp-float(avgPrice.get()))*int(filledQty.get())         profit.delete(0,"end")         profit.insert(0,profitEarned) 

Algo Trading. How to view order details? Fyers, Python

Image
View Order Details def exactPositions():     openPos=(fyers.positions())     posLength=len(openPos["netPositions"])     startPos=0     orderName=""     orderQty1=0     print(posLength)     #print(openPos["netPositions"][1]["qty"])     #print(openPos["netPositions"][9])     while(startPos<posLength):         if(openPos["netPositions"][startPos]["qty"]>0):             print(openPos["netPositions"][startPos]["qty"])             qty.delete(0,"end")             qty.insert(0,openPos["netPositions"][startPos]["qty"])             orderQty1=int(openPos["netPositions"][startPos]["qty"])             print(orderQty1)             orderName=openPos["netPositions"][startPos]["symbol"]             print(orderName)             name.delete(0,"end")             name.insert(0,orderName)             break         startPos+=1     open

Algo Trading. How to display position and exit orders , Fyers, python?

Image
Display trade position in python  def positions():     pos=fyers.positions()     strikeName.delete(0,"end")     strikeName.insert(0,pos["netPositions"][0]["symbol"])     filledQty.delete(0,"end")     filledQty.insert(0,pos["netPositions"][0]["qty"])     avgPrice.delete(0,"end")     avgPrice.insert(0,pos["netPositions"][0]["avgPrice"])

Algo Trading. How to place Orders? Fyers

Image
How to place order ? Fyers, Python  def buyOrder(event):     data = {       "symbol":"NSE:"+event.widget["text"],       "qty":int(qty.get()),       "type":2,       "side":1,       "productType":"INTRADAY",       "limitPrice":0,       "stopPrice":0,       "validity":"DAY",       "disclosedQty":0,       "offlineOrder":"False",       "stopLoss":0,       "takeProfit":0     }     fyers.place_order(data) Please watch the video below for more information!

Algo Trading. How to view option chain? Python , Fyers

Image
How to View Option Chain?   def create_option():     f=open("E:\Coder\option.txt","r")     strike=f.read()          data = {"symbols":"NSE:NIFTY50-INDEX"}     output=fyers.quotes(data)     ltp=output["d"][0]["v"]["lp"]     atStrike=int(ltp)     atStrike=int(ltp-(ltp%50))     atStrike+=100     i=1     while(i<=10):         if(i<5):             button=Button(root,text=strike[0:10]+str(atStrike)+"CE",width=20)             button.grid(row=i,column=0)             button.bind('<Button>',buyOrder)             tempEntry=Entry(root,width=24)             tempEntry.grid(row=i,column=1)             option.append(button)             price.append(tempEntry)             atStrike-=50         elif(i==5):             button=Button(root,text=strike[0:10]+str(atStrike)+"CE",width=20)             button.grid(row=i,column=0)             button.bind('<Button>',buyOrder)             temp

Algo Trading.How to connect to Fyers API? Python

Image
 def connect_fyers():     global fyers     session=accessToken.SessionModel(client_id="XXXXXXX-100",     secret_key="YYYYYYYYYY",redirect_uri="https://trade.fyers.in/",      response_type="code", grant_type="authorization_code",     state="abcdefg",scope="",nonce="")     response = session.generate_authcode()     #https://api.fyers.in/api/v2/generate-authcode?client_id=XXXXXXX-100&redirect_uri=https://fyers.in&response_type=code&state=sample_state&nonce=sample_nonce     auth_code=sessionVar.get()     top.destroy()     session.set_token(auth_code)     response = session.generate_token()     access_token = response["access_token"]     fyers = fyersModel.FyersModel(client_id="XXXXXXX-100", token=access_token,log_path="E:\python")     profile=fyers.get_profile()     print(profile["data"]["name"])     print(mav(20)) def session_pop():     global t

Algo Trading.How to create User Interface , Fyers, Python

Image
Here is the code to create GUI root=Tk() Label(root,text="ALGO TRADING",width=20).grid(row=0,column=0) Button(root,text="SESSION",width=20,command=session_pop).grid(row=0,column=1) Button(root,text="STRIKES",width=20,command=create_option).grid(row=0,column=2) Button(root,text="PRICE",width=20,command=lambda:allThreads(1)).grid(row=0,column=3) Label(root,text="QUANTITY",width=20).grid(row=1,column=2) qty=Entry(root,width=24) qty.grid(row=1,column=3) Button(text="POSITION",width=20,command=exactPosition).grid(row=2,column=2) Button(text="START",width=20,command=lambda:allThreads(2)).grid(row=2,column=3) Label(root,text="NAME",width=20).grid(row=3,column=2) strikeName=Entry(root,width=24) strikeName.grid(row=3,column=3) Label(root,text="QUANTITY",width=20).grid(row=4,column=2) filledQty=Entry(root,width=24) filledQty.grid(row=4,column=3) Label(root,text="AVERAGE",width=20).grid(row=5,colum