简体   繁体   English

How do I stream data from two different web sockets at the same time using the websocket.WebsocketApp in python?

[英]How do I stream data from two different web sockets at the same time using the websocket.WebsocketApp in python?

I am using the Alpca api to create a stock trading algorithm with Python.我正在使用 Alpca api 使用 Python 创建股票交易算法。 I can stream quote and minute bar data through the web socket using:我可以通过 web 套接字使用 stream 报价和分钟柱数据:

    socket = "wss://data.alpaca.markets/stream"

    ws = websocket.WebSocketApp(socket, on_open=on_open, on_message=on_message, 
    on_close=on_close)
    ws.run_forever()

However, I need to stream trade_update data at the same time from a different socket:但是,我需要同时从不同的套接字 stream trade_update 数据:

    socket = "wss://paper-api.alpaca.markets/stream "

How do I stream data from two different web sockets at the same time using the format above in python?如何使用 Z23EEEB4347BDD26B5FC6B777 中的上述格式同时使用来自两个不同 web sockets 的 stream 数据?

We can connect to multiple websockets in parallel using Python threading module.我们可以使用 Python 线程模块并行连接到多个 websocket。

Reference: https://steemit.com/utopian-io/@steempytutorials/part-3-connecting-and-managing-multiple-websocket-streams-in-parallel参考: https://steemit.com/utopian-io/@steempytutorials/part-3-connecting-and-managing-multiple-websocket-streams-in-parallel

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用python如何同时连接到两个不同的api,以便可以比较数据? - Using python how do I connect to two different api s at the same time so I can compare data? 如何使用python识别与套接字的两个不同连接? - How can I identify two different connections to sockets using python? 如何使用 websocket 客户端 python 使用 WebSocketApp(不是 create_connection)发送二进制数据 - How to send binary data with websocket client python use WebSocketApp (not create_connection) 同时读取多个Web套接字并在Python中绘制数据 - Read multiple web sockets at the same time and plot data in Python 如何同时执行 python 中的两个程序? - How do I execute two programs from python at the same time? 如何将来自 xarray 中不同数据集的两个变量相加,同时确保仅对具有相同坐标和时间的数据求和? - How do I sum two variables together from different datasets in xarray while ensuring only data with the same coordinates and time get summed? 使用 Python 的剧作家,我如何同时等待两个不同的选择器/句柄并取得第一个成功的匹配? - Using playwright for Python, how do I wait for two different selectors/handles at the same time and take the first successful match? Python,同时在两个套接字上侦听 - Python, Listening on two sockets at the same time 如何从Python中两个不同数据框中的两个不同索引中提取信息? - How do I do extract information from two different indices in two different data frames in Python? 如何在 Python 中同时发生两种不同的事情? - How do I make two different things happen at the same time in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM