1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Passing websocket data to another python program

Discussão em 'Python' iniciado por Stack, Setembro 14, 2024.

  1. Stack

    Stack Membro Participativo

    I have a fairly typical websocket-client program that reads from the wss server.

    import asyncio
    import json
    import websockets

    api_data = {
    "type": "subscribe",
    "channel": "v4_orderbook",
    "id": 'BTC-USD',
    }

    async def wsrun(uri):
    async for websocket in websockets.connect(uri):
    await websocket.send(json.dumps(api_data))
    while True:
    print(await websocket.recv())

    asyncio.get_event_loop().run_until_complete(wsrun('wss://indexer.v4testnet.dydx.exchange/v4/ws'))


    The above program as it is written above just prints all the data to the screen, but what I need to do is pass the data to another python program asynchronously. So that means i have to replace the print() statement but I have no idea what to do.

    The reason I have to do that is because the second program may need to take time to process the data while the first program (that reads the websocket) can't be delayed at all and must keep running and not lose any messages. Given a sufficiently large buffer so that the first program can keep pumping data into the buffer without waiting for the second program.

    Continue reading...

Compartilhe esta Página