How to establish a connection to receive live stock data

273 views Asked by At

I want to establish connection to receive live stock data from https://www.finanznachrichten.de/aktienkurse/realtime-kurse.htm. By looking at the connected websocket, which is wss://rt.finanznachrichten.de/lightstreamer, I thought it would be easy to receive data by adapting some python script from this post.

So my code looks like this:

import websocket
import threading
import time
import argparse

def on_message(ws, message):
    print(message)

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

def on_close(ws):
    print("### closed ###")

def on_open(ws):
    def run():
        ws.send("")
        # time.sleep(1)
        # ws.close()

    threading.Thread(target=run).start()

def main():

    url = "wss://rt.finanznachrichten.de/lightstreamer"
    websocket.enableTrace(True)
    ws = websocket.WebSocketApp(
        url, on_message=on_message, on_error=on_error, on_close=on_close
    )
    ws.on_open = on_open
    ws.run_forever()

if __name__ == "__main__":
    main()

The problem is, I always get 403 Forbidden response. Could someone tell me what am I missing? I don't have much knowledge about web programming, but I thought if a browser can connect to a websocket, so can python.

0

There are 0 answers