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

Odd choice of returned units from orderbookCallBuilder.call() in stellar-sdk #612

Open
ire-and-curses opened this issue Aug 23, 2018 · 5 comments
Labels
horizon horizon-api Issues or features related to the Horizon API

Comments

@ire-and-curses
Copy link
Member

If I do

const buying = new Asset(code, issuer);
const selling = Asset.native();
const orderbookCallBuilder = server.orderbook(buying, selling);
const orders = await orderbookCallBuilder.limit(2).call();

Then I get something like this:

{ bids:
   [ { price_r: [Object], price: '0.0460110', amount: '307.6952943' },
     { price_r: [Object], price: '0.0460010', amount: '298.2101243' } ],
  asks:
   [ { price_r: [Object], price: '0.0564900', amount: '2321.8474106' },
     { price_r: [Object], price: '0.0565000', amount: '1824.6445497' } ],
  base:
   { asset_type: 'credit_alphanum4',
     asset_code: 'ABDT',
     asset_issuer: 'GDZURZR6RZKIQVOWZFWPVAUBMLLBQGXP2K5E5G7PEOV75IYPDFA36WK4' },
  counter: { asset_type: 'native' } }

I'd like to use XLM units for everything. However, it looks like
price is in XLM for bids
amount is amount of XLM for bids
price is in XLM for asks
amount is amount of ABDT for asks?!

I can work around this with something like

export function fixHorizonBaseAmount(asks: any) {
  asks = asks.map((a: any) => ({
    ...a,
    amount: Big(a.amount)
      .mul(a.price)
      .toString(),
  }));

  return asks;
}

but the original returns are surprising, and not documented, AFAIK.

@ire-and-curses ire-and-curses added the horizon-api Issues or features related to the Horizon API label Jul 19, 2019
@2opremio
Copy link
Contributor

@ire-and-curses should we move this to the javascript repo?

@leighmcculloch
Copy link
Member

leighmcculloch commented Jan 13, 2021

I think this issue is to do with the data returned from Horizon and not the SDK. As noted in the linked issue above #1193 (comment) this is also something users of the Go SDK has to deal with.

@ire-and-curses
Copy link
Member Author

Yeah I phrased the repro in terms of the JS SDK, but this is actually a problem with the representation in Horizon.

@lmorgan824
Copy link

I see this is still an open issue as of today. When working with the testnet orderbook, I am still seeing the bids amount and the asks amount in different units. If we speak of amount as how many times one could execute 1 unit, (i.e. size in equity world) and depth as the total available to be executed at that price, then currently, the bids amount is representing "depth" and asks amount is amount. IMHO the bids amount needs to be fixed to not be depth but amount that could be executed at the price. Based on what I'm seeing on StellarTerm/testnet, they've fixed this internally which leads me to believe that this would be a "breaking" change if made as people have hacked around it already. To fix or not to fix....

@lmorgan824
Copy link

My JS hack looks like this currently. (I know my JS looks like C, I'm old school... ;) )
const ob = await sdk.getOrderBook(a1,a2);
for (i = 0; i < ob.bids.length; i++) {
ob.bids[i].amount = (parseFloat(ob.bids[i].amount) / parseFloat(ob.bids[i].price)).toFixed(7);
}

ob now looks like an order book most would expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
horizon horizon-api Issues or features related to the Horizon API
Projects
None yet
Development

No branches or pull requests

5 participants