Tree Service
  • 🌳Welcome
    • How to Subscribe
  • 📈Tree Terminal
    • Installation
    • Setup
      • Create Binance API
      • Create Bybit API
      • Create OKX API
    • First-Timer Checklist
    • Features
      • 📈Charts
      • 📰News feed
      • 📋Command line
      • 💸Positions & orders
      • 💰Accounts
      • 💲Symbols
      • 🤖Botting
      • 📕Orderbook
      • 👆Buttons
      • Customization
      • 🔔Notifications
      • Filters
    • Security
    • FAQ
  • 🗃️Websockets
    • API Key
    • Python connection
    • JavaScript connection
    • Response
    • Like/Dislike feature
    • News history
Powered by GitBook
On this page
  1. Websockets

Python connection

Websocket connection using python

import websocket

def on_message(ws, message):
    print(f"Received: {message}")

def on_error(ws, error):
    print(error)

def on_close(ws, close_status_code, close_msg):
    print("### closed ###")

def on_open(ws):
    ws.send(f"login {API_KEY}")

if __name__ == "__main__":
    websocket.enableTrace(True)
    ws = websocket.WebSocketApp("wss://news.treeofalpha.com/ws",
                              on_open=on_open,
                              on_message=on_message,
                              on_error=on_error,
                              on_close=on_close)

    ws.run_forever()
PreviousAPI KeyNextJavaScript connection

Last updated 5 months ago

🗃️