Trader (googlefied)
I decided to add a new module to my application to allow users to manage portfolios from other sources. My first such source was google portfolios because there’s a well-documented api for google finance.
Well, after a couple of hours of reading the apis for libcurl, json_spirit and testing, I have successfully added google portfolios to my application. You provide your email and password and it will authenticate with google and retrieve your portfolios, complete with transactions and positions.
Trader updates (code generation)
In an attempt to maximize my productivity and minimize errors I was dynamically creating the control widgets for the TA functions from a xml representation. The file looks like the following:
<Abbreviation>ACCBANDS</Abbreviation>
<CamelCaseName>Accbands</CamelCaseName>
<ShortDescription>Acceleration Bands</ShortDescription>
<GroupId>Overlap Studies</GroupId>
<Flags>
<Flag>Overlap</Flag>
</Flags>
<RequiredInputArguments>
<RequiredInputArgument>
<Type>High</Type>
<Name>High</Name>
</RequiredInputArgument>
<RequiredInputArgument>
<Type>Low</Type>
<Name>Low</Name>
</RequiredInputArgument>
<RequiredInputArgument>
<Type>Close</Type>
<Name>Close</Name>
</RequiredInputArgument>
</RequiredInputArguments>
<OptionalInputArguments>
<OptionalInputArgument>
<Name>Time Period</Name>
<ShortDescription>Number of period</ShortDescription>
<Type>Integer</Type>
<Range>
<Minimum>2</Minimum>
<Maximum>100000</Maximum>
<SuggestedStart>100000</SuggestedStart>
<SuggestedEnd>100000</SuggestedEnd>
<SuggestedIncrement>100000</SuggestedIncrement>
</Range>
<DefaultValue>20</DefaultValue>
</OptionalInputArgument>
</OptionalInputArguments>
I have highlighted the relevant parts. The file contains several hundreds of these listings and some have multiple optional input parameters (OptionalInputArgument) of different types (Integer, Double, etc) and precisions.
This is what I was trying to achieve:
I was using tinyxpath to parse this file and create spinboxes for each range using the gtk adjustments. These were then placed in a scrollwindow and added to a notebook for later retrieval. It was fairly straighforward code with the help of the stringstreams classes. The only problem was that it was terribly slow. I therefore deviced a plan to give it its own thread and dull/desensitive the toolbar item that was used to get to the charts. This gave me the following whenever the application started:
After a couple of runs with it it quickly became annoying and I decided to get rid of it. In comes code generation. Since I was already parsing it with the tinyxpath I had the framework to generate the C++ code for this. I wrote a basic class extending Gtk::ScrolledWindow and adding all the features that I wanted. I then modified my code for dynamically parsing the file to output C++ code for it. The relevant line is below:
ofs << "\t fc_" << j << "->add_item(\"" << name << "\","
<< val << ", " << min << ", " << max << ", " << inc
<< ", " << digits << ");" << std::endl;
After a few more modifications I have this now compiled and there is no need to utilize the “dulling” anymore. I have also totally eliminated the need for tinyxpath and I think that’s a positive improvement.
Trader updates (sqlite)
I made a couple of changes to the way the technical charts were displayed. I had always wanted to provide the user a way to query the data by periods. This really should be done with stored procedures and I was eager and looking forward to it till I remembered that sqlite doesn’t support them!
I have the source code for sqlite since I’m using the amalgamated version because I need to write some of my own functions to load either as dynamic shared libraries or statically linked into the code (I prefer the latter). I spent a while reading through the code and btrees for a while thinking of a clever way to do it and then I had an “Aha!” moment. I can simply do this in C++! A few enums, a couple of classes and some simple ternary lines and presto I’ve got it working. Was much quicker and more efficient than adding my own code, which would’ve had to be thoroughly tested in a multithreaded environment to make make sure it really worked.
I like how it turned out and I have one more screenshot to show
Now I need to do some more code generation.
Trader
I am building a gtk-based multithreaded stock trading software on linux. It is coded in C++ with some C and uses a number of open source libraries. The project is being developed commercially for financial institutions in Ghana and as such the code is closed. I will, however, be documenting my experiences here.
Screenshots
Enough words. Here are some screenshots of what I have so far ![]()
- Chart Window with Bar
- Basket Creation
- Created Basket
- Chart Window
- Chart Window Expanded
- Chart With Candlesticks
- Chart With TRIMA
- Chart With MACD
- Components Box
Open Source Libraries
These are some of the important libraries being used:
- gtkmm/glibmm – GUI, dates and threads
- libsigc++ – signals and slots
- cairomm – plotting charts
- sqlite3 – embedded database
- soci – abstraction layer for sqlite
- tinyXpath – parsing xml files
- ta-lib – technical analysis library
- libcurl – url transfer
- boost – multipurpose libraries
Development Environment
Most of my development is done on Ubuntu and would have been difficult without the following development tools:











