twsapi: Market Making App
} Hello. I'm a seasoned vb programmer and I've been trading with IB
} for a long while. I'm thinking about writing a fully automated
} Market Making application that posts bids/asks automatically. I have
} to admit, although I would have no problem writing the software
} (which I don't mind sharing with everyone), I don't think I know
} enough about market making. In general, when I try to post a test 10-
} share sell/buy on a NASDAQ stock inside the bid/ask spread, it
} doesn't seem to show up on the Bid/Ask. Is this because I'm not
} posting lots? or is there some other restriction. I would love to
} hear from people with similar interest, and get a move on this
} project if it is feasible.
}
} Cheers,
}
} JS
Glad to hear you consider yourself to be `seasoned'. :-)
NASDAQ doesn't show orders less than 100 shares. Try Island and the Island
book if you want to play with tiny trades.
Richard
|
Don't change the board
Please do not confuse everyone with posting another
board or splitting it off. Take care.
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
|
|
twsapi: Re: VB Sample Project: How To Place An Order
4
Scott,
the problem with your code is that if you put orders
through? one after the other, TWS will complain about the duplicate order
as they will be (the orderid i mean) separated by 1 to 2 seconds(numbers
apart)
another way is to
Public gblOrderId&()
DIM IC%
?
ReDim Preserve gblOrderId(IC)
IC = IC + 9
gblOrderId(IC)
= DatePart("YYYY", Date) & DatePart("M", Date) & DatePart("Y", Date)
& IC
?
This way you know the day of the year and all orders of that
day, and you cancel any orders that not filled through the gblOrderId() array.
Of course, you would need to monitor it through the OrderStatus
event.
?
Thanks
David
PS Andrew your comments about sharing and not sharing are
disturbing...
when I helped you i did know that you had something to offer
(AI).
Just go with the flow... you may enjoy it. I would not mind
seeing your bit on AI anyway.
|
twsapi: TWS API VB - GONE..
cheer up Andrew...
you have got the guts to say sorry...
That's a lot, at least in my eyes.
David
|
TWS API VB - GONE..
hi..
I have read your E-mails.. I was wrong..
We do not need another group..
I didn't mean to offend anyone...I'm sorry if I have...
I'm with you .. TWS API for VB is gone now..
Andrew
|
twsapi: TWS_AP_VB -An addition to twsapi group
4
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
|
twsapi: Re: VB Sample Project: BEER TIME
I am going to have a beer now.
Thanks to whoever brought up the whole order id question....
I needed to start working on this and his question forced my day to
focus on and understand the order process...
Scott <----------tossing back a Boddingtion Ale
Service.
|
VB Sample Project: How To Place An Order
2
Andrew,
Go here and download this: 1_Project_PlaceOrder.zip
http://groups.yahoo.com/group/twsapi/files/
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:
http://groups.yahoo.com/group/twsapi/files/1_Project_PlaceOrder.zip
Scott
Owner TWS API Yahoo Discussion Forum
|
twsapi: Re: VB Sample Project: How To Place An Order [Code]
Thanks once again Scott,
?
Bruce
|
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@...
|
twsapi: TWS API VB files for newbies - 1st POST
4
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
|
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,
|
Working on polling any good ideas?
2
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.
|
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
|
How do you?
2
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
|
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
|
VB: Code Sample, Level Intermediate....Dynamic ReqMarket Array Management
The following code has been posted as a BAS module in the files
section:
http://groups.yahoo.com/group/twsapi/files/
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
' 'http://groups.yahoo.com/group/twsapi/files/
' 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
|
twsapi: Demo Server Question
2
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:
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
|
Please help - VB code --- SEE command4_click
3
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
|