You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How about a way to subscribe to an order book? The subscribe method only supports a way to subscribe to the transaction stream of an order book. I guess it would be possible to add a class similar to WebsocketClient (or just uses WebsocketClient as parent class) that simply takes an url, a taker_gets and a taker_pays, that you can enter using the with statement. The object would subscribe to the transaction stream of both sides of the order book and the ledger stream. On every message received from the txn stream the updated order book would be parsed and returned. On every message received from the ledger stream all offers whose Expiration match the ledger_index would get removed and the new order book gets returned.
# simplified examplewithSubscribeToOrderBook(...) assubscription:
fornew_order_bootinsubscription:
# do something with the new order book
Of course you could simply have a function called get_final_order_book that takes ask and bid offers and the transaction that affected that book. When doing so you could remove expired offers based on the transactions ledger_index but you would still have the risk of working with an old version of the order book.
Let's say you have an up to date version of an order book in Ledger 73562766 (which is the last validated) and in that order book is an offer with an Expiration set to 73562767 but the next transaction affecting that book is in 73562770 you would have deprecated version of the order book from 73562767 - 73562769.
IMO it would be a very convenient way to make sure one always has the current state of an order book without having to call book_offers for both sides every time a new ledger gets validated.
The text was updated successfully, but these errors were encountered:
It'd be good to create a folder called snippets in the repo and start including things like this there :) (We have something like that in xrpl.js that I'd like to add more to over time)
How about a way to subscribe to an order book? The
subscribe
method only supports a way to subscribe to the transaction stream of an order book. I guess it would be possible to add a class similar toWebsocketClient
(or just usesWebsocketClient
as parent class) that simply takes anurl
, ataker_gets
and ataker_pays
, that you can enter using thewith
statement. The object would subscribe to the transaction stream of both sides of the order book and the ledger stream. On every message received from the txn stream the updated order book would be parsed and returned. On every message received from the ledger stream all offers whoseExpiration
match theledger_index
would get removed and the new order book gets returned.Of course you could simply have a function called
get_final_order_book
that takes ask and bid offers and the transaction that affected that book. When doing so you could remove expired offers based on the transactionsledger_index
but you would still have the risk of working with an old version of the order book.Let's say you have an up to date version of an order book in Ledger 73562766 (which is the last validated) and in that order book is an offer with an
Expiration
set to 73562767 but the next transaction affecting that book is in 73562770 you would have deprecated version of the order book from 73562767 - 73562769.IMO it would be a very convenient way to make sure one always has the current state of an order book without having to call
book_offers
for both sides every time a new ledger gets validated.The text was updated successfully, but these errors were encountered: