Function for Creating Upstox Trade Button

Here goes a pythonic way to create Upstox’s Trade Button! It will work correctly for one button but will fail if you make two buttons on one page because upstoxTradesConfig needs to be iterated in that case!

Refer - https://jsfiddle.net/suraj2/LLn4vj4q/

Usage:

upstox_button_maker('buddha', 'BANKNIFTY19DECFUT,NSE,FO,20,31775.35,SELL,oco,sl,100,500,0,false,i,day,31805.35','BANKNIFTY19DECFUT,NSE,FO,20,31775.35,SELL,oco,sl,100,500,0,false,i,day,31805.35')

Funciton:

def upstox_button_maker(stratname, *argv):
    f = open(stratname+'.html','w')
    f.write('''<div class='btns-container'><div class='branded-btn'> <upstox-tradebutton button-name="'''+stratname+'''" trade></upstox-tradebutton></div></div>\n<script type="text/javascript">\n''')
    f.write('var upstoxTradesConfig = {\n"button-name": {\n"'+stratname+'": [')


    for arg in argv:
        f.write('{')
        symbol,exchange,series,quantity,price,side,complexity,orderType,stoploss,target,trailingTicks,amo,position,tif,triggerPrice=arg.split(",")
        f.write('"symbol": "'+symbol+'",')
        f.write('"exchange": "'+exchange+'",')
        f.write('"series": "'+series+'",')
        f.write('"quantity": '+quantity+',')
        f.write('"price": '+price+',')
        f.write('"side": "'+side+'",')
        f.write('"complexity": "'+complexity+'",')
        f.write('"orderType": "'+orderType+'",')
        f.write('"stoploss": '+stoploss+',')
        f.write('"target": '+target+',')
        f.write('"trailingTicks": '+trailingTicks+',')
        f.write('"amo": '+amo+',')
        f.write('"position": "'+position+'",')
        f.write('"tif": "'+tif+'",')
        f.write('"triggerPrice":'+triggerPrice+'')
        f.write('},\n')
    f.write('] } }</script><script type="text/javascript" src="https://code.upstox.com/tradebutton.js"></script>')
    f.close()
    return