Websocket Stream Data to Excel

56 views
Skip to first unread message

Beat Degree

unread,
Mar 21, 2023, 2:21:33 AM3/21/23
to sup...@xlslim.com
Hi,

I'm a Python beginner but an Excel Expert.

To cut a long story short i have an excel application which uses REST API but i want to upgrade some of the datafeeds to be websocket.

Python seems to be able to "subscribe" to Websockets but i have no idea how i would get that data streamed over to my User Interface in Excel.

Is this something xlWings can do?

Thanks

import websockets
import asyncio
import json

async def main():
uri = "wss://www.bitmex.com/realtime"
async with websockets.connect(uri) as websocket:
# Send a message to subscribe to XBTUSD updates
msg = {
"op": "subscribe",
"args": ["orderBookL2_25:XBTUSD"]
}
await websocket.send(json.dumps(msg))

# Receive messages in a loop and print them out
while True:
result = await websocket.recv()
data = json.loads(result)

#print(json.dumps(data))
print((data))

if __name__ == "__main__":
# Run the 'main' function in an asyncio event loop
loop = asyncio.get_event_loop()
loop.create_task(main())
loop.run_forever()

xlSlim Dev

unread,
Mar 21, 2023, 4:13:26 AM3/21/23
to xlSlim Support
Hello,

xlSlim can help. Looking at your main() function, if you turn it into a generator by adding "yield data" after "print((data))", you will then be able to register the module and stream the data into Excel.



Let me know how you get on.

All the best,
Russel
Reply all
Reply to author
Forward
0 new messages