NXTER.ORG

Coding for NXT Crypto Platform #4: Historical Asset Data

Coding for NXT Crypto Platform #4: Historical Asset Data

In the last topic I showed you how to retrieve basic data about Assets from the Nxt Asset Exchange.

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).

Now, let’s jump back to the code.








  

Trade History

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.

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:

programming-nxt-4-1

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.

Read the next article in this series > …

More resources, example code and dev blogs: https://nxter.org/devcom

More in this series:
Coding for NXT Crypto Platform #1: Configuration
Coding for NXT Crypto Platform #2: First Steps
Coding for NXT Crypto Platform #3: Output from the Asset Exchange

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x