158 lines
6.0 KiB
Python
158 lines
6.0 KiB
Python
"""
|
|
|
|
AUTHOR:
|
|
|
|
Khushal P Soonderji
|
|
|
|
DATE:
|
|
|
|
Monday, 29th Sept., 2025
|
|
|
|
OBJECTIVE:
|
|
|
|
To broadcast live tick updates to connected clients. It doesn't matter which stockbroker we are getting the
|
|
ticks from as long as we are reading standardized ticks from the Kafka queue.
|
|
|
|
REFERENCES:
|
|
|
|
N/A
|
|
|
|
DOWNLOADS:
|
|
|
|
N/A
|
|
|
|
"""
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** IMPORT ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# To make sibling directories accessible for imports:
|
|
import sys
|
|
sys.path.append(".")
|
|
sys.path.append("..")
|
|
|
|
# System-level activities:
|
|
import io
|
|
import os
|
|
import random
|
|
|
|
# My utils:
|
|
from utils_v2.string import json
|
|
from utils_v2.string import regex
|
|
from utils_v2.system import files
|
|
from utils_v2.date_time import date_time
|
|
from utils_v2.database.async_mongo_v2 import AsyncMongo
|
|
from utils_v2.queue.kafka.controllers.async_kafka import ConsumerKafka, get_ssl_context
|
|
from utils_v2.cache.async_redis_cache_v3 import AsyncRedisCache
|
|
from utils_v2.serialization.json_serializer import JSONSerializer
|
|
|
|
# To make HTTP calls:
|
|
import httpx
|
|
|
|
# To work with date and time:
|
|
import datetime
|
|
import time
|
|
|
|
# Models:
|
|
from models.core.user import CoreUserInfoModel
|
|
from models.finstitutions.trading.ticks import TradingTick
|
|
|
|
# To work with SocketIO:
|
|
import socket
|
|
import socketio
|
|
|
|
# For asynchronous activities:
|
|
import asyncio
|
|
|
|
# To work with various datatypes:
|
|
from typing import List
|
|
|
|
# Debugging:
|
|
from icecream import IceCreamDebugger
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** MACROS / ONE-TIME INIT ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# Debugging:
|
|
printer = IceCreamDebugger(prefix = "Tick-Out | ", includeContext = True)
|
|
no_context_printer = IceCreamDebugger(prefix = "Tick-Out | ", includeContext = False)
|
|
|
|
# To make API calls:
|
|
http_client = httpx.AsyncClient(
|
|
limits = httpx.Limits(
|
|
max_connections = 100, # ............ Maximum number of connections allowed in the pool.
|
|
max_keepalive_connections = 50, # ... Maximum number of connections that can be kept alive.
|
|
),
|
|
timeout = httpx.Timeout(
|
|
pool = 120.0, # .... Time to wait for a free connection from the pool.
|
|
connect = 2.5, # ... Time to wait for establishing a connection to the server.
|
|
write = 10.0, # .... Time to wait for sending data.
|
|
read = 9.9 # ....... Time to wait for receiving data.
|
|
)
|
|
)
|
|
|
|
# General:
|
|
SERVER_HOSTNAME = str(socket.gethostname())
|
|
|
|
# For SocketIO:
|
|
# Namespaces:
|
|
NAMESPACE_MODULE = "/ticks"
|
|
# Events:
|
|
EVENT_CONNECT = "connect"
|
|
EVENT_DISCONNECT = "disconnect"
|
|
EVENT_ECHO = "echo"
|
|
EVENT_TICKS = "ticks"
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** VARIABLES ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** CLASSES ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** FUNCTIONS ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** MAIN PROGRAM ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pass
|
|
|