elective-stereophonic
elective-stereophonic
How to read and adjust asset-price from Nxt http API singapore
Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest Stable Nxt Client: Nxt 1.12.2

Author Topic: How to read and adjust asset-price from Nxt http API  (Read 1747 times)

dee22

  • Newbie
  • *
  • Karma: +5/-0
  • Offline Offline
  • Posts: 11
    • View Profile
    • NXTinfo
How to read and adjust asset-price from Nxt http API
« on: August 18, 2015, 03:59:23 pm »

Hello
I try to get prices from the AssetExchange using the Nxt http API:
Example-Querry:
http:     //localhost:7876/nxt?requestType=getTrades&asset=172381791830552501&firstIndex=0&lastIndex=0

This returns the last Trade on this Asset. There i take the price.

It works for most assets, but some assets (like this in the example querry) returns 5.2 NXT (5'200'000 NQT).
But the real price of this asset is 0.52 NXT.

Most assets return the correct price but this asset f.ex. returns the price 10x higher than it should be.

Does anyone know why the API returns wrong values on some assets? Or where i can get the real actual price?

br
dee22

19.08.2015 04:38 pm Edit:
Edited subject of the thread.
« Last Edit: August 19, 2015, 04:37:47 pm by dee22 »
Logged
nxtinfo.org NXT Faucet - explore Assets - calculate Dividend payments

LibertyNow

  • Sr. Member
  • ****
  • Karma: +78/-33
  • Offline Offline
  • Posts: 361
    • View Profile
    • Liquid Tech
Re: BUG in Nxt http API
« Reply #1 on: August 18, 2015, 04:02:29 pm »

Are you adjusting for the asset decimal places?
Logged
LQD NXT:17750387231635486778, EDGE NXT: 10713749908351947210
LQD: http://www.liquidtech.info, EDGE: https://www.bustabit.com/user/EDGE_NXTAE

dee22

  • Newbie
  • *
  • Karma: +5/-0
  • Offline Offline
  • Posts: 11
    • View Profile
    • NXTinfo
Re: BUG in Nxt http API
« Reply #2 on: August 19, 2015, 08:48:49 am »

I'm not sure if i do it correctly.
I divide the price just by 1 Million because the price is in QNT.
5'200'000 QNT / 1'000'000 = 5.2 NXT
that should be correct, isn't it?
Or do i have to divide QNT by 100 Million? (But this way the value is 10 times too less).
The problem is that the asset nr. 172381791830552501 is just 520'000 NQT worth.
But the "raw API return data" (without any calculations on it) show 5'200'000 NQT.

Other assets return the price as i expect it..
« Last Edit: August 19, 2015, 08:54:05 am by dee22 »
Logged
nxtinfo.org NXT Faucet - explore Assets - calculate Dividend payments

ScripterRon

  • Hero Member
  • *****
  • Karma: +75/-2
  • Offline Offline
  • Posts: 523
    • View Profile
Re: BUG in Nxt http API
« Reply #3 on: August 19, 2015, 03:57:15 pm »

The asset has 1 decimal place.  That means the quantity has an implied decimal point before the last digit and the price has an implied decimal point before the last 7 digits (price decimals is 8-quantity decimals)

For this trade:
Code: [Select]
{
    "trades": [
        {
            "seller": "13982891731110488544",
            "quantityQNT": "2500",
            "bidOrder": "13466779942922388210",
            "sellerRS": "NXT-EUH2-Y9LT-J54V-EPB56",
            "buyer": "15039502742685648975",
            "priceNQT": "5300000",
            "askOrder": "5890834910797382197",
            "buyerRS": "NXT-P44H-3ZA6-TQBD-FESF3",
            "decimals": 1,
            "name": "clubnxt",
            "block": "4289353034813707846",
            "asset": "172381791830552501",
            "askOrderHeight": 488098,
            "bidOrderHeight": 500528,
            "tradeType": "buy",
            "timestamp": 54635803,
            "height": 500528
        }
    ],
    "requestProcessingTime": 4
}
The quantity is 250.0 (quantityQNT=2500) and the price is 0.53NXT (priceNQT=5300000)
Logged

dee22

  • Newbie
  • *
  • Karma: +5/-0
  • Offline Offline
  • Posts: 11
    • View Profile
    • NXTinfo
Re: BUG in Nxt http API
« Reply #4 on: August 19, 2015, 04:28:24 pm »

Thank you verry much ScripterRon for your great example.
Now i understand how it works. And what LibertyNow meant.
Works perfectly.
Logged
nxtinfo.org NXT Faucet - explore Assets - calculate Dividend payments
 

elective-stereophonic
elective-stereophonic
assembly
assembly