Steem API / SteemJ Tutorial #2 - The market_history_api

in #steemdev7 years ago (edited)

The second post of the SteemJ Tutorial series will explain the market_history_api functionalities of the Steem-API and explain how to use them with SteemJ.


SteemTutorialIcon
Source of used Icons: Iconfinder.com

Steem API / SteemJ Tutorial #2 - The market_history_api

Hello Steemians!

for those of you who already use SteemJ, it is not a big surprise that there is quite a huge lack of documentation. At the beginning I thought that this is not a big deal if I keep using the original fields and methods as provided by Steem itself, but it also turned out that the original code has not that much comments and the Steem Dev Documentation is also not providing detailed information.

To make your life easier, to solve the lack of SteemJs documentation and to motivate myself for writing all this stuff, I've decided to create a Steem Tutorial series where I explain a specific part of the Steem API and show how to use/call those things with SteemJ.

The previous part covered the follow_api - So lets continue with another API, the market_history_api.

Market History API

The market_history_api covers all api calls related to the internal Steem market.

Market-History-API TOC

getTicker

Use this method to receive statistic values of the internal SBD:STEEM market for the last 24 hours.

As this method does not require parameters, the call is quite simply.

MarketTicker marketTicker = steemJ.getTicker();

The call above returns a MarketTicker object providing information about the:

  • Latest price
  • Highest price
  • Lowest price
  • Steem volume,
  • SBD volume,
  • Change in percent

For the last 24 hours.

Back to Market-History-API TOC | Back to TOC

getVolume

Use this method to get the SBD and Steem volume that has been traded in the past 24 hours at the internal SBD:STEEM market

MarketVolume marketVolume = steemJ.getVolume();

As shown above the method has no parameter too and also the returned volumes are equal to the one returned by the getTicker method. The only difference is that the getTicker method returns price information in addition.

Back to Market-History-API TOC | Back to TOC

getOrderBook

Use this method to receive the current order book of the internal SBD:STEEM market.

The method has one parameter (the limit) which is used to define the maximum number of asks and bids that should be returned. Please notice that the maximum number of asks/bids is 500 - If you define a limit greater this value an Exception will be thrown.

OrderBook orderBook = steemJ.getOrderBook((short) 50);

The call above will return the next 50 active asks and bids.

Back to Market-History-API TOC | Back to TOC

getTradeHistory

Use this method to get the trade history of the internal SBD:STEEM market between the defined start and end time.

The method requires three parameters in total: The start date, the end date and the maximum number of trades to be returned. Please notice that the maximum number of entries is limitted to 1000 entries. If more values requested an exception will be thrown.

List<MarketTrade> marketTrades = steemJ.getTradeHistory(new TimePointSec("2016-08-08T12:24:17"), new TimePointSec(System.currentTimeMillis()), (short) 10);

The call above will return the 10 latest trades fulfilled between the 2016-08-08T12:24:17 and now.

Back to Market-History-API TOC | Back to TOC

getRecentTrades

Use this method to request the most recent trades for the internal SBD:STEEM market. The number of results is limited by the limit parameter. Please notice that the maximum number of recent trades is 500 - If a limit greater than this value is used, an Exception will be thrown.

List<MarketTrade> marketTrades = steemJ.getRecentTrades((short) 10);

The call above will return the latest '10' fulfilled transactions.

Back to Market-History-API TOC | Back to TOC

getMarketHistory

Use this method to receive the market history for the internal SBD:STEEM market.

List<Bucket> marketHistory = MarketHistoryApi.getMarketHistory(3600, new TimePointSec("2017-08-08T12:24:17"), new TimePointSec(System.currentTimeMillis()));

The method above will request the market history between the 2017-08-08T12:24:17 and now while the result is splitted into buckets. Each bucket represents a timespan of 3600.

Please notice that the node needs to support the requested bucket timespan. It is possible to request the available timespans using the getMarketHistoryBuckets method.

Each bucket entry provides detailed information about the market situation for the timespan tracked by this bucket. A bucket consists of the:

  • Bucket size,
  • Bucket id,
  • SBD close value,
  • STEEM close value,
  • SBD open value,
  • STEEM open value,
  • SBD volume,
  • STEEM volume,
  • SBD high,
  • STEEM high,
  • SBD low,
  • STEEM low

While those values are associated with the timespan tracked by the bucket.

Back to Market-History-API TOC | Back to TOC

getMarketHistoryBuckets

Use this method to receive the bucket seconds being tracked by the node.

List<Integer> marketHistoryBuckets = steemJ.getMarketHistoryBuckets();

The result of this method is a list of available timespans tracked by the node. An example response could be {15,60,300,3600,86400} which means the node tracks buckets for a 15, 60, 300, 3600 and 86400 second timespan.

Back to Market-History-API TOC | Back to TOC


General information

What is SteemJ?

SteemJ is a project that allows you to communicate with a Steem node using Java. So far, the project supports most of the API calls and is also able to broadcast most of the common operation types. Further information can be found on GitHub.

https://github.com/marvin-we/steem-java-api-wrapper

How to add it to your project?

SteemJ binaries are pushed into the maven central repository and can be integrated with a bunch of build management tools like Maven. The Wiki provides a lot of examples for the most common build tools. If you do not use a build management tool you can download the binaries as described here.

Contribute

The project became quite big and there is still a lot to do. If you want to support the project simply clone the git repository and submit a pull request. I would really appreciate it =).

git clone https://github.com/marvin-we/steem-java-api-wrapper.git

Get in touch!

Most of my projects are pretty time consuming and I always try to provide some useful stuff to the community. What keeps me going for that is your feedback and your support. For that reason I would love to get some Feedback from you <3. Just contact me here on Steemit or ping me on GitHub.


If you want to stay up to date or just like the stuff I am doing it would be great if you could press the button below =).

Follow meFollow @dez1337
follow mefollow dez1337


Thanks for reading and best regards,
@dez1337

Sort:  

I've been fiddling with SteemJ for the past week. Can't seem to get it working well with Android Studio. Compilation of Mixion went from 1 minute to 10+ minutes with a 'dexfilewriter' error..

Hay @edgar-trem ,

there is a discussion about SteemJ + Android at GitHub - I would really appritiate if you could add the problems you were facing into that thread. My target is to fix all those issues in Android Studio for the next version.

Thanks and best regards!

Coin Marketplace

STEEM 0.26
TRX 0.11
JST 0.032
BTC 63617.36
ETH 3070.79
USDT 1.00
SBD 3.82