2011-07-17 10:57 PM: Added AsJson API operation as requested from a reader.
I know that I have been writing quite a bit of “general” posts, but I think that I should put up and early disclaimer that the latter part of this one will be a bit on the technical side, however, I think that that can be of interest to non-technical folks out there.
For those of you following me on twitter, for the last week or so I’ve have been playing around with some code that would bring a bit more “exposure” to the trading data coming out from the Trinidad and Tobago Stock Exchange. So, let me build this story up properly…
For a long time, particularly since the invention of computer and telecommunication networks, software engineers have been trying to make it easier for different computer programs built using different technology stacks, running on different hardware, to share information. There have been numerous attempts in this area with quite a bit of success and many continuing challenges. For those of you out there that are reading this and aren’t software engineers, the industry has gone a really long way to solving this problem, and one of the most significant components of getting us there was … you guessed it … the web.
The “web” (this is pretty loaded term, so I had to throw up the air-bunnies ) has vaulted the need to share information to a whole new level, and not just information between people but information between computer programs. It’s so pervasive today that most of us don’t even know it or those of us that do generally don’t think about it. You don’t think about the fact that when you log into Windows Live Messenger and see images or even chat with your friends on Facebook that a bunch of completely different computer systems are communicating with each other, same goes for internet back games, online PC games, online Console game, and the list goes on…
Financial systems are also a key area that can benefit from data exchange between computers and ultimately between people. I’ve been working on a project for a couple of years that needed up-to-date information from the Trinidad and Tobago Stock Exchange (TTSE) on a daily basis. Luckily the TTSE now has a website where anyone can get information about the day’s changes after the trading has closed. That said, there are a couple of ways that this problem can be addressed from on my end:
- Have a human enter the data after visiting the TTSE website
- Get the required information “programmatically” from TTSE system
With option one, there is the possibility that we can inject human errors, forget to enter the information, not to mention the fact that we actually need a human “resource” to do this every day … so there is an obvious bias to being able to directly interface with the stock exchange in some way. There’s just one small problem here – the TTSE has deliberately decided to actively support programmatic information sharing … which they currently don’t do.
What I have been working on (currently without their direct support) is a way to provide this programmatic interface so that other computer applications can make use of their information without the need for human intervention.
I’ve built a couple of “web services” for experimental reasons that provide several methods of accessing data from the TTSE. The manner in which I implemented them was the initial reason I started this post, but I think I’ll deal with that as well as explaining to the non-techie folk what Web Services are.
Couple of weeks ago I built a simple proof-of-concept (POC) bit that allowed you to get an RSS feed of the information on the stock exchange. This old POC can still be found here:
This weekend, I finally got some time to completely nerd-out and with a couple of late night coding sprints, I’ve completely re-written the app to do a whole lot more, and to do it better:
The new base URL is: http://cordelllawrence.com/stockmarketservices/ – (This currently just bounces you back to this page since I haven’t yet created a project write up + documentation etc. … but read on!)
The API’s are RESTful (I’ll explain in a later post on web services), which means that using the API’s is as simple as making a web request … for the non-techies –> typing in a URL in the browser and hitting enter or clicking on a hyperlink.
From the base URL identified above, the URLs to access the services are as follows:
|Feed/AsXml||Returns an XML representation of TTSE trading data|
|Feed/AsCsv||Returns a CSV representation of TTSE trading data|
|Feed/AsRss20||Returns an RSS 2.0 representation of TTSE trading data|
|Feed/AsAtom10||Returns an ATOM 1.0 representation of TTSE trading data|
|Feed/AsJson||Returns a JSON representation of the TTSE trading data|
|Feed/AsHtml||Returns an HTML/XHTML representation of TTSE trading data|
What this mean is that developers can go to the following URLs and get the trade information from the TTSE:
|Fully qualified API URL|
Note the addition of the specific “API call” at the end of the base URL.
However, that isn’t all folks. All of the operations identified above support the following optional parameter list:
|date||Represents the date for which trade data should be returned.
|changesOnly||Defines whether or not all Securities or only those whose values have changed should be returned.
|market||* Currently not implemented completely, however, when implemented:
This will identify which market the user would like information returned from
tt – Gets data from Trinidad and Tobago Stock Exchange
|complexView||* Currently not implemented completely, however, when implemented:
This will determine whether more properties other than Tag, Volume, Open, Close and Change data will be returned
|styleUrl||Only supported by the AsHtml operation
When supplied, the HTML/XHTML document being returned by the call will be styled according to the CSS style sheet URL provided by this parameter
Format: <any url> that points to a style sheet
What all of that stuff up there means, is that if you would like to get the trade data for the 1st of June 2010 as a CSV you can go to the following URL:
The same pattern can be applied to any of the API calls and multiple parameters can be used in any order as long as they are properly delimited by the ampersand ( ‘&’ ) character. Here is an example to get trade data as XML on a specific date with only changed items:
The AsHtml?styleUrl parameter is an interesting one. Try using it without the parameter and then try using it with a sample style that I have provided. To make it easy I have provided the hyperlink below:
The parameters all have default values, as the API matures and * if * you guys think it interesting/useful enough to make use of it, then I’ll provide comprehensive documentation. What this means for developers is that you can easily inject data from this service into you own website and style the information such that it is consistent with you website. Cool huh… well I think it’s pretty cool.
I could go on a bit more about this, but I feel like the length of this post is getting out of hand … so I’ll start wrapping up …
According to their website (http://stockex.co.tt) in the Trading System section, the TTSE has moved to an electronic platform some time ago:
On March 18th 2005 the Trinidad and Tobago Stock Exchange Limited implemented an Electronic Trading System replacing the manual open outcry system which was used at the Exchange since its inception in 1981.
Wouldn’t it be fantastic if we could actually programmatically interface with this system and not have to “hack” a solution to this problem? Well hopefully someone from the TTSE will see this and get some ideas about how it can help drive Trinidad and Tobago towards a more information-driven society.
So, for all you coders out there, have fun with API’s and feel free to drop me a line at firstname.lastname@example.org if you have any comments or suggestions as to how they can be improved or any bugs that there may be.
PLEASE NOTE: These APIs are not supported by TTSE and there is no guarantee that I will absolutely have the time or resources to continue working on them, so I strongly suggest that you do not use these APIs on your production systems. If you wish to do so, contact me via email or by commenting on this post so that we can discuss further.