Comments (7)
@hiohiohio, I tried following your suggestion, but unfortunately, I'm still encountering the same error.
from alpaca-py.
@hiohiohio I encountered the same error when I ran your code: data websocket error, restarting connection: server rejected WebSocket connection: HTTP 404.
To troubleshoot, I implemented my own code to make a request to wss://stream.data.alpaca.markets/v1beta3/crypto/us
, and it worked seamlessly without encountering any issues. Below is the code for reference:
import asyncio
import websockets
import json
from autotrader.configs.alpaca_settings import ALPACA_API_KEY, ALPACA_SECRET_KEY
async def connect_to_websocket():
uri = "wss://stream.data.alpaca.markets/v1beta3/crypto/us"
async with websockets.connect(uri) as websocket:
auth_data = {
"action": "auth",
"key": ALPACA_API_KEY,
"secret": ALPACA_SECRET_KEY
}
await websocket.send(json.dumps(auth_data))
subscribe_data = {
"action": "subscribe",
"trades": ["BTC/USD"],
"quotes": ["LTC/USD", "ETH/USD"],
"bars": ["BCH/USD"]
}
await websocket.send(json.dumps(subscribe_data))
async for message in websocket:
print(message)
asyncio.run(connect_to_websocket())
This code establishes a WebSocket connection without encountering the mentioned error. Please let me know if you have any insights into why the original code might be facing this issue.
from alpaca-py.
@CurtMRosenbladWheeler Thank you for the issue report. Can you please try to use BTC/USD
instead of BTCUSD
?
from alpaca-py.
@CurtMRosenbladWheeler hmmm. the below code works for me (Sorry, I am currently hitting the rate limit, so cannot try with your code). May I please ask you to provide actual logs of the error if possible?
from alpaca.data.live import CryptoDataStream
stream = CryptoDataStream(
api_key=API_KEY,
secret_key=API_SECRET,
)
symbol = "BTC/USD"
async def handler(data):
print(data)
stream.subscribe_quotes(handler, symbol)
stream.subscribe_trades(handler, symbol)
stream.run()
from alpaca-py.
@CurtMRosenbladWheeler thank you for the update and detailed info. Appreciate. It helps me a lot. Unfortunately, I still cannot reproduce the error you mentioned in my env. May I please ask you to provide the version of below libraries and python? I think the issue could be coming from library compatibility issues.
python
msgpack
pydantic
pydantic_core
websockets
from alpaca-py.
Found a way to reproduce this and created a PR to fix.
#385
from alpaca-py.
Hey everyone! I can't import alpaca.data.live. I've downloaded the alpaca-py. Please help me :)
from alpaca-py.
Related Issues (20)
- [Bug]: trading_client.get_account only works on Paper=False, if using Paper=True -> unauthorized (even with Paper keys) HOT 2
- [Bug]: StockHistoricalDataClient produces a wrong URL HOT 4
- [Question]: How can I inherit the sdk's classes e.g. TradingClient? HOT 3
- [Bug]: Incompatibility with Google Colab pre-installed dependencies HOT 2
- [Bug]: noisy model_* pydantic attributes HOT 2
- [Bug]: Corporate actions support broken HOT 2
- [Question]: How to understand the number of API calls I'm making?
- [Bug]: error during websocket communication: 4 validation errors for TradeUpdate HOT 8
- [Bug]: Paper API - quantity in opened position is not the same as requested in market order HOT 1
- Can you download documents? HOT 3
- [Bug]: Websockets conflict HOT 2
- Fix link of docs in repo page HOT 1
- [Question]: How to get hourly historical data starting from 9:30am (NY time)? HOT 1
- light edit for docs
- [Bug]: Order stuck in pending_cancel
- [Bug]: potentially unnecessary parameter is required when submitting OCO orders
- [Bug]: PydanticUserError: If you use `@root_validator` with pre=False (the default) you MUST specify `skip_on_failure=True`. Note that `@root_validator` is deprecated and should be replaced with `@model_validator`. HOT 2
- [Bug]: HOT 1
- [Bug]: Unable to execute ReplaceOrderRequest on a stop loss order HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alpaca-py.