I have already followed above link step by step to setup postback. Everything looks fine but somehow script "app.py" is not throughing out results in its log. log file is totally empty throughout (even if n numbers of orders executed).
I can see POST/GET lines entries at ngrok online console.
but I don't know how to take these data into my main python script. I am having tough time in fetching json data into my python script.
127.0.0.1 - - [27/Dec/2017 13:43:45] "POST /post HTTP/1.1" 500 - Traceback (most recent call last): File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise raise value File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise raise value File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/home/rakesh/wksp1/my_trade/GoogleFin/Kite_new/app.py", line 69, in post f.write(request.get_data() + '\n') TypeError: can't concat bytes to str
So, Idea is any placed order gets executed, there will be a new post appended in log file. This is working totally fine now. However, i have to keep on polling this log file to detect any change in log file and read last line through my script. I can google it how to do it in python, but do you have any piece of reliable (best way) code to do that. Kindly share that too.
You can actually integrate that python script into yours. Instead of writing it into a file you can call another function with that request data for further processing. The above gist can be reduced to:
from flask import Flask, request app = Flask(__name__)
I have already followed above link step by step to setup postback. Everything looks fine but somehow script "app.py" is not throughing out results in its log. log file is totally empty throughout (even if n numbers of orders executed).
I can see POST/GET lines entries at ngrok online console.
but I don't know how to take these data into my main python script. I am having tough time in fetching json data into my python script.
any other reference ??
Thanks,
Right now I have given https://95b6a468.ngrok.io as postback url at my kite app dashboard.
Are you suggesting that I should use https://95b6a468.ngrok.io/post ?
following is the screenshot of my kite app dashboard
127.0.0.1 - - [27/Dec/2017 13:43:45] "POST /post HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/rakesh/anaconda3/lib/python3.4/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/rakesh/wksp1/my_trade/GoogleFin/Kite_new/app.py", line 69, in post
f.write(request.get_data() + '\n')
TypeError: can't concat bytes to str
f.write(request.get_data() + '\n')
to
Following correction is working fine now.
f.write(str(request.get_data())+'\n')
Thanks for the reply.
So, Idea is any placed order gets executed, there will be a new post appended in log file. This is working totally fine now. However, i have to keep on polling this log file to detect any change in log file and read last line through my script. I can google it how to do it in python, but do you have any piece of reliable (best way) code to do that. Kindly share that too.
Thanks a lot again.
I am trying to set up the postback url as mentioned here. I get an error 404 not found and the request is not POST its coming as HEAD.
I have set up exactly like above using ngrok and flask app. I am able receive response made from other POST requests.
I am suspecting this might not be working as the I am trying this after market hours. I will try this again tomorrow morning.
yes as soon as i update the link on the console i get this message.
But i am not able to receive any messages related to orders. I have tried using postman to send json data and it works from that end.
I received the data when the order got cancelled. I was expecting a message when the order was placed. But this is okay.
Thanks