fasenderos / nodejs-order-book

Ultra-fast Node.js Order Book written in TypeScript for high-frequency trading (HFT) :rocket::rocket:
https://github.com/fasenderos/nodejs-order-book
MIT License
143 stars 35 forks source link

How to get the latest price and trades from OrderBook #403

Closed loongmxbt closed 3 months ago

loongmxbt commented 4 months ago

Hi, I'm new to orderbook. How can I get the latest price and historical trades from the orderbook. I've checked lob.snapshot(); and seems no last trade price inside it. Thanks in advance!

fasenderos commented 4 months ago

Hi, just to understand what the use case of this feature would be? At the moment, you need to keep track of the responses received from the order book for each order.

loongmxbt commented 4 months ago

@fasenderos Hi, I want to have a sheduler to get the latest price every 1s or 5s, and send them to subscribers. and I thought I have to get the latest price from the orderbook snapshot.

fasenderos commented 3 months ago

The snapshot isn’t intended for that, and calling every second or so can potentially degrade the order book performance.

At the moment, you need to keep track of the responses received from the order book for each order, however I’m working on new features and one of them expose the market price of the order book.

loongmxbt commented 3 months ago

@fasenderos Thanks for your answer! Now I'm gonna use a tsdb or memory-db to store the latest trade price and sequence, and client subscribe the current price from the db. And when the trading ends, move the tick level series data to postgres/mysql.

fasenderos commented 3 months ago

@loongmxbt v6.1.0-beta.0 now has a new property lob.marketPrice for getting the current market price.

loongmxbt commented 3 months ago

Thanks a lot! I'll try out the new version. 😄