XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.2k stars 511 forks source link

v0.18.0 returns different value in orderbook as in v0.17.9 #835

Closed jnr101 closed 6 years ago

jnr101 commented 6 years ago

Hello,

I am testing v0.18.0, but I find a difference on some of the returned orderbooks. The script I am running:

const {RippleAPI} = require('ripple-lib');

const api = new RippleAPI({
  server: 'wss://s1.ripple.com' // Public rippled server hosted by Ripple, Inc.
});
api.on('error', (errorCode, errorMessage) => {
  console.log(errorCode + ': ' + errorMessage);
});

var address = "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"

var orderbook = {
  "counter": { currency: "USD", "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" },
  "base": { "currency": "USD", "counterparty": "rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq" }
}

var options = {
    "limit": 5
}

api.connect().then(() => {
  return api.getOrderbook(address, orderbook, options)
}).then(openorders => {
  console.log("ASK:", JSON.stringify(1/openorders.asks[0].properties.makerExchangeRate, null, 2))
  console.log("BID:", JSON.stringify(1/openorders.bids[0].properties.makerExchangeRate, null, 2))
  return api.disconnect();
}).catch(console.error);

Running under v0.17.9 returns:

>node getOrderbook.js
ASK: 1.0050251256281406
BID: 0.971722864639005

Running under v0.18.0 returns:

>node getOrderbook.js
ASK: 1.0050251256281406
BID: 1.0027103097025

The value for v0.17.9 is consistent with current values, v0.18.0 seems to be wrong. I am running node v9.2.0

n.b. Could this be autobridge values? Are they calculated correct? They don't seem to match with e.g. xrpcharts autobridge orders

intelliot commented 6 years ago

Hello @jnr101 ,

This looks like a bug to me. I found the change that causes this discrepancy and fixed it in https://github.com/ripple/ripple-lib/pull/836. I would appreciate if you'd like to review/test the fix.

Thanks for catching this!

jnr101 commented 6 years ago

Hey intelliot,

I would like to, but I don't know how to build the ripple-lib. After "yarn install", what should I do next to get ripple-lib? edit. never mind, I found it (./dist/npm/api.js)

jnr101 commented 6 years ago

Intelliot,

I did some tests with my software and values are matching now with previous values (from 0.17.9), so looks like it has been fixed :-)

intelliot commented 6 years ago

Great!

For future reference, you can build for Node.js with yarn compile and the resulting JS files will be written in ./dist/npm/. I'll add this info to the README as well.

jnr101 commented 6 years ago

Did you also update the master?

intelliot commented 6 years ago

Not yet - I'll do that now.

Edit: The master branch has been updated.