diff --git a/kill_sio.sh b/kill_sio.sh new file mode 100644 index 0000000..7b6fe16 --- /dev/null +++ b/kill_sio.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Kill all the scripts: +echo "Killing the script." +pkill -9 -f "$(pwd)/wsio/finstitutions/trading/main.py" + +# All done: +echo "Done!" +exit 0 \ No newline at end of file diff --git a/playground/socketio/to_kafka.py b/playground/socketio/to_kafka.py index ff7a9b9..ab4c6ea 100644 --- a/playground/socketio/to_kafka.py +++ b/playground/socketio/to_kafka.py @@ -185,6 +185,7 @@ def main(): # Get the instruments of interest: response = httpx.post(url = r"https://api.thecaoffice.com/markets/watchlist/distincts") instruments_of_interest = response.json()["data"]["rs0"] + print("TOTAL INSTR. OF INTEREST:", len(instruments_of_interest)) symbols_of_interest = [i["symbol"] for i in instruments_of_interest] # Create an instance of Zerodha's Kite connection: @@ -192,17 +193,18 @@ def main(): kite.set_access_token(access_token) # Get the entire list of instruments: - instruments = kite.instruments(exchange = "NSE") - instruments += kite.instruments(exchange = "NFO") - instruments += kite.instruments(exchange = "BSE") - instruments += kite.instruments(exchange = "BFO") + instruments = [] + # instruments += kite.instruments(exchange = "NSE") + # instruments += kite.instruments(exchange = "NFO") + # instruments += kite.instruments(exchange = "BSE") + # instruments += kite.instruments(exchange = "BFO") instruments += kite.instruments(exchange = "MCX") - instruments += kite.instruments(exchange = "CDS") - instruments += kite.instruments(exchange = "BCD") + # instruments += kite.instruments(exchange = "CDS") + # instruments += kite.instruments(exchange = "BCD") # # Pick the instruments of interest: - # instruments = [TradingSymbol.from_zerodha_kite(i) for i in instruments[:1000]] - instruments = [TradingSymbol.from_zerodha_kite(i) for i in instruments if i["tradingsymbol"] in symbols_of_interest] + instruments = [TradingSymbol.from_zerodha_kite(i) for i in instruments[:1000]] + # instruments = [TradingSymbol.from_zerodha_kite(i) for i in instruments if i["tradingsymbol"] in symbols_of_interest] # Create the lookup: for i in instruments: diff --git a/run_sio.sh b/run_sio.sh new file mode 100644 index 0000000..4f1442f --- /dev/null +++ b/run_sio.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Use this to run the microservice without any docker setup. +source .venv/bin/activate +python3 "$(pwd)/wsio/finstitutions/trading/main.py" --host "0.0.0.0" --port 5214 --script-id "kps_cnv_KBC3MoaU" & +deactivate + +# All done: +echo "Done!" +exit 0 \ No newline at end of file diff --git a/wsio/finstitutions/trading/main.py b/wsio/finstitutions/trading/main.py index 6fa7430..fcc44d3 100644 --- a/wsio/finstitutions/trading/main.py +++ b/wsio/finstitutions/trading/main.py @@ -57,6 +57,7 @@ from models.finstitutions.trading.symbols import TradingSymbol from models.finstitutions.trading.ticks import TradingTick # To work with SocketIO: +import socket import socketio # For asynchronous activities: @@ -80,6 +81,9 @@ from icecream import IceCreamDebugger printer = IceCreamDebugger(prefix = "Tick-Disp, | ", includeContext = True) printer.disable() +# General: +SERVER_HOSTNAME = str(socket.gethostname()) + # For SocketIO: sio = socketio.AsyncServer(async_mode = "asgi") app = socketio.ASGIApp(sio) @@ -238,6 +242,7 @@ async def init(): ticks_from_kafka, consumer = ConsumerKafka( topic = "tickers", + group_id = f"{SERVER_HOSTNAME}_tickers", bootstrap_servers = "del.ditscentre.in:9092", security_protocol = "SSL", ssl_context = get_ssl_context(