danpaquin / coinbasepro-python

The unofficial Python client for the Coinbase Pro API
MIT License
1.82k stars 732 forks source link

How to loop through orders returned from get_orders? #230

Closed sdenenberg closed 6 years ago

sdenenberg commented 6 years ago

Hello,

I'm trying to loop through orders returned from the call get_orders. No matter what I do I don't seem to be able to access the individual list elements. For example, I want to know each outstanding orders id. Can anyone advise?

Thanks,

Scott

davidmmiller7 commented 6 years ago

@sdenenberg, the get_orders method returns a "paginated" list of lists, so you need a nested for loop to work with it. These lists contain dictionary objects. So generally you can handle it like this, where 'myKey' is 'id' in this case.

for page in orders:     for order in page:         if 'myKey' in list(order.keys()):             pprint(order)

This isn't a gdax-python issue in my opinion--I recommend you check out StackOverflow.com for these types of questions. gdax-python just helps you avoid dealing with the REST API--you still need to be able to do some legwork in Python. Also, instead of saying "no matter what I do", please provide some example code and tell us what your setup is (Python version, etc...) so people can help you better.

sdenenberg commented 6 years ago

@davidmmiller7 thank you very much. I'm relatively new to python and the concept of "paginated" lists was lost on me. I very much appreciate your timely response and your feedback.

davidmmiller7 commented 6 years ago

@sdenenberg No problem! I've only been doing this for a few short years so I'm glad I can help. Python is a great language to learn. Best of luck.

@danpaquin Recommend closing this issue.