Integrate your app with Upstox using TradeButton in Python Flask

Upstox offers tradebutton with the help of that we can customize our trades which will be in html+javascript it is entirely a semi automated tools which we even can use to place basket orders.

To avail this offer you should have an upstox account for that you can follow this url link to have an account https://upstox.com/open-account/?f=36K0 in this you can have some great offers which you can avail in our case for algorithmic trading we can make use of 14 days free api and after that 1500/- rs per month low cost api compared to other brokers.

Let us move to working part of this trade button in this all you have to do is install flask and give a name as filenam.py and follow the code below:


from flask import Flask,render_template

app=Flask(__name__)

@app.route('/m')
def market():
    return render_template('tradeupstox.html')
if __name__=='__main__':
    app.run()

So from the above we can see that a render template is there which says tradeupstox.html for that you need to create an folder as templates and save this html+javascript in that folder as follows:

<upstox-tradebutton trade button-name=one></upstox-tradebutton>
     <script type="text/javascript">
         var upstoxTradesConfig = {
             "button-name": {
                 "one": [{
                     "token": 2885,
                     "symbol": "RELIANCE",
                     "exchange": "NSE",
                     "series": "EQ",
                     "quantity": 1,
                     "side": "buy",
                     "complexity": "simple",
                     "orderType": "m",
                     "position": "i",
                     "tif": "day",
                 }]
             }
         }
     </script>
     <script type="text/javascript" src="https://code.upstox.com/tradebutton.js"></script>

After paste of this code just run your python file and paste url in browser tab which will be a localhost:5000/m and click on the trade button after that if you want to place the order just click on place button and it will automatically place the order upstox platform to check that you can visit pro.upstox.com for more and proper instructions you can follow the above video.

Publisher Offsite order execution-Kite Connect 3-API-BO

Please Folllow the Video Properly then go for the Code Input:


<form method="post" id="basket-form" action="https://kite.trade/connect/basket">
<input type="hidden" name="api_key" value="r5a308ywreuekt3m"/>
<input type="hidden" id="basket" name="data" value=""/>
</form>
<script>
document.getElementById("basket").value='[{"variety":"bo","exchange":"NSE","tradingsymbol":"RELIANCE","transaction_type":"BUY","quantity":10,"product":"MIS","order_type":"LIMIT","price":1341.00,"squareoff":15,"stoploss":7,"trailing_stoploss":2.5},{"variety":"bo","exchange":"NSE","tradingsymbol":"RELIANCE","transaction_type":"BUY","quantity":10,"product":"MIS","order_type":"SL","price":1341.00,"trigger_price":1340.00,"squareoff":15,"stoploss":7,"trailing_stoploss":2.5},{"variety":"bo","exchange":"NSE","tradingsymbol":"RELIANCE","transaction_type":"SELL","quantity":10,"product":"MIS","order_type":"SL","price":1340.00,"trigger_price":1341.00,"squareoff":15,"stoploss":7,"trailing_stoploss":2.5}]';
document.getElementById("basket-form").submit();
</script>