Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to parse responses #79

Open
ashwinkp opened this issue Feb 6, 2022 · 3 comments
Open

How to parse responses #79

ashwinkp opened this issue Feb 6, 2022 · 3 comments

Comments

@ashwinkp
Copy link

ashwinkp commented Feb 6, 2022

Hi,

I am able to place order what would be the best way to extract the order id from the response?
Currently the response has the structure
orderId = {'Success': {'NSE': {'message': 'Your AMO has been Placed: 12220207081042.', 'orderId': 12220207081042, 'price': 525, 'quantity': 1, 'tag': 'ALGO1'}}}

I am new to python so I am currently doing
order_Id= orderId ['Success']['NSE']['orderId']
which works but I suppose its not the best way to do...

A better way would have been if placer order sent a response of order_status type
where one could do
if order_status.status == 'Success'
print("Order ID: " order_status.status )

Any suggestions/comments?

TIA
Ashwin

@kalilinux-png
Copy link

`def order_status(order_Id):
''' This Function Is Used To Get Order Status Like Pending Or Traded ['staus'] == TRAD OR OPN OR CAN ['statusMessage']==Open or Completely Traded Order'''

    return client.order_report(order_Id)['success'][-1]['status']`

@ashwinkp
let me know if this help's you or not

@jayaprakashv2005
Copy link

even i am doing -> "order_Id= orderId ['Success']['NSE']['orderId']"
just add a try catch around it

@ashwinkp
Copy link
Author

@jayaprakashv2005

I wrote a class KResponse. This allows me to get the orderID, Success and other info from the response string in structure format. So now I can do.
resp = client.place_order(...)
orderResp = KResponse(resp)
return str(orderResp.orderId)

class KResponse(object):

def init(self, data):
res = data
if "Success" in res:
self.dict = res['Success']['NSE']
self.Success = True
self.exchange = 'NSE'
elif 'success' in res:
self.dict = res['success']['NSE']
self.Success = True
self.exchange = 'NSE'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants