Hi - I'm executing *place_order* within *on_ticks* and this is a causing an exception and disconnecting the web socket link. Please note, the orders go through and are executed, but the streaming link gets disconnected and does not auto-reconnect (though reconnect is enabled by default).
The error is: Traceback (most recent call last): builtins.TypeError: the JSON object must be str, not 'bytes' the error dump points to files and packages related to web socket connection (twister, autobahn, ticker etc.)
The logged debug info:
2018-01-21 10:09:18,795 Starting new HTTPS connection (1): api.kite.trade 2018-01-21 10:09:18,861 https://api.kite.trade:443 "POST /orders/regular HTTP/1.1" 200 58 2018-01-21 10:09:18,928 WebSocket connection lost: [Failure instance: Traceback: : the JSON object must be str, not 'bytes'
I'm using try/except blocks everywhere, but this error is being thrown as unhandled error. The same code was working well with V2, not sure how to address this now.
V3: 2018-01-21 10:09:18,795 Starting new HTTPS connection (1): api.kite.trade 2018-01-21 10:09:18,861 https://api.kite.trade:443 "POST /orders/regular HTTP/1.1" 200 58 2018-01-21 10:09:18,928 WebSocket connection lost: [Failure instance: Traceback: : the JSON object must be str, not 'bytes'
The only difference is the last field of POST, 'None' (v2) v/s 58 (v3). Guess the error is also due to this - expecting a string but getting a different data type.
@bluenile I just tested the scenario and it works fine. on_tick callback I was placing a market order and as expected order went through and I also got on_order_update callback.
Thanks for this! I have written the program in the same threaded manner as you have suggested, but I continued to get the same error.
Your efforts helped me realize the problem is local, so created another conda environment and ran the program there, things are working fine. Any suggestions on what could be going wrong in the other environment are welcome, but otherwise, this is good.
And thanks for your efforts in replicating the behaviour - it guided me to think differently to solve the problem!
@bluenile Seems like Python 3 unicode related issue where the value is type bytes instead of string. If you can get me full traceback it will be useful.
V2:
2018-01-19 09:15:27,872 Starting new HTTPS connection (1): api.kite.trade
2018-01-19 09:15:29,237 https://api.kite.trade:443 "POST /orders/regular HTTP/1.1" 200 None
V3:
2018-01-21 10:09:18,795 Starting new HTTPS connection (1): api.kite.trade
2018-01-21 10:09:18,861 https://api.kite.trade:443 "POST /orders/regular HTTP/1.1" 200 58
2018-01-21 10:09:18,928 WebSocket connection lost: [Failure instance: Traceback: : the JSON object must be str, not 'bytes'
The only difference is the last field of POST, 'None' (v2) v/s 58 (v3). Guess the error is also due to this - expecting a string but getting a different data type.
Please suggest how to change this. Thanks.
Here is my log
Ideally placing order and all should be done in separate thread from the ticker thread. Check example here - https://github.com/zerodhatech/pykiteconnect/blob/kite3/examples/threaded_ticker.py
Your efforts helped me realize the problem is local, so created another conda environment and ran the program there, things are working fine. Any suggestions on what could be going wrong in the other environment are welcome, but otherwise, this is good.
And thanks for your efforts in replicating the behaviour - it guided me to think differently to solve the problem!