(20250108) Tick-In script handles the buffer better.

This commit is contained in:
2025-01-08 12:23:46 +05:30
parent 505232faff
commit 81fc28295f
4 changed files with 56 additions and 15 deletions
+24 -7
View File
@@ -291,29 +291,36 @@ class TradingTick(BaseModel):
frozen = True
)
tradeTs: AwareDatetime | None = Field(
rcvdTs: AwareDatetime | None = Field(
description = "the time (utc) at which this update was received",
frozen = True,
default = None,
validate_default = True
)
tradeTs: AwareDatetime | None = Field(
description = "the last trade time (utc) of this instrument",
frozen = True
)
tradeTz: str | None = Field(
tradeTz: str | None = Field(
description = "the timezone in which the last trade time should be interpreted; should be compatible with pytz",
frozen = True,
examples = ["UTC", "Asia/Kolkata"]
)
exchgTs: AwareDatetime | None = Field(
exchgTs: AwareDatetime | None = Field(
description = "the time (utc) at which this update was received from the exchange",
frozen = True
)
exchgTz: str | None = Field(
exchgTz: str | None = Field(
description = "the timezone in which the exchange's time should be interpreted; should be compatible with pytz",
frozen = True,
examples = ["UTC", "Asia/Kolkata"]
)
depth: MarketDepth | None = Field(
depth: MarketDepth | None = Field(
description = "the market depth data for this instrument at the time of this update"
)
@@ -380,14 +387,18 @@ class TradingTick(BaseModel):
"pChg": self.pChg,
"vwap": self.vwap,
"totVol": self.totVol,
"rcvdTs": self.rcvdTs.timestamp(),
"tradeTs": self.tradeTs.timestamp(),
"tradeTz": self.tradeTz
"tradeTz": self.tradeTz,
"exchgTs": self.exchgTs.timestamp(),
"exchgTz": self.exchgTz
}
@staticmethod
def from_zerodha_kite(
ticks: dict | List[dict],
instrument_lookup: dict
instrument_lookup: dict,
received_ts: datetime.datetime = None
) -> list:
# Ensure that we are working with a list:
@@ -436,6 +447,7 @@ class TradingTick(BaseModel):
oi = tick.get("oi"),
oiDayHigh = tick.get("oi_day_high"),
oiDayLow = tick.get("oi_day_low"),
rcvdTs = received_ts,
tradeTs = tick.get("last_trade_time"),
tradeTz = "Asia/Kolkata",
exchgTs = tick.get("exchange_timestamp"),
@@ -485,6 +497,11 @@ class TradingTick(BaseModel):
# Done here:
return value
@field_validator("rcvdTs", mode = "before")
def validate_received_timestamp(cls, value):
if value is None: value = date_time.get_current_utc_date_time(as_string = False)
return value
# *****************************************************************************************************************
# ***** ****