简体   繁体   中英

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. I can stream quote and minute bar data through the web socket using:

    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:

    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?

We can connect to multiple websockets in parallel using Python threading module.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM