Jump to content

  • Advertisement

Accessing the order book


Recommended Posts

Hello,

I'd like to access the order book on the ledger for XRP/USD.bitstamp in as close to real time as possible. The server here https://xrpcharts.ripple.com/#/markets/XRP/USD:rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B?interval=15m&range=3d&type=line provides a view of the order book for a given currency pair.

I can't find any REST API call that delivers this info on the ripple API pages and I wonder if there is a way of running a rippled server with validation disabled, but monitoring the state of transactions (or querying the order book via some call) to produce something similar. I'm only interested in doing this from inside a c++ application, so I don't want any nodejs or other script language based solutions, but I'm happy to query things like a REST API or get data from a websocket from inside the c++ code if I need to. I've compiled rippled locally and am happy to link to parts of it if necessary from my program and am not against ripping just the bits I need out, though I suspect that's not necessary (I would like to avoid having too many rippled threads running that are not under my direct control - I already have several beast/asio threads querying data from other websockets on the go).

Can anyone point me in the right direction as to how the best way to get the order book would be. Ideally, I'd like a std::vector of bids and another of asks for xrp/usd.bitstamp etc etc (for now, I'd only really need those two, but might want other IOUs in the future).

Thanks.

Link to post
Share on other sites
38 minutes ago, jargoman said:

You could use the websocket api, the json-rest api or the rippled command line options
https://xrpl.org/get-started-with-the-rippled-api.html

Aha. The page I needed is here https://xrpl.org/book_offers.html.  That's a great help - not sure how I didn't find that previously - I will use the websocket interface and should be able to get what I need. Many thanks indeed.

Link to post
Share on other sites
38 minutes ago, jbjnr said:

Aha. The page I needed is here https://xrpl.org/book_offers.html.  That's a great help - not sure how I didn't find that previously - I will use the websocket interface and should be able to get what I need. Many thanks indeed.

It's better to find a c++ library than doing it all yourself. You need something to sign the transactions 

this project looks interesting. They've copied the rippled source code into the project to create a library.

https://github.com/ripple/ripple-libpp

Link to post
Share on other sites

I'm curious about the websocket interface - when I request the order book, I get a list of taker offers as expected, but as its a websocket, I expected that I could subscribe to the order_book and every ledger close I would automatically receive a new list (or subset thereof) - rather than having to ping every N seconds to get an update. Am I misunderstanding how the system works - or is there a way to simply listen for updates without sending repeated requests? (which is why I initially assumed that I might need to run some subset of the rippled server to have constant access)

Link to post
Share on other sites

Thanks everyone. I have the info I need now. Building the order book by hand isn't an issue as long as I don't miss any offers etc. I'll play around and see if doing a full update once every now and then is necessary of if things stay in sync long term.

Link to post
Share on other sites
17 minutes ago, jbjnr said:

Thanks everyone. I have the info I need now. Building the order book by hand isn't an issue as long as I don't miss any offers etc. I'll play around and see if doing a full update once every now and then is necessary of if things stay in sync long term.

If you have everything local it should stay in sync 100%.
If you need to build autobridged books it's a bit more complex, but nothing impossible, just be careful. There should be some very old topics here on that.

Link to post
Share on other sites
  • 2 weeks later...
On 1/4/2021 at 1:36 AM, jargoman said:

It's better to find a c++ library than doing it all yourself. You need something to sign the transactions 

this project looks interesting. They've copied the rippled source code into the project to create a library.

https://github.com/ripple/ripple-libpp

I just made a small PR to update the demo as it seems very useful - and I will definitely make use of the signing examples in my application. Thanks again.

https://github.com/ripple/ripple-libpp/pull/22

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.