alpacahq / alpaca-py

The Official Python SDK for Alpaca API
https://alpaca.markets/sdks/python/getting_started.html
Apache License 2.0
505 stars 125 forks source link

[Bug]: #411

Closed kenchambers closed 3 weeks ago

kenchambers commented 5 months ago

Is there an existing issue for this?

Current Behavior

I don't seem to be able to get the stream to work. i am correctly instantiating DataStreamClient with valid keys from live import.

from dotenv import dotenv_values

from alpaca.data.enums import DataFeed
from alpaca.data.live import StockDataStream

# Load environment variables from .env file
config = dotenv_values(".env")

API_KEY = config['APCA_API_KEY_ID']
SECRET_KEY = config['APCA_API_SECRET_KEY']

# Instantiate the StockDataStream
stream = StockDataStream(
    api_key=API_KEY,
    secret_key=SECRET_KEY,
    feed=DataFeed.IEX,  # or DataFeed.SIP if you have access
)

print(stream)

# Define your callback function to handle incoming data
async def handle_bar(bar):
    # Process the bar data (this is just a placeholder, adjust according to your data structure)
    print(bar)

# Subscribe to live updates for a symbol, e.g., "AAPL"
stream.subscribe_bars(handle_bar, "AAPL")

# Start streaming
stream.run()

Expected Behavior

Expecting candles to come through, but only seeing:

<alpaca.data.live.stock.StockDataStream object at 0x11939f0b0> which is the print from instantiating client.

SDK Version I encountered this issue in

Name: alpaca-trade-api
Version: 3.2.0
Summary: Alpaca API python client
Home-page: https://github.com/alpacahq/alpaca-trade-api-python
Author: Alpaca

Steps To Reproduce

1. follow code example provided above

Filled out the Steps to Reproduce section?

Anything else?

thats it.

hiohiohio commented 4 months ago

@kenchambers could you please try this again when market is open when you have a chance?

hiohiohio commented 3 weeks ago

Please let me close as this seems trying to fetch data outside of market hours.