2

Price: How many units of buying it takes to get 1 unit of selling. A number representing the decimal form of price_r.

According to the Stellar guides, the price of an offer should be the amount of buying units that can buy one selling unit, so if selling one XLM for 0.45 USD then the price is 0.45 but if selling one USD for XLM then the price would be 2.22 since you need 2.22 XLMs to buy one USD so the question is, should I do the conversion on the client so both offers reflect a similar price on the blockchain? or let the server do the conversion and get dissimilar prices on bids and asks?

Right now if I buy one USD with XLM it stores 0.45 but if I sell one USD for XLM at the same 0.45 it stores 2.22 so when I show the prices on the exchange they're different. So the question again is, should I convert the price on the client when showing the prices or should I convert before saving the operation on the server?

  • when you refer to client and server are you referring to your own client and server? – nikhils May 3 '18 at 20:30
1

Both would be fine.

Caution: keep your price with at least 10 decimal places, because the system treats the bidding/asking price as fractions. Each price is stored as 2 integer variables: numerator and denominator.

An offer is taken only if: (bidding price * asking price) <= 1.0000000000

.

If my memory is correct, both the numerator and denominator holds 10 significant figures. So it is safer to keep your value with at least 10 decimal places (if it is not an exact integer).

| improve this answer | |
1

The prices submitted to the blockchain must be in the format specified by the Stellar docs to actually reflect your intention.

As for representing it on your client (or storing it on your server), you can use whatever format you want as long as you can convert it back to Stellar's representation. It may be easier to use a format that shares the same base currency when representing buy or sell offers since those prices would then share the same denominator and may be easier to reason about.


should I do the conversion on the client so both offers reflect a similar price on the blockchain? or let the server do the conversion and get dissimilar prices on bids and asks?

It should not matter whether you perform your conversions on the client or the server. You should never get dissimilar prices on bids and asks, the price_r may differ but the logical price is still the same.


should I convert the price on the client when showing the prices or should I convert before saving the operation on the server?

As suggested above, if your client converts the prices to be based in one currency then it would be easier for the user when looking at the prices. The server can do the conversion to Stellar's representation before sending it off to the network so the user never sees that.

You could even have the client read/write directly from/to the Stellar Network via the Javascript SDK to avoid duplicating data on your server since all the offer data is already stored on the blockchain and is quite easy to work with. Here is a link to the API to fetch active offers and the API to fetch all offers (you will need to filter this based on type, requiring it to be manage_offer).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.