Skip to content

SubscribeToOrderBook #423

Open
Open
@LimpidCrypto

Description

@LimpidCrypto

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions