Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Streamz with websocket not steaming any data

オープン
#474 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
pandas, python

調査の方向性

Start at the WebSocket callbacks, update_dataframe, source.emit, and source.map(print_result) shown in the issue. Trace whether messages reach source.emit and whether the mapped consumer runs; done means identifying the missing connection or usage detail that prevents received data from being printed.

索引モデルが issue の本文から書いたものです。

説明

I am trying to figure out a right way of streaming data using streamz with websocket. My streaming data is loaded using websocket but not streaming anything.

import config
import websocket, json
import pandas as pd
from streamz.dataframe import DataFrame
from streamz import Stream
import time

ticker_list = ["SCHG"]

# Create DataFrame with specified columns and ticker_list as index
df = pd.DataFrame(columns=['Bid', 'Ask', 'Time'], index=ticker_list)

source = Stream()

def update_dataframe(json_message, df):
    ticker_data = json_message[0]
    ticker_symbol = ticker_data['S']
    df.loc[ticker_symbol, 'Bid'] = ticker_data['bp']
    df.loc[ticker_symbol, 'Ask'] = ticker_data['ap']
    df.loc[ticker_symbol, 'Time'] = pd.to_datetime(ticker_data['t'], unit='s').tz_localize('UTC').tz_convert('America/New_York').strftime('%Y-%m-%d %H:%M:%S%z')

    source.emit(df.copy())  # Emit the updated DataFrame to the stream

def on_open(ws):
    print("opened connection")
    # Authentication
    auth_data = {"action":"auth","key": config.API_KEY,"secret": config.SECRET_KEY}

    # Subscribe
    ws.send(json.dumps(auth_data))
    
    listen_message = {"action":"subscribe","quotes":ticker_list}
    ws.send(json.dumps(listen_message))
    print('subscribed')       

def on_message(ws, message):
    json_message = json.loads(message)
    
    # Update the DataFrame and emit it to the stream
    update_dataframe(json_message, df)

def on_close(ws):
    print("closed connection")

def print_result(x):
    print(x)

sink = source.map(print_result)  # Set up a sink to consume and process the emitted data

socket = "wss://stream.data.alpaca.markets/v2/iex"
ws = websocket.WebSocketApp(socket, on_open=on_open, on_message=on_message, on_close=on_close)
ws.run_forever()
主要言語
Python
スター
1.3k
フォーク
149
平均マージ
17時間 39分
マージ済み PR(30日)
1

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-streamz/streamz のほかの issue

python-streamz/streamz の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。