alpacahq / alpaca-trade-api-python

Python client for Alpaca's trade API
https://pypi.org/project/alpaca-trade-api/
Apache License 2.0
1.73k stars 538 forks source link

[Bug]: Fails to install with Python 3.11 due to `aiohttp==3.8.1` dependency #671

Closed fumoboy007 closed 9 months ago

fumoboy007 commented 1 year ago

Is there an existing issue for this?

Current Behavior

Using Python 3.11, pip install alpaca-trade-api~=2.0 fails with the following error for the aiohttp dependency:

aiohttp/_websocket.c:198:12: fatal error: 'longintrepr.h' file not found
  #include "longintrepr.h"
           ^~~~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
----------------------------------------
ERROR: Failed building wheel for aiohttp

Expected Behavior

pip install alpaca-trade-api~=2.0 with Python 3.11 should succeed.

SDK Version I encountered this issue in

2.3.0

Steps To Reproduce

1. Use Python 3.11.
2. Run `pip install alpaca-trade-api~=2.0`.

Filled out the Steps to Reproduce section?

Anything else?

This issue has already been fixed starting with aiohttp version 3.8.3. However, the alpaca-trade-api package pins its aiohttp dependency to version 3.8.1. We should use a less restrictive requirement specification so that future aiohttp fixes are brought in automatically.

datttran commented 1 year ago

Is there any way I can install this with Python 3.11? I still have issue with aiohttp

sshcli commented 1 year ago

@datttran just move your code to the new official SDK alpaca-py alpaca-py is fully compatible with Python 3.11.

alighten-dev commented 1 year ago

@sshcli alpaca-py is fully compatible with 3.11 but the New API is not included in alpaca-py it's only in the alpaca-trade-api which is not compatible with 3.11

Name: aiohttp Version: 3.8.3

sshcli commented 1 year ago

@alighten-dev @datttran @fumoboy007 the alpaca-trade-api is no longer supported.

Just install alpaca-pyand use the following code:

from alpaca.trading.client import TradingClient          # For trading api        
from alpaca.data import StockHistoricalDataClient       # For data 

api_key= 'xxxxxxxxxxxxxxxxxxxx'
api_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
api = TradingClient(api_key, api_secret, paper=True)
data = StockHistoricalDataClient(api_key, api_secret )
BaileySimrell commented 1 year ago

Ok so @sshcli, it seems this definitely fixes the build/install-related issue, however when trying to run any of the example historical data scripts from Alpaca's docs, they all lead to an ominous 400 error in python 3.11, however after switching to 3.9 in my virtual environment, everything works perfectly.

sshcli commented 1 year ago

@BaileySimrell most of the docs and examples you will find out there are still making reference to the old sdk alpaca-trade-api In terms of docs, this is the start point for the new sdk alpaca-py: https://alpaca.markets/docs/python-sdk/api_reference/index.html

BaileySimrell commented 1 year ago

@sshcli yes, I have definitely realized that ... though the examples from the getting started alpaca-py reference you sent did not work on python 3.11 on my machine. after switching to 3.9, they all worked.

sshcli commented 1 year ago

@BaileySimrell if the error you are getting now if different from the original error posted in this issue (aiohttp error) I recommend you to create a new issue with all possible details and exact steps to reproduce it, in the new alpaca-py repo