Designing an Automated Trading Application on the Netbeans Rich Client Platform (Part 1)
Over the past 10 years new opportunities have opened in the stock, futures and currency markets to allow retail traders the ability to produce their own automated trading strategies which was once only the realm of hedge funds and investment banks. Interactive Brokers was one of the first brokerage firms to offer a Java API to its retail customers. Originally envisioned as way for developers to augment Interactive Brokers Trader Workstation (TWS) desktop application with features such as charting or record keeping, the API has gained popularity as a way to automate trading strategies.
In my first iteration of developing a trading strategy and software to automate the trades I built a Java desktop application using Swing components which would monitor stocks throughout the day and place trades when certain parameters were met, and then exit the trades at the close of the trading day. The software worked well, and it was adequate for the strategy it was designed to trade, however it was not extensible and attempting to implement new trading strategies to automate as well as connect to different brokerage accounts proved difficult and cumbersome. Also, there are restrictions on how many stocks could be monitored via the broker’s data feed so the software had to be able to accommodate real-time market data feeds from other sources in addition to the broker’s data feed.
I was introduced to the Netbeans Rich Client Platform (RCP) a couple of years ago and have recently decided to begin porting my application to the platform due to a large number of advantages that it provides. The Netbeans RCP is built on a modular design principle allowing the developer to define abstract APIs for features and then provide modules which may have different implementations of the API, allowing the application to select at runtime which implementation to use. Not only does it provide for a cleaner design by separating concerns, but by using the Netbeans Lookup API it also decouples the application and its various components from each other. There are numerous other features that can be leveraged including a built-in windowing system, text editor, file explorer, toolbar, table and tree table components as well the Action API (just to name a few).
The trading application will make use of the RCP module system to define abstract APIs with the following functionality:
- Place and cancel orders for stocks, options, futures, or currencies
- Provide event notification when orders are filled
- Monitor cash balances in the account
Market Data API
- Subscribe to real-time quote data for any ticker symbol
- Subscribe to Level 2 data (market depth/order-book) for any ticker symbol
Historical Data API
- Request historical price data for any ticker symbol
Trading Strategy API
- Define a set of rules for entering and exiting trades
- Ability to use any broker, market data, and historical data API implementations in order to make trading decisions.
The primary implementation for the Broker, Market Data and Historical data API modules will be utilizing Interactive Broker’s Java API, but other implementations can also be created as Netbeans modules and then imported into the trading application so that trading strategies can make use of market data from different sources if needed.
New trading strategies can be built as Netbeans modules
implementing the Trading Strategy API, where each strategy can make use of one
of the implementations of the various data and broker APIs. Utilizing the
Netbeans Lookup API, strategies can query the platform to get a list of all
implementations of the broker and market data APIs providing for loose coupling
between the APIs and allowing the user to select which implementation to use at
Below is a diagram illustrating the organization of the various API components of the application:
In future posts I will go into more detail on how to create an API plug-in for the Netbeans RCP as well as show how to create a concrete implementation of the API. In the illustration above the abstract broker, market data, and trading strategy APIs are installed into the RCP as plug-ins. The broker API has a single implementation for Interactive Brokers at this point in time. The market data API has plug-ins which provide implementations for real-time market data from Yahoo Finance as well as Interactive Brokers real-time market data. Finally, the trading strategy API has 2 implementations in this example. The first strategy named “Limit Buyer” will watch the prices of approx 800 stocks and place limit order to buy when certain conditions are met. The second strategy in the example above, named AUD/NZD Currency Strategy will monitor the exchange rates of the Australian and New Zealand dollars and place orders to buy or sell when certain conditions are met.
At this point in time the application is functional and is utilizing Interactive Brokers as the main brokerage as well as market data provider. The AUD/NZD trading strategy is actively being traded through the application, albeit with a rudimentary user interface which is publishing messages to a text area within the strategy’s main tab. The screenshot below illustrates Interactive Brokers “Trader Workstation” application, the large black application (which is a Java Swing app), as well as the Netbeans RCP automated trading application which is the small white application, with the large text area. In the screenshot below the application is currently monitoring prices and placing trades for the Australian Dollar, New Zealand dollar, Hong Kong dollar and Japanese yen currencies.
This post is just a high level overview on the design of an RCP application to trade in the financial markets. Future parts to this series will include more information on how to implement abstract APIs and make them available for other portions of the application to use via the Netbeans Lookup API as well as working with some of the Netbeans UI components included with the platform such as tabs, trees and tables, showing how easy it is to render the same data via these different views using the Netbeans Nodes API. In addition to this I would like to incorporate some JavaFX components into the application such as the charting components that can be found in the core JavaFX library which will provide a graphical representation of some of the data the strategies are monitoring which will be a bit more user friendly than the current large text area. The integration of JavaFX components within the application will be documented in a future post as well.
You can follow my trading related blog if you would like to see
the actual trading results of the application as its being refined at:
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)