Stockyard Architecture

The Stockyard system is divided into the standard three tiers: client, server, and database.  The database is provided by MySQL.  The server sub-system uses the API provided by the PACT Consulting Group to access the MyTrack brokerage servers.  

When I first coded the program, the client and server portions where tightly coupled in a single executable file.  Later I decided that I wanted my CPU to run only the server component at a higher priority to improve performance.  This left me at a quandary since both sides share the data structures that contained stock data.  Duplicating the data introduces a whole new network protocol between client and server which uses up more CPU and network resources. (COM was out of the question because a buddy of mine told me of the performance hit I'll would take.)  Because I imagine only running the client on the same machine as the server, I decided on a shared memory and a basic winsock implementation.  More on this in the Code Walkthrough section.

 

Behind the Code

The database consist of tables to hold both stock and position data.  There are over 5000 stock symbols stored there.  Along with each symbol is data relevant to the stock ticker, such bid and ask prices, historical data, and variables I came up with.  About every quarter, I update the database with the lastest stock symbols from the NASDAQ and NYSE using the Stockyard Manager.  I chose the NASDAQ and NYSE only because they are the most popular American exchanges -- for other exchanges, I would have to pay the brokerage firm extra service fees for quote and ticker updates.

Based on price criteria, a subset of stocks are loaded onto the program's memory.  When the markets are open, these stocks receive at least one quote update.  Due to bandwidth, brokerage servers restrict the amount of requests they receive from users like me; therefore the Stockyard server sends one quote request at time as defined by me. Currently with an interval set at one second, it takes the server a minimum of 30 minutes to send requests and process responses for the over 2000 stocks.  On a typical day, a stock can receive a minimum of eight quotes -- but these are "unplayable" stocks so receiving only eight quotes for them are acceptable.

A subset of these stocks, the playable ones, get more than just quotes -- they receive ticker messages.  Tickers are real-time price updates the brokerage firm receives from a market when a stock is traded.  The brokerage then passes on these messages to their subscribers which include my Stockyard server.  In other words, Stockyard knows immediately when a stock is traded on the markets.  Due to bandwidth limitations, 200 stocks at most can receive ticker updates.  Please note that MyTrack has a disclaimer that it does not guarantee the "'accuracy, completeness, timeliness, or fitness" of the information it provides.  Most firms that provide market data can say the same thing. My concern is to only obtain a fair portrayal of the market conditions, even if the data is not complete.  Unless I am standing on the floor of an exchange, I cannot expect 100% data accuracy nor should anyone else... but I digressed.

What makes a stock "playable"?  This is where writing your own trading software becomes an advantage.  I created a scoring system where stocks are rated based on chart movements.  My scoring ranges from -10000 to +10000: a stock with a score of 10000 is a strong candidate for a LONG position (buy first, sell later); a stock with a -10000 is a strong candidate for a SHORT position (short first, cover later).  A stock becomes playable when it receives a non-zero score and is promoted to a special list (the Scout Board) to receive ticker updates.  However if 200 stocks are already on the Scout Board (since only a maximum of 200 stocks can receive ticker updates), a stock cannot be promoted unless it has a higher absolute score than a stock already on the list, in which case that stock is demoted to receiving only periodic quotes.

At the very least, the scoring system helps me identify which stocks are of interest to play.  At best, I can allow Stockyard to trade a stocks by itself once its score reaches a certain value.  This part of the program is constantly being revised as I try to come up with new and hopefully more accurate algorithms.  Luckily, the brokerage firm provides a "simulation" account that allows me to simulate trading stocks with Monopoly money.  I can practice on this simulation account while concurrently trading using my real account.

Trading can be as simple as clicking a button, or I can set limits.  I can also setting target and stop prices, and plan accumulation or reduction of holdings.  There is also news and Level II data.  I seem to keep adding new stuff as I come up with them so the list of features is everchanging.  Therefore this is not "The End," but rather "To Be Continued."

 

 
 

<< Beginnings

Windows >>

 

 

1