kiteconnect-rs
kiteconnect-rs copied to clipboard
index change field is returned instead of timestamp
// Index quote/full
28 | 32 => {
let mut data: JsonValue = json!({
"tradable": tradable,
"mode": if packet_length == 28 {"quote"} else {"full"},
"instrument_token": instrument_token,
"last_price": reader.read_i32::<BigEndian>().unwrap() as f64 / divisor,
"ohlc": {
"high": reader.read_i32::<BigEndian>().unwrap() as f64 / divisor,
"low": reader.read_i32::<BigEndian>().unwrap() as f64 / divisor,
"open": reader.read_i32::<BigEndian>().unwrap() as f64 / divisor,
"close": reader.read_i32::<BigEndian>().unwrap() as f64 / divisor,
},
"change": 0
});
if data["ohlc"]["close"] != 0 {
let last_price: f64 = data["last_price"].as_f64().unwrap();
let ohlc_close: f64 = data["ohlc"]["close"].as_f64().unwrap();
data["change"] = json!((last_price - ohlc_close) * 100 as f64 / ohlc_close);
}
if packet_length == 32 { // timestamp incase of full
data["timestamp"] = json!(reader.read_i32::<BigEndian>().unwrap() as f64 / divisor);
}
tick_data.push(data);
},
In https://github.com/zerodha/kiteconnect-rs/blob/7fdd0a19e189c32cc0ebf77febba9af2badf9788/src/ticker.rs#L242
We are doing data["timestamp"] = json!(reader.read_i32::<BigEndian>().unwrap() as f64 / divisor); which will read the next 4bytes after the close value which is change instead of timestamp
timestamp is the next 4bytes after change
So it should be something like
data["change"] = json!(reader.read_i32::<BigEndian>().unwrap() as f64 / divisor);
// and then
if packet_length == 32 { // timestamp incase of full
data["timestamp"] = json!(reader.read_i32::<BigEndian>().unwrap() as f64 / divisor);
}
Reference

@joeirimpan