Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

index change field is returned instead of timestamp #36

Open
asnimansari opened this issue Jun 8, 2021 · 1 comment
Open

index change field is returned instead of timestamp #36

asnimansari opened this issue Jun 8, 2021 · 1 comment

Comments

@asnimansari
Copy link
Contributor

asnimansari commented Jun 8, 2021

                     // 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

data["timestamp"] = json!(reader.read_i32::<BigEndian>().unwrap() as f64 / divisor);

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

image

@asnimansari
Copy link
Contributor Author

@joeirimpan

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant