Resetting utils subtree.

This commit is contained in:
yatmesh
2025-06-12 13:46:29 +05:30
parent c6ac5c6570
commit c03e75d30e
214 changed files with 290 additions and 148757 deletions
+154 -99
View File
@@ -32,6 +32,9 @@
# To make sibling directories accessible for imports:
import sys
import utils_v2.cache.async_redis_cache_v2
sys.path.append(".")
sys.path.append("..")
@@ -458,6 +461,51 @@ class TradingTick(BaseModel):
# Done here:
return modelled_ticks
@staticmethod
def time_setter(item):
if not item.get("expiryTs"):
return item
# Try parsing the expiry timestamp
expiry = date_time.parse_date_time(
item["expiryTs"],
timezone=date_time.TIMEZONE_UTC
)
# Handle case where parsing fails
if expiry is None:
return item # or log an error / raise exception
# Convert to the timezone of the exchange:
expiry = date_time.to_timezone(
expiry,
timezone=item["expiryTz"]
)
# Format for MariaDB:
item["expiryTs"] = expiry.strftime("%Y-%m-%d")
return item
@staticmethod
def redis_market_key(
exchange=None,
symbol=None,
segment=None,
expiry_date=None,
strike=None
):
# variable for each -
exchange = TradingTick.exchange if exchange is None else exchange
symbol = TradingTick.symbol if symbol is None else symbol
segment = TradingTick.segment if segment is None else segment
expiry_date = TradingTick.time_setter(TradingTick.exchgTs) if expiry_date is None else expiry_date
strike = TradingTick.strike if strike is None else strike
redis_key = {"exchange":exchange, "symbol":symbol, "segment":segment, "expiryDate":expiry_date, "strike":strike}
return redis_key
# ┓┏ ┓• ┓ •
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
@@ -512,104 +560,111 @@ class TradingTick(BaseModel):
if __name__ == "__main__":
zerodha_tick_a = {
"tradable": True,
"mode": "full",
"instrument_token": 408065,
"last_price": 1928.25,
"last_traded_quantity": 157,
"average_traded_price": 1942.5,
"volume_traded": 5596931,
"total_buy_quantity": 217126,
"total_sell_quantity": 380092,
"ohlc": {
"open": 1975.15,
"high": 1979.95,
"low": 1911.25,
"close": 1946.2
},
"change": -0.9223101428424646,
"last_trade_time": "2024-12-20 14:46:14",
"oi": 0,
"oi_day_high": 0,
"oi_day_low": 0,
"exchange_timestamp": "2024-12-20 14:46:15",
"depth": {
"buy": [
{
"quantity": 3,
"price": 1928.15,
"orders": 2
},
{
"quantity": 6,
"price": 1927.95,
"orders": 2
},
{
"quantity": 66,
"price": 1927.7,
"orders": 2
},
{
"quantity": 25,
"price": 1927.65,
"orders": 1
},
{
"quantity": 194,
"price": 1927.6,
"orders": 6
}
],
"sell": [
{
"quantity": 134,
"price": 1928.25,
"orders": 5
},
{
"quantity": 3,
"price": 1928.3,
"orders": 1
},
{
"quantity": 560,
"price": 1928.35,
"orders": 2
},
{
"quantity": 64,
"price": 1928.4,
"orders": 2
},
{
"quantity": 400,
"price": 1928.45,
"orders": 1
}
]
}
}
zerodha_tick_b = {
}
zerodha_lookup = {
408065: {
"symbol": "MYSTOCK",
"exchange": "NSE",
"exchangeToken": 12345678,
"segment": "NFO-OPT",
"type": "CE",
"expiryTs": "2024-12-20",
"expiryTz": "Asia/Kolkata"
}
}
my_ticks = TradingTick.from_zerodha_kite(
ticks = [zerodha_tick_a],
instrument_lookup = zerodha_lookup
trade = TradingTick
trade.redis_market_key_maker(
exchange="TATA",
segment="EQ"
)
print(json.to_string(my_ticks[0].model_dump(), default = str))
print(json.to_string(my_ticks[0].summary, default = str))
# zerodha_tick_a = {
# "tradable": True,
# "mode": "full",
# "instrument_token": 408065,
# "last_price": 1928.25,
# "last_traded_quantity": 157,
# "average_traded_price": 1942.5,
# "volume_traded": 5596931,
# "total_buy_quantity": 217126,
# "total_sell_quantity": 380092,
# "ohlc": {
# "open": 1975.15,
# "high": 1979.95,
# "low": 1911.25,
# "close": 1946.2
# },
# "change": -0.9223101428424646,
# "last_trade_time": "2024-12-20 14:46:14",
# "oi": 0,
# "oi_day_high": 0,
# "oi_day_low": 0,
# "exchange_timestamp": "2024-12-20 14:46:15",
# "depth": {
# "buy": [
# {
# "quantity": 3,
# "price": 1928.15,
# "orders": 2
# },
# {
# "quantity": 6,
# "price": 1927.95,
# "orders": 2
# },
# {
# "quantity": 66,
# "price": 1927.7,
# "orders": 2
# },
# {
# "quantity": 25,
# "price": 1927.65,
# "orders": 1
# },
# {
# "quantity": 194,
# "price": 1927.6,
# "orders": 6
# }
# ],
# "sell": [
# {
# "quantity": 134,
# "price": 1928.25,
# "orders": 5
# },
# {
# "quantity": 3,
# "price": 1928.3,
# "orders": 1
# },
# {
# "quantity": 560,
# "price": 1928.35,
# "orders": 2
# },
# {
# "quantity": 64,
# "price": 1928.4,
# "orders": 2
# },
# {
# "quantity": 400,
# "price": 1928.45,
# "orders": 1
# }
# ]
# }
# }
# zerodha_tick_b = {
#
# }
# zerodha_lookup = {
# 408065: {
# "symbol": "MYSTOCK",
# "exchange": "NSE",
# "exchangeToken": 12345678,
# "segment": "NFO-OPT",
# "type": "CE",
# "expiryTs": "2024-12-20",
# "expiryTz": "Asia/Kolkata"
# }
# }
#
# my_ticks = TradingTick.from_zerodha_kite(
# ticks = [zerodha_tick_a],
# instrument_lookup = zerodha_lookup
# )
#
# print(json.to_string(my_ticks[0].model_dump(), default = str))
# print(json.to_string(my_ticks[0].summary, default = str))
+12
View File
@@ -123,6 +123,18 @@ class NimbusWhatsAppMessage(BaseModel):
default = None
)
# ---- ADDED BY OMKAR 2025-05-13 ----
waGroupId: str = Field(
description="The Whatsapp group ID. of the target recipient(s) group",
frozen=True
)
waGroupName: str | None = Field(
description="The actual group name.",
frozen=True,
default=None
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫