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

0 Members and 1 Guest are viewing this topic.

Offline FrankBlabu

Hi,

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]
...
{"base":{"amount":238,"asset_id":"1.3.121"},"quote":{"amount":41045,"asset_id":"1.3.0"}}
...

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.

Offline chigbolu

  • Full Member
  • ***
  • Posts: 143
    • View Profile
Re: Computing real world exchange rates from asset publish feed operations
« Reply #1 on: August 27, 2020, 06:04:28 am »
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

Re: Computing real world exchange rates from asset publish feed operations
« Reply #2 on: August 27, 2020, 04:32:53 pm »
Hi,

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: https://bts.ai/block/35847994.

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 FrankBlabu

Re: Computing real world exchange rates from asset publish feed operations
« Reply #3 on: August 27, 2020, 04:49:40 pm »
Ok, maybe I got a little close to the solution. The asset precision seems to play some role here, like describes in this example: https://dev.bitshares.works/en/master/bts_guide/tutorials/publish-feed.html

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 abit

  • Committee member
  • Hero Member
  • *
  • Posts: 4473
    • View Profile
    • Abit's Hive Blog
  • BitShares: abit
  • GitHub: abitmore
Re: Computing real world exchange rates from asset publish feed operations
« Reply #4 on: August 27, 2020, 09:57:07 pm »
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 »
BTS account: abit
BTS committee member: abit
BTS witness: in.abit