|
|
Requesting live data through TWS API with C# .Net Part 2
Author: Joe
Tutorial Objective: Request live
volume data from Interactive Brokers TWS api using C# .Net
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 live data through TWS API with C#.Net
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 modify our code to receive tick volume updates
and display those updates in a ListBox control. Go ahead and open
up your code from Requesting live data through TWS API with C# .Net
. If you did not complete the tutorial, you can download the full
source code at the end of its page.
From the previous tutorial we have already made a request to TWS for data
updates. However, up to this point we only wrote the function needed catch
the price updates. Now we will add the function call needed to catch the
volume updates as well. First we need to tell C# what function will receive
this information. Add the following line inside the form_load.
Tws1.tickSize += new AxTWSLib._DTwsEvents_tickSizeEventHandler(this.tickSize);
Now we need to declare this function, add the following function:
private void tickSize(object sender, AxTWSLib._DTwsEvents_tickSizeEvent
e)
{
String msg = "Volume Update: Id=" + e.id + " Type: " + e.tickType
+ " Size: " + e.size;
listBox1.Items.Add(msg);
}
Just like in the price update function we have 3 important pieces of
information. We have the e.id which matches to our requesting id. We have
e.size which is the volume/size information being sent, and we have
e.tickType which specifies what type of information we are
receiving.
tickType=0 means bid size
tickType=3 means ask size
tickType=5 means last trade size
tickType=6 means volume
Now you should be able to make TWS send you all the live price/volume
information you need to make your trading decisions.
Download the full source for this tutorial Here
Similar tutorials
|
|
|