<jupyter_start><jupyter_text><jupyter_code>pip install websocket-client

import websocket, json

cc = 'btcusd'
interval = '1m'
socket = f'wss://stream.binance.com:9443/ws/{cc}t@kline_{interval}'
socket
closes, highs, lows = [], [], []
# making candlesticks

def on_message(ws, message):
    json_message = json.loads(message)
    candle = json_message['k']
    is_candle_closed = candle['x']
    close = candle['c']
    high = candle ['h']
    low = candle['l']
    vol = candle['v']

    if is_candle_closed:
      closes.append(float(close))
      highs.append(float(high))
      lows.append(float(low))

      print(closes)
      print(highs)
      print(lows)

def on_close(ws, close_status_code, close_msg):
    print("Connection Closed")

ws = websocket.WebSocketApp(socket,on_message = on_message, on_close = on_close)
ws.run_forever()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1444954128440367, 'fraction_numerical': 0.005733944954128441, 'mean_word_length': 4.259036144578313, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '238392', 'license': 'MIT', 'n_tokens_mistral': 329, 'n_tokens_neox': 324, 'n_words': 56, 'path': 'Copy_of_Websocket_Binance_Python.ipynb', 'repo_name': 'nkipa/Build-an-AI-Startup-with-PyTorch', 'size': '872'}