Author Topic: Computing real world exchange rates from asset publish feed operations  (Read 3880 times)

0 Members and 1 Guest are viewing this topic.

Online abit

  • Committee member
  • Hero Member
  • *
  • Posts: 4664
    • View Profile
    • Abit's Hive Blog
  • BitShares: abit
  • GitHub: abitmore
For example, EUR's precision is 4, to specify one Euro, set the amount as 1 * 10^4 aka 10,000.
BTC's precision is 8, so "amount = 100,000,000" means one Bitcoin.

Precision is only used in UI.
The core itself doesn't really care about precision, all computations in core are based on the smallest unit aka Satoshi.
« Last Edit: August 27, 2020, 09:59:56 pm by abit »
BitShares committee member: abit
BitShares witness: in.abit

Offline FrankBlabu

Ok, maybe I got a little close to the solution. The asset precision seems to play some role here, like describes in this example:

So the price for the asset publish feed operation is computed via

Code: [Select]
price = price * 10 ** asset["precision"] / 10 ** base["precision"]

which would match the factor 10 as the precision field for BTS is 5 and for EUR it's 4. But I cannot find information about how the asset precision is handled in general. Neither in the bitshares-core source code nor in the documentation. Is there a hint to learn more about that particular topic ? What role does the asset precision play here ?

Best regards.

Offline FrankBlabu


no, I think we are talking about USD. At least it's a feed operation, not a trade operation. The issue gets weirder if I inspect a random block at some block explorer service, like here:

The website reports 19.97674 BTS/USD from the asset publish feed operation in this block, which is about 0.0500582 USD/BTS. Now when I look at the raw block JSON on the very same site, the published values are 43 USD / 8590 BTS, which is 0.00500582 USD/BTS. Again factor 10 between the rate computed from the raw block content and the value the website computes from that.

I'm afraid I'm missing some basic asset feature here.

Best regards.

Offline chigbolu

  • Sr. Member
  • ****
  • Posts: 215
    • View Profile
Depends on the asset in question, for example BITUSd is still depegged at 0.0345 and does not follow normal price trend in USD, there are also some bridge USD that are now defunct and show very unusual prices eg openlegder, cryptobridge, and sparkdex, so it depends on the asset in question.

Offline FrankBlabu


I'm trying to understand the internals of BitShares. For that, I had a deeper look into the operations being passed around and I do not properly understand the "asset publish feed" operation.

If I got that right, the operations settlement/core exchange rate prices are representations of "in the real world, I get x pieces of asset A for y pieces of asset B". So for A being 'USD' and B being 'BTS', it should be possible to directly compute the real world BTS exchange rate in USD from that.

Now, after some debugging, I get values like this for, say, the 2019/2/26:

Code: [Select]

So for 238 USD, I will get 41045 BTS which leads to a price of about 0.0052 USD/BTS.
But if I look up historical BTS pricing, the exchange rate for that particular day is about 0.046 USD/BTS, in general about 10 times larger.

So where is my error of thought here ? Is there some factor involved which is asset specific ?

Thank you very much in advance.