how can I list orders that I placed when market was closed. Those orders are marked as “NEW” when you placed when market is closed. which parameter should I pass to api.list_orders() in order to get those new orders?
How about filtering by order.submitted_at
and compare with market hours? This can be done in the client side.
I’m running into a similar problem. I’m just trying to get a list of my entire order history, but list_orders() doesn’t seem to want to return filled orders. Is there something I’m doing wrong?
If using the python alpaca-trade-api-python
SDK one can get a list of all unfilled orders something like this
# Imports we need. Also import pandas while we're at it. It'll come in handy later on.
import alpaca_trade_api as alpacaapi
import pandas as pd
# Set endpoints for either live or paper trading
ALPACA_API_ENDPOINT = 'https://paper-api.alpaca.markets'
ALPACA_API_KEY_ID = 'XXXXX'
ALPACA_API_SECRET_KEY = 'XXXXXXX'
# Get a reference to a a rest object
api = alpacaapi.REST(ALPACA_API_KEY_ID, ALPACA_API_SECRET_KEY, ALPACA_API_ENDPOINT)
# Get a list of all orders.
open_orders_list = api.list_orders(status='open')
Setting status='open'
will return only unfilled open orders. Setting status
to either ‘closed’ or ‘all’ will return only closed or all orders respectively. The default quantity returned is 50. To get more than that add the parameter limit
. The maximum however is 500. If one has more than 500 orders to return then the list will need to be ‘chunked’ into smaller pieces using the after
and/or until
parameters. Something like this will return up to 100 of the most recently closed orders
all_orders_list = api.list_orders(status='closed', limit=100)
The list is rather cumbersome to work with (IMHO). It can be easily turned into a dataframe like this
all_orders_df = pd.DataFrame([order._raw for order in all_orders_list])
Hope that helps. BTW welcome to the forums @Travis_Welch.
This is exactly the help I was looking for! I assumed the default value for status was all, but I was wrong. Thanks!