Sandbox testing for postback

mohit839
Hi.
Is there a way to test various place order and trades postback in a sandbox test environment.
Someplace where we can place some dummy orders and simulate the real time receipt of postbacks without actually carrying out real trades.
  • sujith
    You can place order post market and try it out. Please note that you will only receive postback if order gets executed. If it is rejected by our mini RMS then you will get 400 http status code and there won't be an entry in the orderbook.
  • mohit839
    I was trying to automate the login (request token related) and came across a couple of options using selenium and others. is there a official way on how that should be done. due to numerous attempts, my account got locked and I had to reset once. a sandbox would have been useful in that scenario. also to test the code logic when an order does get executed a sandbox would be helpful. currently I am checking using postman.
  • sujith
    It is mandatory by the exchange that a user has to login manually at least once a day. We don't recommend automating login as it is against the regulations.

    You may refer to the example here.
  • mohit839
    I am not able to get postback to work . I have the following code (this works fine when I test using postman.
    kite = get_kite_client()
    logging.info("Callback received")
    json_payload = json.loads(request.data)
    if json_payload['status'] == 'COMPLETE' :
    do_something()

    f = open(log_name(),'a+')
    f.write(json_payload['order_id']+' '+json_payload['tradingsymbol']+' '+json_payload['status']+'\n')
    f.close()
    return 'done'

    In real working, it gives me the following error
    2023-10-09 11:04:24,862: Exception on /post [POST]
    Traceback (most recent call last):
    File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
    File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
    File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
    File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
    File "/home/vbalgo/mysite/flask_app.py", line 263, in post
    json_payload = json.loads(request.data)
    File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
    File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
    json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)


    Secondly, if I have 2 algos running, is there a way for postback to also receive some intimation about which algo this order is associated with. I can probably note down order_ids at my end and based on that route it to the correct algo internally as well. But want to know if that that is the best way to do it.
Sign In or Register to comment.