question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question]: list_orders() Quantity

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

This is not a bug, it is a question. I can’t find any documentation or example about this.

I know how to show a list of orders:

api = alpaca.REST(api_key, api_secret, base_url, api_version='v2')  
ORDERS = api.list_orders()

But what I don’t know, is how to get the quantity of orders I have open right now. I don’t have the order id, I just have the symbol

For example: I want to know the exact qty of open orders I have to sell TSLA to avoid submitting another order.

Thanks in advance for your response.

Expected Behavior

Get orders qty

SDK Version I encountered this issue in

Alpaca-trade-api- == 2.0.0

Steps To Reproduce

Try to get the quantity of open orders for a given symbol (Ex: TSLA)

Filled out the Steps to Reproduce section?

  • I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.

Anything else?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
drew887commented, Apr 21, 2022

Ah sorry, did you mean the sum of the quantity field of all open orders? Not just the number of orders?

If that’s the case then that’s not really something we need to provide direct capabilities too into the SDK imo, as it would be common/easy enough to do it with general python functionality. IE reducing over the list of returned orders or using a for loop would be the first things that come to mind.

For example does something like :

from functools import reduce

api = alpaca.REST(api_key, api_secret, base_url, api_version='v2')  
orders = api.list_orders(symbols=['TSLA'])

total_qty = reduce(
      lambda result, order: result + int(order.qty),
      orders,
      0
)

give you the result you’re looking for?

0reactions
sshclicommented, Apr 21, 2022

@drew887 Sorry man, my mistake len(ORDERS) is the man.

Thanks again and sorry for the inconvenience

Read more comments on GitHub >

github_iconTop Results From Across the Web

ListOrders - Services.amazon.com
The ListOrders operation includes order information for each order returned, including AmazonOrderId, OrderStatus, FulfillmentChannel, and ...
Read more >
Amazon OA SDE-1 New Grad (2021 Batch) (India) - LeetCode ...
Working solution to the problem with full explanation : Logic : I've passed my comparator function and then applied the logic inside the...
Read more >
Iterate through all list orders - python - Stack Overflow
I first considered using a list to store the numbers 1 to 11 then just randomising the list order using the shuffle function....
Read more >
Aggregate Query Question - Salesforce Developer Community
I have a process that will read through an order when it is updated and determine if there are duplicate sku's on the...
Read more >
LINQ statement to list orders with outstanding items to be ...
I need a LINQ statement which generates a list of sales orders where there is an outstanding qty of items to be shipped...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found