Placing an order with the out-of-the box API:
start TWS PAPERTRADING account
configure->api check "Enable ActiveX and Socket Clients"
java -jar jtsclient.jar
Market data (again):
hit the "Req Mkt Data" button, fill out these fields:
Symbol: ES
Security Type: FUT
Expiry: 20070315
Exchange: GLOBEX
Primary Exchange: GLOBEX
Local Symbol: ESH7
Leave the other fields alone
Hit "OK."
Buy (limit):
Hit "Place Order" on "Sample"
In the Order Info section, set the limit price >= the ask price:
Lmt Price 1420.25
hit "OK"
An API tab will appear on TWS
If the order is filled, A position count will show
On "Sample" there will be some execution details in the middle window
Sell(market):
Hit "Place Order" on "Sample"
In the order info section
change BUY to SELL in the Action field
change LMT to MKT in the Order Type field
Hit "OK" on "Sample"
The TWS position counter should have gone to zero
and there should be execution details in the middle window.
That's how easy it is with the API. But what do those things do in the code. Looking in the 'java' directory under IBJts, wherever you dumped the '.jar' file, you'll see two directories, 'TestJavaClient' and 'com'. 'TestJavaClient has the high level code, 'com' has the low level code.
In TestJavaClient/SampleFrame.java, search for onReqMktData; you'll see where the button is created, then later, in the same file, you'll see the handler that is invoked when the button is pressed. That handler invokes m_orderDlg.show, where the contract details are entered by the user; then, m_client.reqMktData() is invoked. That method is found in IBJts/java/com/ib/client/EClientSocket.java (search for reqMktData). There you'll see that the data that was entered into the form is extracted and sent, string by string, using the 'send' method -- 'send' is in the same file and is an overloaded method -- if it gets an integer argument, the argument is stringized before being "sent." So, TWS gets a sequence of strings from the API. Later today, I'll connect and find out what happens if I disconnect from the internet while doing some of these things.
Does anybody know of a flow graph generator for Java? Does eclipse offer anything that might be useful for doing either static or dynamic analyis of a Java app?