You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to retrieve all trades across several days for a given symbol. My strategy is to run get_trades_async for each date separately. Below, I test get_trades_async for a single date, where I attempt to retrieve all trades for SPY on October 11, 2024. When I run the following, I get a type error:
symb, tf = asyncio.run(async_rest_data_client.get_trades_async('SPY','2024-10-11', '2024-10-11',limit=None))
>> raise TypeError(
TypeError: Invalid variable type: value should be str, int or float, got None of type <class 'NoneType'>
Expected Behavior
The underlying Alpaca API only accepts a limit between 1 and 10,000. It defaults to 1,000 if no limit is given. However, a "next_page_token" is provided in order to continue requesting more data where it left off in case of a request larger than 10,000 (as in my case). The _request function keeps requesting packets until "next_page_token" is no longer available. This is good. However, the purpose of this is defeated when limit is reached in the calling for-loop:
async def _iterate_requests(self,
...
async for packet in self._request(url, payload):
...
if len(df) >= limit:
break
return df
async def _request(self, url, payload):
...
while 1:
async with session.get(url, **opts) as response:
response = await response.json()
page_token = response.get('next_page_token')
payload["page_token"] = page_token
yield response
if not page_token:
break
Entering a limit > 10,000 to avoid an early break will append this limit to the url and cause Alpaca to not return anything at all. Entering a limit of None will cause TypeError.
SDK Version I encountered this issue in
Alpaca Trade API version: 3.0.0
Steps To Reproduce
Run
asyncio.run(async_rest_data_client.get_trades_async('SPY','2024-10-11', '2024-10-11',limit=None))
### Filled out the Steps to Reproduce section?
- [X] 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_
The text was updated successfully, but these errors were encountered:
mj-z-ali
added a commit
to mj-z-ali/alpaca-trade-api-python
that referenced
this issue
Oct 14, 2024
Is there an existing issue for this?
Current Behavior
I would like to retrieve all trades across several days for a given symbol. My strategy is to run
get_trades_async
for each date separately. Below, I testget_trades_async
for a single date, where I attempt to retrieve all trades for SPY on October 11, 2024. When I run the following, I get a type error:Expected Behavior
The underlying Alpaca API only accepts a limit between 1 and 10,000. It defaults to 1,000 if no limit is given. However, a
"next_page_token"
is provided in order to continue requesting more data where it left off in case of a request larger than 10,000 (as in my case). The_request
function keeps requesting packets until"next_page_token"
is no longer available. This is good. However, the purpose of this is defeated whenlimit
is reached in the calling for-loop:Entering a limit > 10,000 to avoid an early break will append this limit to the url and cause Alpaca to not return anything at all. Entering a limit of None will cause TypeError.
SDK Version I encountered this issue in
Alpaca Trade API version: 3.0.0
Steps To Reproduce
Produces TypeError.
Run
Produces empty dataframe.
The text was updated successfully, but these errors were encountered: