Requesting historical data through TWS API with C++ Part 2
Author: Joe
Tutorial Objective: Request historical
quote data from TWS and print the data to the screen..
Souce Code: Download
the full source for this tutorial Here
Disclaimer
This tutorial is to be used at your own risk. By using this tutorial
you agree not to hold the writers of this tutorial, StockBotProgramming.com,
or anyone affiliated with StockBotProgrammign.com liable for any
damages that may occur as a result of using this tutorial and/or
provided source code.
This tutorial will assume you have a copy of Visual Studio 2005
and have Interactive Broker's TWS API installed. You can get a copy
Visual Studio Here,
and the TWS API is available for download Here.
It is highly recommended that you read Requesting historical data through TWS API with
C++ before attempting this tutorial. If you have any suggestions
regarding this tutorial or if you notice any mistakes please suggest it here.
Today we are going to build off of the source code from Requesting historical data through TWS API with
C++ and add code save the historical data in a comma separated
format for use with backtesting. This will be a very small and easy
change.
The first thing to do is create a global variable named globalName
by adding the following line to the top of the program:
char globalName[50];
Next we need to initialize this variable with the stock symbol
we want to look up. Add the following line to the top of the main()
function.
strcpy(globalName,"MSFT");
The next step is to change the following piece of code to use the
globalName variable:
contract.c_symbol = globalName;
Next goto the function event_historical_data(). Replace the printing
statement with the following code:
FILE*output=fopen("c:\\c++data.txt","a");
fprintf(output,"\n%s,%s,%f,%f,%f,%f,%d",globalName,date,open,high,low,close,volume);
fclose(output);
Now you should be able to use this code, as a building block for
any tools you may need for gathering historical data.
Download the full source
for this project Here
|