Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SubscribeToOrderBook #423

Open
LimpidCrypto opened this issue Aug 8, 2022 · 2 comments
Open

SubscribeToOrderBook #423

LimpidCrypto opened this issue Aug 8, 2022 · 2 comments
Labels

Comments

@LimpidCrypto
Copy link
Contributor

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 example
with SubscribeToOrderBook(...) as subscription:
  for new_order_boot in subscription:
    # 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.

@mvadari
Copy link
Collaborator

mvadari commented Aug 15, 2022

IMO that shouldn't be a method in the library - it's a little too specialized. But it could be a snippet in the repo.

@JST5000
Copy link
Contributor

JST5000 commented Aug 23, 2022

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)

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

No branches or pull requests

4 participants