开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育
Date

Re: VB Sample Project: How To Place An Order

marinindextrader
 

Here is the footnote I left off concerning order id's, thier creation
and value.

Why choose an arbitrary value for an order id?

I might suggest that your order id system be based on time.
Using various functions one can extract a string from the system time
and date, convert it to a long value and then and use this as an id.

Why would one want to do this?

If they were (in the future) to decide to capture all trades and
store in a database, the id can be reconverted into its date value
and reports can be printed on a time basis.

Here is a crude example of creating an id based on date and time:

Example Date: 6/20/02 10:24:17 AM

Private Sub Command2_Click()
Dim newString As String
Dim newId As Long
newString = newString & Month(Date)
newString = newString & Day(Date)
newString = newString & DatePart("h", Now)
newString = newString & DatePart("m", Now)
newString = newString & DatePart("s", Now)

Text1 = newString 'displays 620102417; a unique number
newId = CLng(newString) 'convert to long value

'this value is within the confines of Long type data: 2,147,483,647


End Sub


There are other reasons to manipulate the order id...

What if you want your id to be based on a conditional check of the
symbol...for instance all trades with cisco will be between X and Y...

Or...if you trade options you might want an order prefix that
describes where in the money you are...or something like that..
I dont know much about options specifications

Or...you may want use an ordering system that relates to the type of
trade it was...Long or Short...

The choices are endless, and to dismiss everything but an arbitrary
system is ridiculous

If your storing the number...put it to work

Scott

Owner TWS API Yahoo Discussion Forum
"The other Yahoo Board"

heheheheh


Re: twsapi: Re: VB Sample Project: How To Place An Order [Code]

 

开云体育

Thanks once again Scott,
?
Bruce
?
?
?

----- Original Message -----
Sent: Sunday, June 23, 2002 10:37 AM
Subject: twsapi: Re: VB Sample Project: How To Place An Order [Code]

Put a Text1 textbox on your form.
Put a Command1 command button on your form
Add a Simple BAS Module

Stick this in the Form: (and the rest in the Module)

Private Sub Command1_Click()

?? 'here I have just plugged in literal values for the example
?? 'of course you could pull these in as variables or control
properties
?? 'such as a combo box text or what not...
?? Call PlaceNewOrder("BUY", 1, "ES", "FUT", "200209",
0, "", "GLOBEX", "", "MKT", 0, 0)
End Sub

Private Sub Form_Load()

?? 'connection call
?? Tws1.Connect "", 7496
??
?? 'initialize your module variables
?? Call InitVarsNewOrderMod
?? Text1 = "PLACE ORDER DEMO:" & vbCrLf & vbCrLf & _
??????????? "When you click Command1, a market order will fire off
for 1 Contract of September " & _
??????????? "ES. Keep clicking it and it will keep buying one at
market. Each time you click, " & _
??????????? "This box will fill with the order information stored in
your array"

End Sub


'and use this for when you log out and relog in
'you can conditionally test next valid id in the module

Private Sub Tws1_nextValidId(ByVal id As Long)

?? 'call a module level Sub that captures the IB id on log in
?? Call CaptureID(id)
??

End Sub

'now create a private sub that will handle the order routines
'the array captures the order info and stores it for you
'good idea IMHO to internally track this info and not rely
'on IB soley

Private Sub PlaceNewOrder(ByVal action As String, ByVal quantity As
Long, _
?? ByVal symbol As String, ByVal secType As String, ByVal expiry As
String, _
?? ByVal strike As Double, ByVal right As String, ByVal exchange As
String, _
?? ByVal curency As String, ByVal orderType As String, ByVal lmtPrice
As Double, _
?? ByVal auxPrice As Double)
??
?? Dim mirror(12) As Variant 'left this as zero based for clarity
??
?? Dim newID As Long
??
?? 'assign all of the arguements to the array
?? 'not the conspicuous absence of id in the arguements
??
?? mirror(1) = action: mirror(2) = quantity: mirror(3) = symbol
?? mirror(4) = secType: mirror(5) = expiry: mirror(6) = strike:
?? mirror(7) = right: mirror(8) = exchange: mirror(9) = curency:
?? mirror(10) = orderType: mirror(11) = lmtPrice: mirror(12) =
auxPrice
??
?? 'pass the array out to the module
?? newID = Get_Set_NewOrderID(mirror)
??
?
?? 'place the order
?? Call Tws1.placeOrder(newID, action, quantity, symbol, secType,
expiry, strike, right, exchange, _
?? curency, orderType, price, auxPrice)


End Sub

'MODULE CODE STARTS HERE

Option Explicit

Private m_arrOrders() As Variant 'master array
Private m_myID As Long 'your starting point
Private m_theirID As Long 'thier starting point
Private m_nextID 'next id your going to use
Private m_incrament As Integer 'a variable to incrament by any value;
1, 5, 10 etc
'


'call on form load
Sub InitVarsNewOrderMod()

?? m_myID = 3030 'set your starting level here
??
?? ReDim m_arrOrders(12, 0)
??
?? m_incrament = 10 'optional to incrament by other than 1

End Sub


Sub CaptureID(ByVal theirID As Long)
??
?? 'capture theirs at log on
?? m_theirID = theirID
??
??
End Sub

'store your order info and give an id back to the calling sub
'this is the workhorse

Function Get_Set_NewOrderID(ByVal mirror As Variant) As Long

?? Dim iTemp As Integer
??
?? 'find the proper id; this looks a little convaluted but stare at it
?? 'you will see that if the next available IB id is greater than
your starting
?? 'point, it will back up one then add your incrament
?? 'otherwise it just keeps ripping out new id's per your incrament
?? If m_theirID < m_myID Then
????? m_nextID = m_myID
????? m_myID = m_myID + m_incrament
?? Else
????? m_myID = m_theirID - 1 + m_incrament
????? m_nextID = m_myID
????? m_myID = m_myID + m_incrament
?? End If
??
?? 'assign the id to the first element of the array
?? m_arrOrders(0, UBound(m_arrOrders, 2)) = m_nextID
??
?? 'assign the mirror to the rest of the array
?? For iTemp = 1 To UBound(m_arrOrders)
????? m_arrOrders(iTemp, UBound(m_arrOrders, 2)) = mirror(iTemp)
?? Next iTemp
??
?? 'redim and preserve your array in preperation for the next order
?? ReDim Preserve m_arrOrders(12, UBound(m_arrOrders, 2) + 1)
??
?? 'display your array in the text box
?? Call DisplayArray
??
?? 'finally send the new id back to the calling sub to actually make
the order
?? Get_Set_NewOrderID = m_nextID
??

End Function

'and a sub to display your array information
Private Sub DisplayArray()

?? Dim iTemp As Integer, iTemp2 As Integer
?? Dim OrderString As String
??
?? 'loop through the array and build a string to display
?? For iTemp = 0 To UBound(m_arrOrders, 2) - 1
????? For iTemp2 = 0 To UBound(m_arrOrders)
???????? Select Case iTemp2
???????? Case LBound(m_arrOrders)
??????????? 'place the number of orders at the begining of each line
??????????? OrderString = OrderString & "Trade: " & iTemp + 1 & ",? "
& _
??????????? "ID# " & m_arrOrders(iTemp2, iTemp) & ",?? "
???????? Case UBound(m_arrOrders)
??????????? 'insert a line return character when you reach the end of
the
??????????? 'first trade
??????????? OrderString = OrderString & m_arrOrders(iTemp2, iTemp) &
vbCrLf
???????? Case Else
??????????? OrderString = OrderString & m_arrOrders(iTemp2, iTemp)
& ",?? "
???????? End Select
????? Next iTemp2
?? Next iTemp
??
?? 'display the string
?? Form1.Text1 = OrderString

End Sub







To unsubscribe from this group, send an email to:
twsapi-unsubscribe@...



Your use of Yahoo! Groups is subject to the .


Re: VB Sample Project: How To Place An Order [Code]

marinindextrader
 

Put a Text1 textbox on your form.
Put a Command1 command button on your form
Add a Simple BAS Module

Stick this in the Form: (and the rest in the Module)

Private Sub Command1_Click()

'here I have just plugged in literal values for the example
'of course you could pull these in as variables or control
properties
'such as a combo box text or what not...
Call PlaceNewOrder("BUY", 1, "ES", "FUT", "200209",
0, "", "GLOBEX", "", "MKT", 0, 0)
End Sub

Private Sub Form_Load()

'connection call
Tws1.Connect "", 7496

'initialize your module variables
Call InitVarsNewOrderMod
Text1 = "PLACE ORDER DEMO:" & vbCrLf & vbCrLf & _
"When you click Command1, a market order will fire off
for 1 Contract of September " & _
"ES. Keep clicking it and it will keep buying one at
market. Each time you click, " & _
"This box will fill with the order information stored in
your array"

End Sub


'and use this for when you log out and relog in
'you can conditionally test next valid id in the module

Private Sub Tws1_nextValidId(ByVal id As Long)

'call a module level Sub that captures the IB id on log in
Call CaptureID(id)


End Sub

'now create a private sub that will handle the order routines
'the array captures the order info and stores it for you
'good idea IMHO to internally track this info and not rely
'on IB soley

Private Sub PlaceNewOrder(ByVal action As String, ByVal quantity As
Long, _
ByVal symbol As String, ByVal secType As String, ByVal expiry As
String, _
ByVal strike As Double, ByVal right As String, ByVal exchange As
String, _
ByVal curency As String, ByVal orderType As String, ByVal lmtPrice
As Double, _
ByVal auxPrice As Double)

Dim mirror(12) As Variant 'left this as zero based for clarity

Dim newID As Long

'assign all of the arguements to the array
'not the conspicuous absence of id in the arguements

mirror(1) = action: mirror(2) = quantity: mirror(3) = symbol
mirror(4) = secType: mirror(5) = expiry: mirror(6) = strike:
mirror(7) = right: mirror(8) = exchange: mirror(9) = curency:
mirror(10) = orderType: mirror(11) = lmtPrice: mirror(12) =
auxPrice

'pass the array out to the module
newID = Get_Set_NewOrderID(mirror)


'place the order
Call Tws1.placeOrder(newID, action, quantity, symbol, secType,
expiry, strike, right, exchange, _
curency, orderType, price, auxPrice)


End Sub

'MODULE CODE STARTS HERE

Option Explicit

Private m_arrOrders() As Variant 'master array
Private m_myID As Long 'your starting point
Private m_theirID As Long 'thier starting point
Private m_nextID 'next id your going to use
Private m_incrament As Integer 'a variable to incrament by any value;
1, 5, 10 etc
'


'call on form load
Sub InitVarsNewOrderMod()

m_myID = 3030 'set your starting level here

ReDim m_arrOrders(12, 0)

m_incrament = 10 'optional to incrament by other than 1

End Sub


Sub CaptureID(ByVal theirID As Long)

'capture theirs at log on
m_theirID = theirID


End Sub

'store your order info and give an id back to the calling sub
'this is the workhorse

Function Get_Set_NewOrderID(ByVal mirror As Variant) As Long

Dim iTemp As Integer

'find the proper id; this looks a little convaluted but stare at it
'you will see that if the next available IB id is greater than
your starting
'point, it will back up one then add your incrament
'otherwise it just keeps ripping out new id's per your incrament
If m_theirID < m_myID Then
m_nextID = m_myID
m_myID = m_myID + m_incrament
Else
m_myID = m_theirID - 1 + m_incrament
m_nextID = m_myID
m_myID = m_myID + m_incrament
End If

'assign the id to the first element of the array
m_arrOrders(0, UBound(m_arrOrders, 2)) = m_nextID

'assign the mirror to the rest of the array
For iTemp = 1 To UBound(m_arrOrders)
m_arrOrders(iTemp, UBound(m_arrOrders, 2)) = mirror(iTemp)
Next iTemp

'redim and preserve your array in preperation for the next order
ReDim Preserve m_arrOrders(12, UBound(m_arrOrders, 2) + 1)

'display your array in the text box
Call DisplayArray

'finally send the new id back to the calling sub to actually make
the order
Get_Set_NewOrderID = m_nextID


End Function

'and a sub to display your array information
Private Sub DisplayArray()

Dim iTemp As Integer, iTemp2 As Integer
Dim OrderString As String

'loop through the array and build a string to display
For iTemp = 0 To UBound(m_arrOrders, 2) - 1
For iTemp2 = 0 To UBound(m_arrOrders)
Select Case iTemp2
Case LBound(m_arrOrders)
'place the number of orders at the begining of each line
OrderString = OrderString & "Trade: " & iTemp + 1 & ", "
& _
"ID# " & m_arrOrders(iTemp2, iTemp) & ", "
Case UBound(m_arrOrders)
'insert a line return character when you reach the end of
the
'first trade
OrderString = OrderString & m_arrOrders(iTemp2, iTemp) &
vbCrLf
Case Else
OrderString = OrderString & m_arrOrders(iTemp2, iTemp)
& ", "
End Select
Next iTemp2
Next iTemp

'display the string
Form1.Text1 = OrderString

End Sub


VB Sample Project: How To Place An Order

marinindextrader
 

Andrew,

Go here and download this: 1_Project_PlaceOrder.zip



To All:

I havnt spent much time at all on the placeOrder routine...that is
coming this week for me.

However here is my take on the whole affair after some quick study of
the methods.

The next valid Id call is made right after startup. If it is the
first time you have started IB for the day and have had no open
orders, the next valid id will be 0. If you have made orders the last
order id you placed will be incramented by 1...

That having been said..If you are making your first trade you can
assign anything you please as an order id...the key is to incrament
it each time a trade is made. If and when you logged off to go to
lunch for instance, then upon relogging, that is when the next valid
id comes into play. Of course your system could save the information
in the registry or whatnot and you more than likely could recall your
own last id and go from their...the bottom line is that the order
id's must ascend in relative value to one another...that is really
the crux of it...relogging in will fetch the next valid id..

All that having been said, let me share some code with you on how I
would handle incramenting the id and storing relevant order
information....

Assume your first chosen id is 3030. More on choosing id#'s later;
read footnote at bottom. Here is what happens. You place the order
and it is sent upstream to IB and they record your chosen order id.
If you relogged and captured the next valid id it would read
3031..but your not going to relog each time to fetch an id so you
have to handle the incramenting your self.

Now...you can incrament by whatever you choose...1, 5 10 etc...it is
a Long type value so you will be limited to a ceiling of
2,147,483,647...LOL shouldn't be a problem with whatever creative
method you choose to craft id's

So on to te crux of the matter....

First off I would create a module that tracks your order id and all
order information.

Second I would create a Form level sub to handle the Tws1.place order
call...


I would post the code but its easier to just download the project:



Scott
Owner TWS API Yahoo Discussion Forum


Re: twsapi: TWS_AP_VB -An addition to twsapi group

marinindextrader
 

Calm Down and wait two seconds...

My next post will have all you need brother

Scott
Owner Moderator TWS API Discussion Forum


--- In twsapi@y..., multicen2002 <no_reply@y...> wrote:
Thank you for comment
I'll wait for more FOR and against..
and if neccecery i'll remove group extention..
what ever work for benefit of all of us.

I am just saying that if ppl do not wish to share idea or
code they do not need to join. But it is more than fair
to exchange and not just take.

Yes, twsapi is kickin.. but scott can not be the only one who share.
I program for more than 5 years - database and adaptive apps.
never did data feed.. as europian ..i am expecting cooperation..
I will post my ADAPTIVE AI program and its components as I go
but please forgive me if i do not wish to share my hours of typing
and testing with ppl who do not wish to share.

I thing it is more than fair to work in a team on making better
apps.. here we go.. Its to ME more like
OPEN SOURCE just like FREEBSD

again thanx for your comment
Andrew






--- In twsapi@y..., "Bruce Hawkins" <hawkinsk001@h...> wrote:
I am not sure what you are trying to accomplish, I don't think we
need to splinter this topic.

If people want to post they will, lets keep the focus of this to
create stand alone programs, not complaining that nobody is posting
code. There already have been some posts regarding requests for
code.
You can't force people to post code through exclusion.

As far as response is concerned, on 6/21 David matched you post
for
post trying to assist you with your problem.

Needless to say Scott is the glue that holds this board together.

If I haven't made my opinion clear I think it is a mistake to
create another group.

Sincerely,

Bruce Hawkins


----- Original Message -----
From: multicen2002
To: twsapi@y...
Sent: Sunday, June 23, 2002 7:48 AM
Subject: twsapi: TWS_AP_VB -An addition to twsapi group


Hello
I just started new group based on great twsapi.
It is not any competition to existing group just extention for
VB programmers and newbies.
TWS_AP_VB will filter users and will focus on VB ONLY supporting
twsapi.
I am seting the TWS_AP_VB as membership only but everyone who
will POST a sample or partial code on twsapi for VB can join.

I hope this will seperate ppl who want to share from all others
who just want to TAKE.

Again.. THIS IS NOT A NEW GROUP.. if you just need help or
advice
twsapi is the main group for all of us.

any Q ?? contact me direct multicen2002@y...



To unsubscribe from this group, send an email to:
twsapi-unsubscribe@y...



Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.


Re: twsapi: TWS_AP_VB -An addition to twsapi group

multicen2002
 

Thank you for comment
I'll wait for more FOR and against..
and if neccecery i'll remove group extention..
what ever work for benefit of all of us.

I am just saying that if ppl do not wish to share idea or
code they do not need to join. But it is more than fair
to exchange and not just take.

Yes, twsapi is kickin.. but scott can not be the only one who share.
I program for more than 5 years - database and adaptive apps.
never did data feed.. as europian ..i am expecting cooperation..
I will post my ADAPTIVE AI program and its components as I go
but please forgive me if i do not wish to share my hours of typing
and testing with ppl who do not wish to share.

I thing it is more than fair to work in a team on making better
apps.. here we go.. Its to ME more like
OPEN SOURCE just like FREEBSD

again thanx for your comment
Andrew






--- In twsapi@y..., "Bruce Hawkins" <hawkinsk001@h...> wrote:
I am not sure what you are trying to accomplish, I don't think we
need to splinter this topic.

If people want to post they will, lets keep the focus of this to
create stand alone programs, not complaining that nobody is posting
code. There already have been some posts regarding requests for code.
You can't force people to post code through exclusion.

As far as response is concerned, on 6/21 David matched you post for
post trying to assist you with your problem.

Needless to say Scott is the glue that holds this board together.

If I haven't made my opinion clear I think it is a mistake to
create another group.

Sincerely,

Bruce Hawkins


----- Original Message -----
From: multicen2002
To: twsapi@y...
Sent: Sunday, June 23, 2002 7:48 AM
Subject: twsapi: TWS_AP_VB -An addition to twsapi group


Hello
I just started new group based on great twsapi.
It is not any competition to existing group just extention for
VB programmers and newbies.
TWS_AP_VB will filter users and will focus on VB ONLY supporting
twsapi.
I am seting the TWS_AP_VB as membership only but everyone who
will POST a sample or partial code on twsapi for VB can join.

I hope this will seperate ppl who want to share from all others
who just want to TAKE.

Again.. THIS IS NOT A NEW GROUP.. if you just need help or advice
twsapi is the main group for all of us.

any Q ?? contact me direct multicen2002@y...



To unsubscribe from this group, send an email to:
twsapi-unsubscribe@y...



Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.


Re: twsapi: TWS_AP_VB -An addition to twsapi group

 

开云体育

I am not sure what you are trying to accomplish, I don't think we need to splinter this topic.
?
If people want to post they will, lets keep the focus of this to create stand alone programs, not complaining that nobody is posting code. There already have been some posts regarding requests for code. You can't force people to post code through exclusion.
?
As far as response is concerned, on 6/21 David matched you post for post trying to assist you with your problem.
?
Needless to say Scott is the glue that holds this board together.
?
If I haven't made my opinion clear I think it is a mistake to create another group.
?
Sincerely,
?
Bruce Hawkins
?
?

----- Original Message -----
Sent: Sunday, June 23, 2002 7:48 AM
Subject: twsapi: TWS_AP_VB -An addition to twsapi group

Hello
I just started new group based on great twsapi.
It is not any competition to existing group just extention for
VB programmers and newbies.
TWS_AP_VB will filter users and will focus on VB ONLY supporting
twsapi.
I am seting the TWS_AP_VB as membership only but everyone who
will POST a sample or partial code on twsapi for VB can join.

I hope this will seperate ppl who want to share from all others
who just want to TAKE.

Again.. THIS IS NOT A NEW GROUP.. if you just need help or advice
twsapi is the main group for all of us.

any Q ?? contact me direct multicen2002@...



To unsubscribe from this group, send an email to:
twsapi-unsubscribe@...



Your use of Yahoo! Groups is subject to the .


TWS_AP_VB -An addition to twsapi group

multicen2002
 

Hello
I just started new group based on great twsapi.
It is not any competition to existing group just extention for
VB programmers and newbies.
TWS_AP_VB will filter users and will focus on VB ONLY supporting
twsapi.
I am seting the TWS_AP_VB as membership only but everyone who
will POST a sample or partial code on twsapi for VB can join.

I hope this will seperate ppl who want to share from all others
who just want to TAKE.

Again.. THIS IS NOT A NEW GROUP.. if you just need help or advice
twsapi is the main group for all of us.

any Q ?? contact me direct multicen2002@...


Re: twsapi: TWS API VB files for newbies - 1st POST

 

开云体育

Thank you very much Scott for taking the time and being so open.
?
Bruce

----- Original Message -----
Sent: Sunday, June 23, 2002 6:46 AM
Subject: Re: twsapi: TWS API VB files for newbies - 1st POST

Agreed,

I try and post code every week...
I put up bits and pieces and modules in the Files section
all the time...

As my program develops I will be shareing what ever it is I am
working on at the time

Check out the files section:



I am now just begining on the order handling routines and within a
week or two I will begin to post what I come up with

Any and all are certainly encouraged to share...

At the same time..those who don't are just as welcome to NOT post or
NOT respond...

Each of us will get or give differently...some alot and some none...

All is good

Scott
Yahoo TWS API



--- In twsapi@y..., multicen2002 wrote:
>
>
> POST your code, too
> and look under FILE AREA
> TWS API - Let's share VB code NR-1
>
> Somebody need to break an ace.
> just little somethink to play with..
>
> Andrew
>
>
>
>
> --- In twsapi@y..., "Bruce Hawkins" wrote:
> > Yes,? I agree any code examples that can be posted are greatly
> appreciated. Its frustrating when you
> >? know the info is out there but you can't get to it.
> >
> > I realize some people are trying to come up with a program to
> market to people who don't want to invest
> > the time to build there own.
> >
> > But I can't imagine all 200 plus members of this board are going
to
> do that, so what would it hurt to throw
> > out a few scraps of code? The people struggling with? creating
> there own programs are not the competition,
> > I could care less about marketing a standalone for TWS I just
want
> a program that I can tweak to my satisfaction.
> >
> > Thank you Scott for your effort and postings of files.
> >
> > Sincerely,
> >
> > Bruce
> >?? ----- Original Message -----
> >?? From: multicen2002
> >?? To: twsapi@y...
> >?? Sent: Saturday, June 22, 2002 4:01 PM
> >?? Subject: twsapi: TWS API VB files for newbies - 1st POST
> >
> >
> >?? 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
> >
> >
> >???????? Yahoo! Groups Sponsor
> >?????????????? ADVERTISEMENT
> >?????????????
> >???????
> >???????
> >
> >?? To unsubscribe from this group, send an email to:
> >?? twsapi-unsubscribe@y...
> >
> >
> >
> >?? Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service.



To unsubscribe from this group, send an email to:
twsapi-unsubscribe@...



Your use of Yahoo! Groups is subject to the .


Re: twsapi: Re: How do you?+ TWS API VB files for newbies - 1st POST

 

开云体育

All I can offer is this post from the IB board from Jaba,
?
?

Posted on Sunday, May 19, 2002 - 03:30 pm: ??

ok, since I see people are requesting this over, and over again... I put together a ridiculously simple VB Project. It will use ActiveX API to connect to the TWS, then request and display quotes for NQ contract. It's downloadable from Visual Basic Project directory, URL at the bottom of this message.

I hope this helps
Jaba


----
?
?
Bruce
?
?
?
?
?
?
?
?
----- Original Message -----
Sent: Sunday, June 23, 2002 5:57 AM
Subject: twsapi: Re: How do you?+ TWS API VB files for newbies - 1st POST

will you add a code line to your post ??
or sample to file area?? It will take you extra 2 more minutes.
Thanx


Andrew



--- In twsapi@y..., "qnolte" <q@n...> wrote:
> Use the "nextValidId" event to get a valid Id to use each time.
>
> --- In twsapi@y..., "Bruce Hawkins" <hawkinsk001@h...> wrote:
> > How do I get? Tws.ocx on to a new form?
> >
> > I tried the following on the Demo and it worked except I have to
> keep increasing the order ID to place more orders.
> >
> > Call Tws1.placeOrder(3030, "BUY", 1, "ES", "FUT", "200209", _
> > 0, "", "GLOBEX", "", "LMT", 1000.00, 0)
> >
> > How do you work around this?
> >
> > Any input appreciated,
> >
> > Bruce
> >
> > P.S. The form I am using now (which was a simple Demo I got from
> Jaba) I beleive has an earlier ver. of Tws.ocx



To unsubscribe from this group, send an email to:
twsapi-unsubscribe@...



Your use of Yahoo! Groups is subject to the .


Re: Working on polling any good ideas?

marinindextrader
 

GoldSilverMana,

Let me know if you find a polling thingy...I vaguely recall that when
I first set the group up that Polling was an available option...

However it also said that if I enabled it, our email address would
have to be made public...so I opted against the idea...

Now I have gone back into the maintenance section and can't find a
refrence at all to a polling option....

I will delve a tad deeper into the Yahoo polling and see what I can
find...

I like the idea...just don't know how to go about it at this point

Let us know what you come up with

Scott










--- In twsapi@y..., "goldensilvermana" <kybryan@c...> wrote:
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.


Re: twsapi: TWS API VB files for newbies - 1st POST

marinindextrader
 

Agreed,

I try and post code every week...
I put up bits and pieces and modules in the Files section
all the time...

As my program develops I will be shareing what ever it is I am
working on at the time

Check out the files section:



I am now just begining on the order handling routines and within a
week or two I will begin to post what I come up with

Any and all are certainly encouraged to share...

At the same time..those who don't are just as welcome to NOT post or
NOT respond...

Each of us will get or give differently...some alot and some none...

All is good

Scott
Yahoo TWS API



--- In twsapi@y..., multicen2002 <no_reply@y...> wrote:


POST your code, too
and look under FILE AREA
TWS API - Let's share VB code NR-1

Somebody need to break an ace.
just little somethink to play with..

Andrew




--- In twsapi@y..., "Bruce Hawkins" <hawkinsk001@h...> wrote:
Yes, I agree any code examples that can be posted are greatly
appreciated. Its frustrating when you
know the info is out there but you can't get to it.

I realize some people are trying to come up with a program to
market to people who don't want to invest
the time to build there own.

But I can't imagine all 200 plus members of this board are going
to
do that, so what would it hurt to throw
out a few scraps of code? The people struggling with creating
there own programs are not the competition,
I could care less about marketing a standalone for TWS I just
want
a program that I can tweak to my satisfaction.

Thank you Scott for your effort and postings of files.

Sincerely,

Bruce
----- Original Message -----
From: multicen2002
To: twsapi@y...
Sent: Saturday, June 22, 2002 4:01 PM
Subject: twsapi: TWS API VB files for newbies - 1st POST


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


Yahoo! Groups Sponsor
ADVERTISEMENT




To unsubscribe from this group, send an email to:
twsapi-unsubscribe@y...



Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.


Re: twsapi: TWS API VB files for newbies - 1st POST

multicen2002
 

POST your code, too
and look under FILE AREA
TWS API - Let's share VB code NR-1

Somebody need to break an ace.
just little somethink to play with..

Andrew




--- In twsapi@y..., "Bruce Hawkins" <hawkinsk001@h...> wrote:
Yes, I agree any code examples that can be posted are greatly
appreciated. Its frustrating when you
know the info is out there but you can't get to it.

I realize some people are trying to come up with a program to
market to people who don't want to invest
the time to build there own.

But I can't imagine all 200 plus members of this board are going to
do that, so what would it hurt to throw
out a few scraps of code? The people struggling with creating
there own programs are not the competition,
I could care less about marketing a standalone for TWS I just want
a program that I can tweak to my satisfaction.

Thank you Scott for your effort and postings of files.

Sincerely,

Bruce
----- Original Message -----
From: multicen2002
To: twsapi@y...
Sent: Saturday, June 22, 2002 4:01 PM
Subject: twsapi: TWS API VB files for newbies - 1st POST


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


Yahoo! Groups Sponsor
ADVERTISEMENT




To unsubscribe from this group, send an email to:
twsapi-unsubscribe@y...



Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.


Re: How do you?+ TWS API VB files for newbies - 1st POST

multicen2002
 

will you add a code line to your post ??
or sample to file area?? It will take you extra 2 more minutes.
Thanx


Andrew

--- In twsapi@y..., "qnolte" <q@n...> wrote:
Use the "nextValidId" event to get a valid Id to use each time.

--- In twsapi@y..., "Bruce Hawkins" <hawkinsk001@h...> wrote:
How do I get Tws.ocx on to a new form?

I tried the following on the Demo and it worked except I have to
keep increasing the order ID to place more orders.

Call Tws1.placeOrder(3030, "BUY", 1, "ES", "FUT", "200209", _
0, "", "GLOBEX", "", "LMT", 1000.00, 0)

How do you work around this?

Any input appreciated,

Bruce

P.S. The form I am using now (which was a simple Demo I got from
Jaba) I beleive has an earlier ver. of Tws.ocx


Re: How do you?

qnolte
 

Use the "nextValidId" event to get a valid Id to use each time.

--- In twsapi@y..., "Bruce Hawkins" <hawkinsk001@h...> wrote:
How do I get Tws.ocx on to a new form?

I tried the following on the Demo and it worked except I have to
keep increasing the order ID to place more orders.

Call Tws1.placeOrder(3030, "BUY", 1, "ES", "FUT", "200209", _
0, "", "GLOBEX", "", "LMT", 1000.00, 0)

How do you work around this?

Any input appreciated,

Bruce

P.S. The form I am using now (which was a simple Demo I got from
Jaba) I beleive has an earlier ver. of Tws.ocx


How do you?

 

开云体育

How do I get? Tws.ocx on to a new form?
?
I tried the?following on the Demo and it worked except I have to keep increasing the order ID to place more orders.
?
Call Tws1.placeOrder(3030, "BUY", 1, "ES", "FUT", "200209", _
0, "", "GLOBEX", "", "LMT", 1000.00, 0)
?
How do you work around this?
?
Any input appreciated,
?
Bruce
?
P.S. The form I am using now (which was a simple Demo I got from Jaba) I beleive has an earlier ver. of Tws.ocx


Re: twsapi: TWS API VB files for newbies - 1st POST

 

开云体育

Yes,? I agree any code examples that can be posted are greatly appreciated. Its frustrating when you
?know the info is out there but you can't get to it.
?
I realize some people are trying to come up with a program to market to people who don't want to invest
the time to build there own.
?
But I can't imagine all 200 plus members of this board are going to do that, so what would it hurt to throw
out a few scraps of code? The people struggling with? creating there own programs are not the competition,
I could care less about marketing a standalone for TWS I just want a program that I can tweak to my satisfaction.
?
Thank you Scott for your effort and postings of files.
?
Sincerely,
?
Bruce

----- Original Message -----
Sent: Saturday, June 22, 2002 4:01 PM
Subject: twsapi: TWS API VB files for newbies - 1st POST

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



To unsubscribe from this group, send an email to:
twsapi-unsubscribe@...



Your use of Yahoo! Groups is subject to the .


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