I have this Code to connect to the KuCoin web socket and receive the candle stick data. My question is: How can I save the message to a variable (maybe in a another script)? I want to use this data afterwards and save it to a database and then use it for calculations and ploting.
import asyncio
from kucoin.client import WsToken
from kucoin.ws_client import KucoinWsClient
async def kline_msg(msg):
if msg["topic"] == "/market/candles:SLP-USDT_30min":
print(msg["data"])
async def wsocket():
client = WsToken()
ws_client = await KucoinWsClient.create(None, client, kline_msg, private=False)
await ws_client.subscribe("/market/candles:SLP-USDT_30min")
while True:
print("Sleep until message")
await asyncio.sleep(60)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(wsocket())