I am having some trouble understanding the code in the sample application. Say I am starting a new form and I have one textbox on the form. How do I connect the textbox so that it grabs the last price. I think after I see this example by itself I will understand. Can someone help? Thanks.
Timmy, they have samples in VB in the IB website. Basically, you have to have an event code that processes the events (i.e puts it into your textbox)
if you're talking about the downloadable sample i have looked at it. this is the one i don't understand. can you please give some code that only deals with what i'm talking about or pseudo code or the logic of the connection?
It would be helpful if you post the code you don't understand. Are you using Visual Studio.NET, or VB.6?
That's the thing. The code in the sample is mixed up with so much other code that i don't know which ones i need and don't need. i'm not really asking for an explanation of code i already have. lets just say you're starting clean. you have a new form and a textbox. you want the textbox to grab the last price. how do you do this? can you provide the code to do this and come comments? i think i can figure it out from there. oh, this is vb6.
I highly recommend that you move up to VB.NET, since VB6 is obsolete. Anyway, you must first add IBâs ActiveX component to your form like you added the textbox. Then, in your code window, there are two drop-down menus on top. The left one lists your component objects you added to the form. Select IBâs ActiveX control. Then, the right drop-down menu lists its corresponding methods and events. Select the appropriate event associated with price updating. VB6 will then automatically create the subroutine for you, containing parameters that pass the last price, and probably other items as well. Simply assign the textboxâs text value to the price variable passed as a parameter. For example: Private Sub NewPriceEvent(SymbolName as String, Price as Double) Text1.text = Price End Sub
hope this helps. This is very close to real code, just missing assigment statements for the putright,exp1,etc. like exp1="09/09/2002" Create a button with this code in the click event. id=1 is IBM, Id=2 = wmt for example. Call Tws1.reqMktData(1, "IBM", secType, exp1, strike, PutRight, mult, exch, exch, cur) Call Tws1.reqMktData(2, "WMT", secType, exp1, strike, PutRight, mult, exch, exch, cur) In the form put this sub Private Sub Tws1_tickPrice(ByVal id As Long, ByVal TickType As Long, ByVal price As Double, ByVal canAutoExecute As Long) Dim mktDataStr As String If id = 1 And TickType = 4 Then text1.text = price 'IBM last price ElseIf id =2 If TickType = 4 Then text2.text= price 'wmt price endif end sub This Tws1 is the "event sink " which will get any events fired back and you need to capture it. Good luck
sam123, whoa that looks easy! thanks. while i have your attention, do you mind explaining in plain english what "property get" and "enumerations" do for you? why not just use simple variables and constants? i have tried googling but the explanations seem to always be kind of theoretical and wordy, so i don't understand when you would need to use them. the sample code from ib uses them. lastly, i'm sure you can tell by now that i've taught myself some vb6, but still have lots to learn. as far as i can tell, there is still a huge community of vb6 developers out there and they bitch about vb.net. are there any clear advantages of using vb.net or anything you can't do with vb6 that you can do with vb.net? i'm not talking about saving .0000000000000002 milliseconds or something trivial like that.
thanks gatrader. i'll need to mess around with it some more. if any of you don't mind saving me some time, can you please show me comprehensive working example? i have a form with 1 textbox. i added the tws control. now, i need to connect it and have the last price of say "YHOO" show in the textbox. what code do i need and where do i put it? i hope i'm not being unreasonable with this request. thanks.
okay great. i got it to work, but i have a question about reqmktdata. GATrader: In your example, reqmktdata has 10 arguments. However, in the IB User Guide, it says that there are only 9. Below is what it says in the IB user's guide. void reqMktData(long id, String symbol, String secType, String expiry, double strike, String right, String multiplier String exchange, String currency) It looks like 10 is correct because if I use the 9 like the User's guide says, I get an error that says "argument not optional." If the User's guide is incorrect, then how did you know what the 10th one is?