I’m trying to get a list of orders after a specific date through Alpaca-py. I’m getting an error
{“code”:40010001,“message”:“invalid format for after; format: ‘2006-01-02T15:04:05Z’”}
Can someone give an example of how to set the “after” parameter correctly?
Thanks
@Kun_Zhao The alpaca-py SDK is rather finicky. It doesn’t like timezone aware datetimes. I find it easiest to use the pandas to_datetime
method and then remove the timezone by using tz_convert(None)
. Like this
!pip install alpaca-py
import pandas as pd
from alpaca.trading.client import TradingClient
from alpaca.trading.requests import GetOrdersRequest
trading_client = TradingClient(ALPACA_API_KEY_ID_PAPER,
ALPACA_API_SECRET_KEY_PAPER,
paper=True,
raw_data=True,
)
orders_request = GetOrdersRequest(status=‘all’,
after=pd.to_datetime(“20o6-01-02T15:04:05Z”).tz_convert(None),
limit=500,
nested=False,
)
all_orders_list = trading_client.get_orders(orders_request)
@Dan_Whitnable_Alpaca Thanks for your help!
It seems there is a new datelimt in GetOrdersRequest, can’t get closed orders older than 4 days?