Keyboard Shortcuts
ctrl + shift + ? :
Show all keyboard shortcuts
ctrl + g :
Navigate to a group
ctrl + shift + f :
Find
ctrl + / :
Quick actions
esc to dismiss
Likes
- Twsapi
- Messages
Search
Working on polling any good ideas?
goldensilvermana
Are there any IT people that have access to a polling system we can
use (to enhance and push forward the development of a trading interface)or have any ideas on anyone who does? Looking for low cost solution. Idea: Team would send in ideas on polling questions that they would like answered and then vote on the items that would be put into the polls. They would have control of the questions asked and the results would be a benifit to them rather that someone else. IB has not volunteered yet to do this(specific) surveys. Posted thread items: (1) All interested parties need to make a list of what problems they want solved. IB request( no response) 1. Sponsor specific surveys (trading interface) to find out what are the major goals of IB's users that are real serious about a trading interface. |
TWS API VB files for newbies - 1st POST
multicen2002
Special thanx to users for trying to solve BUY/SALE/CANCEL
code lines for VB OCX. Nothing works .... It look like nobody knows or want to share a sample VB PROJECT in files area showing PROPER USE of: Tws1.placeOrder Many of us are not experienced in programming but we can modify a sample project. If there is a single person in this Group which can write a sample project with: Auto orderID numbering, BUY at ask , sale at BID and cancel odrer buttons PLEASE RESPOND. We do not want to know how you trade. All we need is your technical advice. Is this not why this TWS API group exists ?? Or maybe I am wrong?? TO OTHER USERS : PLEASE SUPPORT MY REQUEST by posting SUPPORT message Thanx everybody. Andrew |
VB: Code Sample, Level Intermediate....Dynamic ReqMarket Array Management
marinindextrader
The following code has been posted as a BAS module in the files
section: It is the topmost item on the list This module and the form code with it, will dynamically manage an array of all tickers called. It will update the array with tickPrice and tickSize events, and gives functions for deleting tickers that are no longer needed. It will not allow the duplicate call of a ticker. If you use identical tickers in several locations this will cut overhead The use of filter arrays to post tickPrice and tickSize eliminate the need for any conditional statments in the tickPrice tickSize TWS subs. One line of code keeps the array up to date. The cancel market data sub has some flags particular to my program. They can be eliminated and the sub can be passed the symbol as an arguement from elswhere in your program... Scott Yahoo TWS API The top commented section goes in the form that holds the TWS API, the rest would be put in a module. code follows: ''REQ MARKET DATA SUB ON MAIN FORM 'Private Sub reqMarketData() ' ' ' contract description vars ' Dim TWSsymbol As String, TWSsecType As String, TWSexpiry As String ' Dim TWSstrike As Single, TWSright As String, TWSexchange As String ' Dim TWScurency As String ' ' Dim Mirror(7) As Variant 'static; only passed in a sub call ' Dim Update() As Variant 'must be dynamic for assignment ' ' ReDim Update(1) ' ' 'assign security description ' TWSsymbol = m_newSymbol ' TWSsecType = cmbSecType.Text ' TWSexpiry = expiryAlphaToNum(cmbYear.Text & cmbMonth.Text) ' TWSstrike = 0 ' TWSright = "" ' TWSexchange = cmbExchange.Text ' TWScurency = "" ' ' 'assign values to the Mirror array, id ommitted; will be assigned ' Mirror(1) = TWSsymbol: Mirror(2) = TWSsecType: Mirror(3) = TWSexpiry ' Mirror(4) = TWSstrike: Mirror(5) = TWSright: Mirror(6) = TWSexchange: Mirror(7) = TWScurency ' ' 'pass Mirror out to module level function ' Update = Fxn_UpdateReqMarketArray(Mirror) ' ' 'evaluate results and call new ticker if needed ' If Update(1) Then ' Call Tws1(0).reqMktData(Update(0), TWSsymbol, TWSsecType, TWSexpiry, TWSstrike, _ ' TWSright, TWSexchange, TWScurency) ' ' 'this sub goes out onto the web and fetches Open, High, Low, Close ' 'using a Winsock Connection ' Call Init_GetClose(UCase(TWSsecType), LCase(TWSsymbol), TWSexpiry) ' ' 'the results are added to the master tick array ' 'you can find this code in the files section as GetClose.zip ' ' ' End If ' ' 'release the Mirror array ' Erase Mirror ' 'End Sub ' ''CANCEL MARKET DATA SUB ON MAIN FORM 'Private Sub cancelMktData() ' ' Dim bInUseTab As Boolean ' Dim bInUseGrid As Boolean ' Dim id As Long ' ' 'these two functions are specific to my program...similar functions would be ' 'crafted for your use if required; or you could pass the old symbol into the ' 'sub as an arguement; either way they are optional...you just need a symbol ' ' bInUseTab = Fxn_CheckForTabUse(m_oldSymbol) 'checks if still used (Tabs) ' bInUseGrid = Fxn_CheckForGridUse(m_oldSymbol) 'checks if still used (Grid Pages) ' ' 'if no longer needed then remove it ' If Not bInUseTab And Not bInUseGrid Then ' ' 'get the id# from the Req Market Array ' id = Fxn_GetOldSymbolID(m_oldSymbol) ' ' 'remove from the Req Market Array by id# ' Call Remove_ReqMarketArray(id) ' ' 'cancel the data stream using the id# ' Tws1(0).cancelMktData id ' ' End If ' 'End Sub ' ''TICKPRICE SUB ON MAIN FORM 'Private Sub Tws1_tickPrice(Index As Integer, ByVal id As Long, ByVal tickType As Long, _ ' ByVal price As Single) ' ' Call Update_ReqMarketArrayPrice(Index, id, tickType, price) ' 'End Sub ' ''TICKSIZE SUB ON MAIN FORM 'Private Sub Tws1_tickSize(Index As Integer, ByVal id As Long, ByVal tickType As Long, _ ' ByVal size As Long) ' ' Call Update_ReqMarketArraySize(Index, id, tickType, size) ' 'End Sub 'THE ABOVE CODE GOES ON THE FORM WHERE YOUR TWS API MODULE IS 'MODULE THAT MAINTAINS THE ARRAYS Option Explicit Private arrReqMarket() As Variant 'this is the Master Working array Private arrIndex() As Integer 'this array keep matches id's with an index value Private arrTranslator(5) As Integer 'this array is a filter for tickTypes 'SUB TO INITIALIZE THE VARIABLES Sub Init_VarsReqMarketMod() 'called on form load ReDim arrReqMarket(19, 0) 'the Value of this translator array is evident in the tickPrice and tickSize subs 'tickPrice bid-last-ask arrTranslator(1) = 8: arrTranslator(4) = 9: arrTranslator(2) = 10 'tickSize, bid-last-ask arrTranslator(0) = 11: arrTranslator(5) = 12: arrTranslator(3) = 13 End Sub 'FUNCTION TO ADD ELEMENTS TO ARRAY Function Fxn_UpdateReqMarketArray(ByRef Mirror() As Variant) As Variant() Dim iTemp As Integer Dim bMatch As Boolean Dim tempArray(1) As Variant Static id As Integer 'make static to remember 'searches the array and if mirror doesnt match adds an element For iTemp = 0 To UBound(arrReqMarket, 2) If arrReqMarket(1, iTemp) = Mirror(1) Then If arrReqMarket(2, iTemp) = Mirror(2) Then If arrReqMarket(3, iTemp) = Mirror(3) Then If arrReqMarket(4, iTemp) = Mirror(4) Then If arrReqMarket(5, iTemp) = Mirror(5) Then If arrReqMarket(6, iTemp) = Mirror(6) Then If arrReqMarket(7, iTemp) = Mirror(7) Then bMatch = True tempArray(0) = -1 tempArray(1) = False 'assignment..don't add Fxn_UpdateReqMarketArray = tempArray Debug.Print "perfect match" End If End If End If End If End If End If End If Next iTemp 'add a ticker if above is false If Not bMatch Then 'add array element 'incrament id by 1 id = id + 1 arrReqMarket(0, UBound(arrReqMarket, 2)) = id 'copy over the Mirror For iTemp = 1 To UBound(Mirror) arrReqMarket(iTemp, UBound(arrReqMarket, 2)) = Mirror(iTemp) Next iTemp 'Redim the ReqMarket array in preperation for next ticker ReDim Preserve arrReqMarket(UBound(arrReqMarket), UBound (arrReqMarket, 2) + 1) 'update the index finder array Call Update_IndexArray 'optional...just want to make sure the memory is released Erase tempArray 'assign results tempArray(0) = id tempArray(1) = True 'send back to ReqMarket Sub Fxn_UpdateReqMarketArray = tempArray End If End Function 'SUB TO REMOVE TICKERS Sub Remove_ReqMarketArray(ByVal id As Integer) Dim iTemp As Integer, iTemp2 As Integer Dim tempArray As Variant 'prep the tempArray for duty ReDim tempArray(UBound(arrReqMarket), 0) 'copy over all tickers that dont match the id to be removed For iTemp = 0 To UBound(arrReqMarket, 2) If id <> arrReqMarket(0, iTemp) Then For iTemp2 = 0 To UBound(arrReqMarket) tempArray(iTemp2, UBound(tempArray, 2)) = arrReqMarket (iTemp2, iTemp) Next iTemp2 'add a slot and loop again ReDim Preserve tempArray(UBound(arrReqMarket), UBound (tempArray, 2) + 1) End If Next iTemp 'assign the results and remove the tempArray arrReqMarket = tempArray Erase tempArray 'update the index finder array Call Update_IndexArray End Sub 'KEEPS THE INDEX FINDER ARRAY UP TO DATE Sub Update_IndexArray() Dim iTemp As Integer, MaxID As Integer, id As Integer Dim tempArray() As Integer 'find the highest id number For iTemp = 0 To UBound(arrReqMarket, 2) If arrReqMarket(0, iTemp) > MaxID Then MaxID = arrReqMarket(0, iTemp) End If Next iTemp 'dimension the temp array ReDim tempArray(MaxID) 'match the id with index For iTemp = 0 To UBound(arrReqMarket, 2) id = arrReqMarket(0, iTemp) tempArray(id) = iTemp Next iTemp 'assign index and remove the tempArray arrIndex = tempArray Erase tempArray End Sub 'FEEDS THE REQ MARKET ARRAY WITH PRICE INFO Sub Update_ReqMarketArrayPrice(ByVal Index As Integer, ByVal id As Integer, ByVal tickType As _ Integer, ByVal price As Single) 'update the Req Market array with each tickPrice; automatically arrReqMarket(arrTranslator(tickType), arrIndex(id)) = price End Sub 'FEEDS THE REQ MARKET ARRAY WITH SIZE INFO Sub Update_ReqMarketArraySize(ByVal Index As Integer, ByVal id As Integer, ByVal tickType As Integer, _ ByVal size As Integer) 'update the Req Market array with each tickSize; automatically arrReqMarket(arrTranslator(tickType), arrIndex(id)) = size End Sub 'FINDS THE SYMBOL ID GIVEN THE SYMBOL Function Fxn_GetOldSymbolID(f_oldSymbol) As Integer Dim iTemp As Integer 'go find the id# 'match with symbol For iTemp = 0 To UBound(arrReqMarket, 2) - 1 If arrReqMarket(1, iTemp) = f_oldSymbol Then 'assignment Fxn_GetOldSymbolID = arrReqMarket(0, iTemp) Exit For 'bail out End If Next iTemp 'this Finder function could take an array as an arguement if you want an 'all points match similiar to the Fxn_UpdateReqMarketArray function above End Function |
Re: twsapi: Demo Server Question
marinindextrader
Thanks Todd
toggle quoted message
Show quoted text
--- In twsapi@y..., Todd Turner <todd_a_turner@y...> wrote:
I use the demo accounts with the standalone TWS all |
Re: Please help - VB code --- SEE command4_click
marinindextrader
This call:
Private Sub Command4_Click() Call Tws1.placeOrder(3030, "BUY", 1, "ES", "FUT", "200209", "", "", "GLOBEX", "", "LMT", 0, 0) End Sub Is incorrect.... Proper call for limit order: Call Tws1.placeOrder(3030, "BUY", 1, "ES", "FUT", "200209", _ 0, "", "GLOBEX", "", "LMT", 1000.00, 0) Strike is of type "float", and must be defined with a numeric value; Not an empty string... And if you are sending a limit order, you must define a limit price.... I believe you can just leave the currency field blank... "GLOBEX", , "LMT", not sure about this but I think it isn't even looked at unless secType is of type CASH Scott |
Re: twsapi: Demo Server Question
Todd Turner
I use the demo accounts with the standalone TWS all
the time: Login: cdemo for futures and edemo for stocks. Password: demouser for both --- marinindextrader <marinindextrader@...> wrote: To any and all... __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup |
Re: Please help - VB code --- SEE command4_click
marinindextrader
Your IF statements need to define their upper limits just under the
threshold of the next limit...otherwise they will all trigger....is that what you wanted? Example: If size >= 10 And size < 20 Then Label7.Visible = True Else Label7.Visible = False End If If size >= 20 And size < 30 Then Label8.Visible = True Else Label8.Visible = False End If |
Re: Please, help
multicen2002
DAVID
it's working U R LifeSAVER.. thank you so much Andrew --- In twsapi@y..., "David" <kotomo@p...> wrote: as it may workPrivate Sub Command4_Click()1, "ES", "FUT", "200209", 0, "", "GLOBEX", "", "LMT", 1025, 0 put there the right "YOUR" priceread the rewuirements and check your DIM statementsEnd Sub----- Original Message ----- you probably define,say, quantity as long or single and should beinteger this is your problemand I canlarger > number and increase by delta of 10 or more ( still firstorder maythen placeother changeslike you,Terms of > Service.Service. Service. |
Re: twsapi: Please, help
David
开云体育>?? Private Sub
Command4_Click()
> >?? Tws1.placeOrder 3030, "BUY",? ?? 1, "ES", "FUT", "200209", 0, "", "GLOBEX", "", "LMT", 1025, 0 1025 is the price you wnat to buy or better - be careful with this as it may work put there the right "YOUR" price
>?? End Sub >
|
Please help - VB code --- SEE command4_click
multicen2002
Option Explicit
' contract description vars Dim id As Long Dim symbol As String Dim secType As String Dim expiry As String Dim strike As Long Dim right As String Dim exchange As String Dim curency As String Dim port As Long Private Sub Command1_Click() Tws1.reqMktData id, symbol, secType, expiry, strike, right, exchange, curency Label23.ForeColor = vbGreen Label23.Caption = "connected" End Sub Private Sub Command2_Click() Tws1.cancelMktData id Label23.ForeColor = vbRed Label23.Caption = "disconnected" End Sub ** BAD CODE ** Private Sub Command4_Click() Call Tws1.placeOrder(3030, "BUY", 1, "ES", "FUT", "200209", "", "", "GLOBEX", "", "LMT", 0, 0) End Sub Private Sub Form_Load() 'Here I have set all of the values as static constants for demonstration purposes port = 7496 'this is the port number you wrote down id = 1 ' symbol = "ES" secType = "FUT" expiry = "200209" strike = 0 right = "" exchange = "GLOBEX" curency = "" Tws1.Connect "", port 'This must be the very first thing that is called End Sub '------------------------------------------------------ ' PRICES '------------------------------------------------------ Private Sub Tws1_tickPrice(ByVal id As Long, ByVal tickType As Long, ByVal price As Single) 'Dim oldprice 'Dim lastprice 'If tickType = LastPriceID Then 'If price > oldprice Then 'Label26.BackColor = vbRed 'End If 'oldprice = price 'End If 'End Sub '* 'PRICE -last transaction '* Dim LastPrice If id = 1 Then 'reference the reqMktData call by its id number If tickType = 4 Then LastPrice = price Label1.Caption = Format(LastPrice, "0.00") End If End If '* 'PRICE - BID '* Dim BIDPrice If id = 1 Then 'reference the reqMktData call by its id number If tickType = 1 Then BIDPrice = price Label3.Caption = Format(BIDPrice, "0.00") End If End If '* 'PRICE - ASK '* Dim ASKPrice If id = 1 Then 'reference the reqMktData call by its id number If tickType = 2 Then ASKPrice = price Label4.Caption = Format(ASKPrice, "0.00") End If End If End Sub '------------------------------------------------------ ' SIZES '------------------------------------------------------ '* 'SIZE - LAST '* Private Sub Tws1_tickSize(ByVal id As Long, ByVal tickType As Long, ByVal size As Long) If id = 1 Then 'reference MUST BE 1 If tickType = 5 Then 'Label2.Caption = Format(size, "000000") Label2.Caption = size End If End If '* 'SIZE - BID '* If id = 1 Then 'reference MUST BE 1 If tickType = 0 Then Label5.Caption = size If size > 10 Then Label7.Visible = True Else Label7.Visible = False End If If size > 20 Then Label8.Visible = True Else Label8.Visible = False End If If size > 30 Then Label9.Visible = True Else Label9.Visible = False End If If size > 40 Then Label10.Visible = True Else Label10.Visible = False End If If size > 60 Then Label11.Visible = True Else Label11.Visible = False End If If size > 100 Then Label12.Visible = True Else Label12.Visible = False End If If size > 140 Then Label13.Visible = True Else Label13.Visible = False End If If size > 180 Then Label14.Visible = True Else Label14.Visible = False End If If size > 240 Then Label15.Visible = True Else Label15.Visible = False End If If size > 320 Then Label16.Visible = True Else Label16.Visible = False End If If size > 440 Then Label17.Visible = True Else Label17.Visible = False End If If size > 560 Then Label18.Visible = True Else Label18.Visible = False End If If size > 680 Then Label19.Visible = True Else Label19.Visible = False End If If size > 800 Then Label20.Visible = True Else Label20.Visible = False End If If size > 1200 Then Label21.Visible = True Else Label21.Visible = False End If If size > 2000 Then Label22.Visible = True Else Label22.Visible = False End If End If End If '* 'SIZE - ASK '* If id = 1 Then 'reference MUST BE 1 If tickType = 3 Then Label6.Caption = size End If End If End Sub |
Re: twsapi: Please, help
David
开云体育Type mismatch - your declarations of your variables is
incorrect - read the rewuirements and check your DIM statements
you probably define,say,?quantity as long or single and
should be integer
this is your problem
?
?
|
Re: Please, help
multicen2002
Please, will you overrite my code line to work ??
it is not working - market , limit..NONE thanx David Andrew --- In twsapi@y..., "David" <kotomo@p...> wrote: You have to specify the limit price for the LMT orders - put therthe CurrentAsk to get you in the market now. ----- Original Message -----line ?? Please, post a sample code line which really works for you and Ican go from there.may cause duplicate error - keep trying or increase first and thenplace an order)changes will not make it work(dont trade ES)you, > everything starting to work just fine.Service. |
Re: twsapi: Please, help
David
开云体育You have to specify the limit price for the LMT orders - put
ther the CurrentAsk to get you in the market now.
|
Re: twsapi: Please, help
multicen2002
Run-time Error 13
--- In twsapi@y..., "David" <kotomo@p...> wrote: what errors do you get ?line ?? Please, post a sample code line which really works for you and Ican go from there.may cause duplicate error - keep trying or increase first and thenplace an order)changes will not make it work(dont trade ES)you, > everything starting to work just fine.Service. |
Re: twsapi: Please, help
multicen2002
Run-time Error 13
--- In twsapi@y..., "David" <kotomo@p...> wrote: what errors do you get ?line ?? Please, post a sample code line which really works for you and Ican go from there.may cause duplicate error - keep trying or increase first and thenplace an order)changes will not make it work(dont trade ES)you, > everything starting to work just fine.Service. |
Re: twsapi: Please, help
David
开云体育what errors do you get ?
|
Re: twsapi: Please, help
multicen2002
Thank you for trying David.
But again it is not working.. everything else works fine. Anybody know how to solve my 1 week long torture with this line ?? Please, post a sample code line which really works for you and I can go from there. WARM Thank you to You all. Andrew !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ----------------------------------- bad code line start here ----------------------------------- Private Sub Command4_Click() Tws1.placeOrder 3030, "BUY", 1, "ES", "FUT", "200209", "", "", "GLOBEX", "", "LMT", 0, 0 End Sub --- In twsapi@y..., "David" <kotomo@p...> wrote: First, your ORDERID - 1 could be a PROBLEM - generate a largernumber and increase by delta of 10 or more ( still first order may cause duplicate error - keep trying or increase first and then place an order) after Expire Date - the strike price use 0will not make it work(dont trade ES) again for currency use ""Service. |
Re: twsapi: Please, help
David
开云体育First, your ORDERID - 1 could be a PROBLEM - generate a larger
number and increase by delta of 10 or more ( still first order may cause
duplicate error - keep trying or increase first and then place an
order)
after Expire Date - the strike price use 0
right? use "" instead
on the exchange not sure - use "GLOBEX" if after the other
changes will not make it work(dont trade ES)
again for currency use ""
This should work
David
|
Please, help
multicen2002
Hi,
I am working on my VB API for IB platform. Thanx to ppl like you, everything starting to work just fine. BUT.. I wasted 1 week trying to send limit order from my box. what is wrong with this code ?? ---------------------------------------- code ---------------------------------------- Private Sub Command4_Click() Tws1.placeOrder 1, "BUY", 1, "ES", "FUT", "200209",_ LastPrice, , "SMART", , "LMT", LastPrice, 0 End Sub Please, help .. multicen2002@... |
Demo Server Question
marinindextrader
To any and all...
I have never used the demo server. I have always used my accounts...for testing What is up with the demo server? When I fire up my client side TWS what special user name and password are required to access the demo server? I have a suspicion that you need to log on through the web based Java platform to access the demo server accounts...I hope I am wrong... Thanks Scott |
to navigate to use esc to dismiss