Friday, March 31, 2017

Friday Fun XLV - StockTicker


On my way back from Singapore last time I've created a little Demo that shows the new StockTileSkin of my TilesFX library.
In principle the StockTileSkin is very similar to the SparkLineTileSkin with the difference that it always shows the increase/decrease of the reference value in percentage and as a number.

So in the demo I get the current stock quote of Oracle and IBM once a minute from the NYSE. Because I'm not really into the broker and banking business I have no idea if that makes sense, so forgive me if this idea is totally stupid :)

To understand how this Skin works it needs some more explanation...
First of all you have to define the so called averaging period, this number represents the number of values that you would like to show in the line graph.

In this example I've decided to poll the stock quote every minute and set the averaging period to 120 which means the graph will show the last 2 hours when filled up
If no value is present the min and max values will be taken from Tile.getMinValue() and Tile.getMaxValue(). You also have to make sure that these values are in a usable range because values in Tile will be clamped to the min- and maxValue (I might change this for this specific skin in the future).

For a real good demo I should preload the line chart with the data of the previous day but I did not had the time to extend the demo to this.
Means if you start the demo and the NYSE is closed at that time you won't see any change in the value at all. But if you start it during the trading hours of the NYSE you might see some changes over time (but keep in mind that I only poll once a 1 minute).
If you did not set the reference value, the first value of the data list will be taken to calculate the increase of decrease of the current value. 
If you would like to stick your manual set reference value you might want to set autoReferenceValue property to false.
The reference value will be visualized using a dashed line color with the tresholdColor.

In addition to the StockTileSkin I thought it might be nice to make use of my DotMatrix control and create and add a scrolling ticker too.
To give you an idea what I'm talking about, here is a screenshot of the demo...

The service that I use to get the stock quotes can be found at and is nice for testing some things. The problem is that first of all the data is not available for all companies so it took me some time to figure out two quotes that are updated regularly which made me end up with Oracle and IBM :)

If you would like to add another company stock symbol you can simply add it to the list of symbols in the Main.class. For example let's add Microsoft to the list

public class Main extends Application {
    private static final List<String> SYMBOLS;
    static {
        SYMBOLS = new ArrayList<>();
        SYMBOLS.add("MSFT"); // Simply add it to the list

Be aware that I did not spend much time in layouting mulitple stock items...means I've tried it with 2 and 3 stock might look bad with 4 but you will figure out how to make it better ;)

I hope that the StockTileSkin is somehow useful and if you have suggestions on how to improve it...please let me know :)

If you are interested in the source code of this demo you can find it as always on github.

And at last here is a little video that shows the StockTicker Demo in action after it ran for some time.

That's it for today...cheers from Singapore and...keep coding... :)

No comments:

Post a Comment