1

SOVED: I thought Test2 was buying 3 AXX, but in fact it was selling 3 XLM. Don't forget to check the ordering and meaning of parameters!

I'm having trouble explaining what's going on with my bid and offers:

Issuer: GD57JZ42YKIEDLCFIZD2BW6LIYN7KIOEMFSIL37WZ5RS7DPLEW6DOOWG
Asset: AXX

Test1: GC5RQZPRI2SXMOL5JP2QTJXO72IAJLGMNU7TG5ADU6OMYDEJI3APJTZI
Balance: 444 AXX

Test2: GBPJWQBGYSIWHFDLDKNO4XMHUC7RUOX7GBORLG4ZKUFGKWMPW77OIHXA
Balance: 77 AXX

They each create an offer:

Test1: sell 20 AXX
Test2: buy 3 AXX

What I expected to happen is:

Test1 balance: 441 AAX (444 - 3)
Test2 balance: 80 AAX  (77 + 3)
Sell offer: 17 AXX     (20 - 3)

What actually happened was:

Test1 balance: 424 AAX (444 - 20)
Test2 balance: 97 AAX  (77 + 20)
Buy offer: 2.9 AAX     (3 - 0.1)

...

So my questions are:

  • Why did Test2 get 20 AAX when it only wanted 3?
  • Why is there a buy offer of 2.9 AAX?

I'm hoping this is just my misunderstanding of the documentation.

Edit: Here's the links to operations for Test1 and Test2:

https://www.stellar.org/laboratory/#explorer?resource=operations&endpoint=for_account&values=eyJhY2NvdW50X2lkIjoiR0M1UlFaUFJJMlNYTU9MNUpQMlFUSlhPNzJJQUpMR01OVTdURzVBRFU2T01ZREVKSTNBUEpUWkkifQ%3D%3D&network=test

https://www.stellar.org/laboratory/#explorer?resource=operations&endpoint=for_account&values=eyJhY2NvdW50X2lkIjoiR0JQSldRQkdZU0lXSEZETERLTk80WE1IVUM3UlVPWDdHQk9STEc0WktVRkdLV01QVzc3T0lIWEEifQ%3D%3D&network=test

And as you can see, the trades for Test2 indicate taking 20 and not 3?

https://www.stellar.org/laboratory/#explorer?resource=trades&endpoint=for_account&values=eyJhY2NvdW50X2lkIjoiR0M1UlFaUFJJMlNYTU9MNUpQMlFUSlhPNzJJQUpMR01OVTdURzVBRFU2T01ZREVKSTNBUEpUWkkifQ%3D%3D&network=test

https://www.stellar.org/laboratory/#explorer?resource=trades&endpoint=for_account&values=eyJhY2NvdW50X2lkIjoiR0JQSldRQkdZU0lXSEZETERLTk80WE1IVUM3UlVPWDdHQk9STEc0WktVRkdLV01QVzc3T0lIWEEifQ%3D%3D&network=test
2
  • Please provide links to transactions in horizon. Or at least update offers in the post with the price and asset bought/sold. Commented May 28, 2018 at 15:24
  • Thanks, updated the post. Sell was 1/250 and Buy was 250
    – Alfie John
    Commented May 28, 2018 at 23:34

1 Answer 1

2

From the MANAGE_OFFER docs:

Price {numerator, denominator} Price of 1 unit of selling in terms of buying. For example, if you wanted to sell 30 XLM and buy 5 BTC, the price would be {5,30}.

The price in the offer of Test1 account is:

{
  "n": 1,
  "d": 250
}

and it's selling AXX and buying XLM (native). To translate this: Test1 wants to sell 250 AXX for 1 XLM (in that ratio/price). It wants to sell 20 AXX so it will get (if the offer is fully consumed):

250 AXX - 1 XLM
 20 AXX - x XLM

 x = 20 * 1 / 250 = 0.08

The opposite offer's price (Test2 offer) is exactly an inverse (250/1) and selling 3 XLM for AXX:

250 AXX - 1 XLM
  x AXX - 3 XLM

 Test2 can by up to:
 x = 3 * 250 / 1 = 750

It means that the Test1's offer will be fully consumed because amount required to fully consume this offer is just 0.08 XLM and Test2 is selling 3 XLM. Also it can buy up to 750 AXX but Test1 is selling only 20 AXX. So after the trade happens we have:

Test 1 XLM balance += 0.08
Test 1 AXX balance -= 20
Test 1 offer: fully consumed

Test 2 XLM balance -= 0.08
Test 2 AXX balance += 20
Test 2 offer: still selling 2.92 XLM (it only sold 0.08 XLM)
1
  • That took me a while to grok. I just spotted that my text in the question does not match the operation that took place and your reasoning. I wanted Test2 to buy 3 AAX as in my description when in fact (as you correctly stated) Test2 sold 3 XLM! Thanks!!
    – Alfie John
    Commented May 29, 2018 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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