(20241226) Change and Percent Change bug fixed for Zerodha's ticks.

This commit is contained in:
2024-12-26 11:53:47 +05:30
parent a8449ebaef
commit 8e89575032
3 changed files with 53 additions and 28 deletions
+15 -7
View File
@@ -208,6 +208,11 @@ class TradingTick(BaseModel):
examples = ["UTC", "Asia/Kolkata"]
)
prevClose: float = Field(
description = "the closing price of this instrument on the previous day",
frozen = True
)
ltp: float = Field(
description = "the last price of this instrument at the time of requesting the symbol list",
frozen = True
@@ -233,17 +238,17 @@ class TradingTick(BaseModel):
)
h: float = Field(
description = "this session's high price",
description = "this session's highest price",
frozen = True
)
l: float = Field(
description = "this session's low price",
description = "this session's lowest price",
frozen = True
)
c: float = Field(
description = "this session's close price",
description = "this session's close price; typically the same as the ltp",
frozen = True
)
@@ -364,7 +369,7 @@ class TradingTick(BaseModel):
"ltp": self.ltp,
"chg": self.chg,
"pChg": self.pChg,
"totVol": self.totVol,
"totVol": self.totVol
}
@staticmethod
@@ -383,8 +388,10 @@ class TradingTick(BaseModel):
# Stash frequently needed vars:
broker_token = tick["instrument_token"]
tick_lookup = instrument_lookup[broker_token]
change = tick["change"]
last_price = tick["last_price"]
prev_close = tick["ohlc"]["close"]
change = last_price - prev_close
p_change = tick["change"]
# Model the currently picked tick:
modelled_ticks.append(
@@ -400,14 +407,15 @@ class TradingTick(BaseModel):
strike = tick_lookup.get("strike"),
expiryTs = tick_lookup.get("expiryTs"),
expiryTz = tick_lookup.get("expiryTz"),
prevClose = prev_close,
ltp = last_price,
qty = tick.get("last_traded_quantity"),
chg = change,
pChg = change / (last_price - change),
pChg = p_change,
o = tick["ohlc"]["open"],
h = tick["ohlc"]["high"],
l = tick["ohlc"]["low"],
c = tick["ohlc"]["close"],
c = last_price,
totVol = tick.get("volume_traded"),
vwap = tick.get("average_traded_price"),
totBuyQty = tick.get("total_buy_quantity"),