Is it expected behavior for the alpaca historical trades api to throw an error if there are no trades?

That doesn’t seem right.

@connorcreate What specific endpoint and/or method are you using? In general, if there are no trades then a 200 valid response is returned but there is just no JSON data. Here is an example trying to fetch trades on a Saturday (when there are no trades). The response is simply an empty set and no error.

I am using the new alpaca-py library so it actually may just be an issue with that ( I am sorry for not clarifying that). If I call this during a valid trading day it works fine but on days or times when no trades happen I get this exception thrown.

request = StockTradesRequest(symbol_or_symbols='AAPL', start=datetime(2011, 1, 1, 14, 0, 0), end=datetime(2011, 1, 1, 14, 1, 0))

stock_client.get_stock_trades(request)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[32], line 2
      1 request = StockTradesRequest(symbol_or_symbols='AAPL', start=datetime(2011, 1, 1, 14, 0, 0), end=datetime(2011, 1, 1, 14, 1, 0))
----> 2 stock_client.get_stock_trades(request)
      3 # trade_client.get_calendar(GetCalendarRequest(start=datetime(2010, 1, 4, 14, 0, 0), end=datetime(2010, 1, 4, 14, 1, 0)))

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\alpaca\data\historical\stock.py:151, in StockHistoricalDataClient.get_stock_trades(self, request_params)
    148 if self._use_raw_data:
    149     return raw_trades
--> 151 return TradeSet(raw_trades)

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\alpaca\data\models\trades.py:69, in TradeSet.__init__(self, raw_data)
     66 parsed_trades = {}
     68 for symbol, trades in raw_data.items():
---> 69     parsed_trades[symbol] = [Trade(symbol, trade) for trade in trades]
     71 super().__init__(data=parsed_trades)

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\alpaca\data\models\trades.py:69, in (.0)
     66 parsed_trades = {}
     68 for symbol, trades in raw_data.items():
---> 69     parsed_trades[symbol] = [Trade(symbol, trade) for trade in trades]
     71 super().__init__(data=parsed_trades)

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\alpaca\data\models\trades.py:44, in Trade.__init__(self, symbol, raw_data)
...
     45         if key in TRADE_MAPPING
     46     }
     48     super().__init__(symbol=symbol, **mapped_trade)

AttributeError: 'NoneType' object has no attribute 'items'```

@connorcreate I think what the SDK is complaining about is your symbol_or_symbols. It wants it to be a list. Like this

request = StockTradesRequest(symbol_or_symbols=['AAPL'], 
                             start=datetime.datetime(2018, 1, 1, 14, 0, 0), 
                             end=datetime.datetime(2018, 1, 1, 14, 1, 0),
)

data_client.get_stock_trades(request)

Try that.

The python typing says it does allow strings and when I pass in strings on valid timeframes it returns data. Here is an image showing both of those things :slight_smile:

@connorcreate Agreed, it’s funny that a list doesn’t throw that error. Sort of a bug? @rahul