Coding for NXT Crypto Platform #4: Historical Asset Data
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).
Now, let’s jump back to the code.
Date Type Quantity Price Total Buyer Seller
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.
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:
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.
More resources, example code and dev blogs: https://nxter.org/devcom