ripple-unmaintained / ripple-lib-java

Java version of ripple-lib (work in progress)
ISC License
126 stars 109 forks source link

CheckPrice (Subsribe to order book) doesn't work ? #79

Open inmyth opened 7 years ago

inmyth commented 7 years ago

To see this problem simply run CheckPrice with already embedded Bitstamp address. The result is empty and it looks like Response.OnResponse callback is never called. When tested with Ripple's websocket tool, you can see that Bitstamp is pretty busy. At the very least BTC/USD and USD/XRP should always have activities.

inmyth commented 7 years ago

So it's not that it doesn't return anything but if it returns too many items, the callback won't be called. One quiet trade to test this on is Bitstamp XRP/JPY (will definitely change) with

Request request =c.subscribeBookOffers(Issue.XRP, Issue.fromString("JPY/rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"));
request.on(Request.OnSuccess.class, new Request.OnSuccess() {

    @Override
    public void called(Response response) {
                if (response.succeeded) {
                    JSONArray offersJSON = response.result.optJSONArray("offers");
                    STArray offers = STArray.translate.fromJSONArray(offersJSON);
                    //etc
        }             
        });
request.request();

It's also unclear if subscribe to book offer like this will listen (subscribe) to a stream or just be one-shot request which immediately returns.

sublimator commented 7 years ago

I'm not sure what's going on there, as I don't use ripple(-lib-java)? very much these days. My guess is that subscribing to the orders books, and getting the subscriptions works fine, due to the implementation happening to always (last I looked) write to all connected subscribers on ledger close. The requests on the other hand, have to go into the Job Queue and with the network currently having some troubles (I saw a rippled issue) there may not ever be a response ...

Actually, I tried a simple account_tx request the other day, and I never got a response and the logging showed warnings of requests timing out.

Try the the "book_offers" command via the WebSocket tool and see if you can get a timely response.

sublimator commented 7 years ago

https://ripple.com/build/rippled-apis/#book-offers

sublimator commented 7 years ago

It's also unclear if subscribe to book offer like this will listen (subscribe) to a stream or just be one-shot request which immediately returns.

It only makes the request. You'll have to do a separate request and use client.on(Client.OnMessage.class, ... ) and check for the correct message type etc and handle accordingly.