Save it as button.html and just click on them for GUI:
<form action = "http://localhost:8090/BUY_trades" method = post>
<p>BUY tradingsymbol:</p>
<p><input type = "text" name = "name" /></p>
<p><input type = "submit" value = "submit" /></p>
</form>
<form action = "http://localhost:8090/SELL_trades" method = post>
<p>SELL tradingsymbol:</p>
<p><input type = "text" name = "name" /></p>
<p><input type = "submit" value = "submit" /></p>
</form>
<form action = "http://localhost:8090/BS_pair" method = post>
<p>BS pair:</p>
<p><input type = "text" name = "name" /></p>
<p><input type = "submit" value = "submit" /></p>
</form>
<form action = "http://localhost:8090/BS" method = post>
<p>Target:</p>
<p><input type = "text" name = "name" /></p>
<p><input type = "submit" value = "submit" /></p>
</form>
Save as filename.py and run them as shown in the instructional Video;
from flask import Flask,redirect, url_for, request
app=Flask(__name__)
@app.route("/tradingsymbol_BUY/<name>")
def tradingsymbol_BUY(name):
return """<script src="https://kite.trade/publisher.js?v=1"></script><button type="submit"
data-kite="r5a308ywreuekt3m"
data-exchange="NSE"
data-tradingsymbol="%s"
data-transaction_type="BUY"
data-quantity="1"
data-order_type="MARKET"
data-product="MIS"/>BUY</button>""" % name
@app.route("/tradingsymbol_SELL/<name>")
def tradingsymbol_SELL(name):
return """<script src="https://kite.trade/publisher.js?v=1"></script><button type="submit"
data-kite="r5a308ywreuekt3m"
data-exchange="NSE"
data-tradingsymbol="%s"
data-transaction_type="SELL"
data-quantity="1"
data-order_type="MARKET"/>SELL</button>""" % name
@app.route("/BUY_trades",methods = ["POST", "GET"])
def BUY_trades():
if request.method == "POST":
user = request.form["name"]
return redirect(url_for("tradingsymbol_BUY",name = user))
else:
user = request.args.get("name")
return redirect(url_for("tradingsymbol_BUY",name = user))
@app.route("/SELL_trades",methods = ["POST", "GET"])
def SELL_trades():
if request.method == "POST":
user = request.form["name"]
return redirect(url_for("tradingsymbol_SELL",name = user))
else:
user = request.args.get("name")
return redirect(url_for("tradingsymbol_SELL",name = user))
@app.route("/symbolpair_BS/<name>")
def symbolpair_BS(name):
return """<button id="custom-button">TRADE THE BASKET</button>
<script src="https://kite.trade/publisher.js?v=1"></script>
<script>
KiteConnect.ready(function(){
var kite=new KiteConnect("r5a308ywreuekt3m");
kite.add({
"exchange" : "NSE",
"tradingsymbol" : "YESBANK",
"transaction_type" : "BUY",
"quantity" : 1,
"order_type" : "MARKET",
"product" : "MIS"
});
kite.add({
"exchange" : "NSE",
"tradingsymbol" : "PNB",
"transaction_type" : "%s",
"quantity" : 1,
"order_type" : "MARKET",
"product" : "MIS"
});
kite.link("#custom-button");
});
</script>""" % name
@app.route('/BUY_SELL/<int:name>')
def BUY_SELL(name):
return """
<button id="custom-button">TRADE THE BASKET</button>
<script src="https://kite.trade/publisher.js?v=1"></script>
<script>
KiteConnect.ready(function(){
var kite=new KiteConnect("r5a308ywreuekt3m");
kite.add({
"exchange" : "NSE",
"tradingsymbol" : "YESBANK",
"transaction_type" : "BUY",
"quantity" : 50,
"order_type" : "MARKET",
"product" : "MIS"
});
kite.add({
"exchange" : "NSE",
"tradingsymbol" : "YESBANK",
"transaction_type" : "SELL",
"quantity" : 50,
"price" : %d,
"order_type" : "LIMIT",
"product" : "MIS"
});
kite.link("#custom-button");
});
</script>""" % name
@app.route("/BS_pair",methods = ["POST", "GET"])
def BS_pair():
if request.method == "POST":
user = request.form["name"]
return redirect(url_for("symbolpair_BS",name = user))
else:
user = request.args.get("name")
return redirect(url_for("symbolpair_BS",name = user))
@app.route("/BS",methods = ["POST", "GET"])
def BS():
if request.method == "POST":
user = request.form["name"]
return redirect(url_for("BUY_SELL",name = user))
else:
user = request.args.get("name")
return redirect(url_for("BUY_SELL",name = user))
if __name__=="__main__":
app.run(debug=True,port=8090)