Coding for NXT Crypto Platform #4: Historical Asset Data

Coding for NXT Crypto Platform #4: Historical Asset Data

In this article I want to cover how to receive historical trades.
The API call we are using here is “getTrades”.’

Historical Trades

Historical trades can either be from any Account or from any Assets, we are continuing as we did before and get latest trades from the Asset SuperNET.

Again we will be using the parameters firstIndex and lastIndex to retreive only the last 10 entries. If you want to get more trades, just change lastIndex to a higher number or erase both firstIndex and lastIndex completely.

If you erase firstIndex and lastIndex it is possible that you get a limited number of entries — this can be setup in your Nxt configuration file. Have a look at the property: nxt.maxAPIRecords=100 and configure it to your needs (just when you are working without an admin password).

For the API request, as stated above, we limited the response by setting firstIndex and lastIndex to 10 entries. Furthermore, the includeAssetInfo set as true will show the decimal for the Asset and the Name of the Asset. This will make the call a bit slower but especially when we are looking at more than one Asset a very helpful addition.

Instead of including includeAssetInfo we could make a getAsset call to receive those parameters (when just looking at one Asset this might be recommended). But when you are looking at an Account last trades instead of an Asset, this can save a lot of work and time.

The most important calculations to mention for this script are the Nxt timestamp, quantity and price. They are calculated as already explained above.

Nxt Timestamp

Nxt has its own timestamp. Nxt was started November on Nov 24, 2013 12:00 am. In Nxt this would be timestamp 0. In Javascript this is 1385294400 (as Javascript started January 1, 1970, 00:00:00), but JavaScript uses Miliseconds, therefore we have to multiply 1000 to get there. As a result we need to add the given timestamp of Nxt to 1385294400 and add the miliseconds to retreive the timestamp in JavaScript.

Analysing the historical data will get you a lot of information about the frequency of trading and how many accounts have been trading an Asset. The more accounts are involved in trading, the better an Asset is spread among traders, which is usually a good sign. Of course, you have to be aware that you do not know the origin of Accounts. It is possible that one person creates multiple accounts and trades from all of these accounts. The Asset appears to be traded by more parties, which seems beneficial for the Asset owner, on the other hand people might create several accounts to track different types of holdings. In a lot of cases it makes sense for a user to have more than just one Account.

The above script will show you a table like this one:

Account Information

As you already know, the Blockchain is fully transparent; you can see any transaction in the network and all the holdings of one account. It still enables you to write encrypted messages, which cannot be read by anybody but the person who holds the passphrase of either the sender or the recipient.
The next step for you is to find out how to create a nice interface to view Accounts. All the necessary steps to get there are explained here.

The API call needed to get Account information is getAccount. You could also use getAccountAssets to monitor Asset holdings but getAccount will show you all the holdings of one account.

A hint: as in the getTrades API, you can decide to include furter informations with includeLessors, includeAssets, includeCurrencies or includeEffectiveBalance.

Enjoy developing with Nxt! In the next article, we will explore creating transactions and more details about the Blockchain. If you have any questions, feel free to contact me via email or my Nxt Forum account.

Quote from: mael on Today at 07:53:25 pmother thing: the adress who got my NXT (NXT-XVBJ-B8VA-Q7MB-HGZXQ) has received a lot of transactions the same day, same hour. What's this ?This appears to be someone run...

yes, I will do that for Ignis snapshot.I just trusted bter when they announced they will take the Ardor Snapshot.Look, this is what you can find looking on archive.org a version of bter main site on September, 18th, 2016[url=https://web.archive.org/...