***A simple interface for the Interactive Brokers TraderWorkstation API using C++ ***
The program must compile on vista using a freely available compiler. The program will run from the command line. The program is intended to be run once per day on a daily basis, to submit externally generated trade orders to TWS.
The program will first connect to TWS using the C++ API. Then it will perform the following functions:
1) Basic Orders
It will monitor a simple text file “[url removed, login to view]” for changes. New lines will be added externally to this text file, with each line representing a new order.
These will be basic orders of the format:
StopLoss, TICKER, Exchange,OrderType, Buy/Sell, Quantity, LimitPrice, AuxPrice, timeInForce, ocaGroup, Transmit
The first field is the StopLoss, explained below. All the subsequent fields are standard fields for basic order types with the TWS API, and should be familiar to anyone programming the API.
The program will read each new order as they are appended to the bottom of the “[url removed, login to view]” file, and will then submit them to TWS. Information about the order will be printed out as orders are accepted and filled (the order parameters, and the order status e.g: submitted, part filled, filled, fill price etc).
2) Automatic Stop Losses
The program will take a Boolean command line argument as to whether to produce protective stops for each order. If this is set to TRUE, then the program must also manage a protective StopLoss order for each order. This represents an order of type STP for an equal number of shares as the parent order, with the order in the opposite direction. E.g. when the parent order is a BUY, the StopLoss order will be a STP SELL order, and vice versa.
The price of the STP order is taken from the first field of the order in the [url removed, login to view] file. If empty, a default of 5% of the parent order fill is used. If this first field contains a number (e.g. 23.56), this will be the STP price. If it contains a number followed by a % sign (e.g. 5%), the STP order will be calculated according to the average fill price of the parent order, once the parent order is completely filled. Each order thus has its own unique StopLoss.
If a new order from the text file closes (or partially closes) an existing position which was entered earlier, it will alter the stop loss appropriately. E.g. if the new order partially closes an existing position, the program will reduce the order quantity of the StopLoss. If a new order completely closes an existing position, it will completely remove the stop loss. If a position is exited manually through TWS, the program will also cancel the StopLoss order.
3) Close positions at a set time
A further command line argument will allow the user to specify a time at which all positions will be “flattened”. E.g. all positions exited using a market order. The appropriate StopLoss orders will also be cancelled.
4) Print Info to file
Verbose output concerning the state of the connection and orders should be outputted to the command line and to a dated logfile.
Furthermore, each order will output key information to a second, less verbose logfile. This will contain the following information for each order on one line each: The original order information from the [url removed, login to view] file, the average fill price, the StopLoss price, total commission, the time the order was entered, and the time the order was filled.