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
automated login
Michel
Hi,
Does somebody know some way to run the TWS application unattended? What I need is: 1- Avoid the login screen, passing parameters (UserName and Password) from my calling application. 2- Respond to the message window asking 'Accept incoming connection attempt?' when I connect to the local server. This is because I'm writting my own program (Visual Basic using TWS ActiveX) which allways runs in the background and want it to automatically launch TWS few minutes before markets open and perform some automated tasks when I'm not at home. I've tried to launch TWS from my application with a call to 'ShellExecute', passing parameters as 'username' or 'user' without success. I always get the login screen blank because I ignore if TWS accepts such parameters and how they must be coded (I think this must be possible because in the web demo, the login screen appears whith such fields pre-filled with 'edemo' and 'demouser'). Perhaps in some 'ini' file? (I've not found any section related to username and password). Thanks for any help. Michel. |
Re: twsapi: How to make the Java API work?
Michel
开云体育I dont
know of Java, but something looks strange: you connect to "gw4.ibllc.com:4000"
which is the IB server on the Internet.
Dont
have you to connect to the local server (as in VB):
"127.0.0.1:7496"?
?
Michel.
[Michel]??-----Mensaje original----- De: philipyeh [mailto:philipyeh@...] Enviado el: lunes, 01 de julio de 2002 4:53 Para: twsapi@... Asunto: twsapi: How to make the Java API work? I am a new user of the TWS Java API. |
Re: How to make the Java API work?
marinindextrader
Not hip to Java, But It looks as if....
..... ..... I dont code in Java but it seems as if you havnt made a regMktData call...or am I missing something? Further I have been unsuccesful passing anything other than variable values through the reqMkt... It appears as if your reqMkt object is expecting an object itself as as an arguement>>> object m_contract...I have tried passing arrays as arguements and get rejected... And, the symbol appears incorrect: ESU2 should be ES You dont need anthing in the field .right "C" should be "" You dont need anything in the field currencey "USD" should be "" Here is a literal example of reqMkt call in VB if this helps: symbol = "ES" secType = "FUT" expiry = "200209" strike = 0 TWSright = "" exchange = "GLOBEX" curency = "" Tws1.reqMktData id, symbol, secType, expiry, strike, TWSright, exchange, curency --- In twsapi@y..., "philipyeh" <philipyeh@y...> wrote: I am a new user of the TWS Java API.(field) + "=" + price);(field) + "=" + size);marketPrice=" + marketPrice + ", marketValue=" + marketValue); |
Re: twsapi: Re: order IDs
Richard Foulk
Let's try to remember that the API is still beta. So if it doesn't
work propperly or reasonably or logically -- then please report it to the IB folks so it can be fixed. Don't just work around it in strange on crazy ways. This is a great facility. Let's do our part to make it better. Richard } I think it should be possible to get the IDs from TWS..... } When TWS logs in it produces a list with standing orders. } Maybe also from a database...? } } Best would be if a ticker could be entered in a 3rd party program. } That program checks if TWS already has that ticker active. } If not then it creates a new id. } If kinda afraid of what happens if you add/delete something directly } from TWS and after that start the program. } Big chance it resubmits the order. } Or am I overlooking something? } } } } --- In twsapi@y..., "Marcus Jellinghaus" <Marcus_Jellinghaus@G...> } wrote: } > I store everything in a database, including the order details and } the order } > id. } > When you have a Limit order which doesn?t get executed, and you } disconnect, } > close TWS, open TWS, and reconnect through the API to TWS, then TWS } forget?s } > the API order ID. } > } > So I decided that I cancel all open orders manually in TWS and then } send all } > open orders again from my programm to TWS. } > } > Marcus } > } > -----Ursprungliche Nachricht----- } > Von: kxlin99 [mailto:klin@p...] } > Gesendet: Sunday, June 30, 2002 1:49 AM } > An: twsapi@y... } > Betreff: twsapi: Re: order IDs } > } > } > Hi there - } > } > I would like to know how you manage order ids from session to } > session. I meant you place an order and store the order id in your } > table, what if the TWS/Windows crashed, and you need reboot the } > machine, how do you change/cancel your open orders? Thanks } > } > --- In twsapi@y..., Robert Carey <rcarey1@o...> wrote: } > > You have to keep track of your trading over time. You have to keep } > track of what you or your Automated Trading System is doing. You } need } > to store what was done, when, and why. } > > Besides, the IRS is coming on 4/15/2003 for sure, if not sooner. } > > That means storage of your trading events on a hard drive and with } > backup. } > > I choose to use the Microsoft .mdb format and access it from VB } > with DAO 3.6. } > > There is a table of trades. It has an entry order number and an } > exit order number in each record. There are lots of other fields to } > keep track of when, where, and why. } > > A recordset RS.TradesEnter is created indexed on the } > openOrderNumber. } > > A recordset RS.TradesExit is created indexed on the } exitOrderNumber. } > > They both point to the same table. } > > } > > Creating a unique entry order number is as follows. } > > RS.TradesEnter.MoveLast } > > thisEntryOrderNumber = RS.TradesEnter![openOrderNumber] + 2 } > > thisExitOrderNumber = thisEntryOrderNumber + 1 } > > Now create a new trade record. } > > RS.TradesEnter.AddNew } > > RS.TradesEnter![openOrderNumber] = thisEntryOrderNumber } > > RS.TradesEnter![closeOrderNumber] = thisExitOrderNumber } > > RS.TradesEnter.Update } > > } > > When a fill arrives, whether partial of full, RS.TradesEnter } > updates the when,where,why fields. } > > When you or your ATS decides to close a position, } > RS.TradesExit "seeks" this ExitOrderNumber and updates the when, } > where, why fields. } > > That should keep you and the IRS happy. } > > Comments? } > > RCarey |
twsapi: Re: order IDs
ruffstuff123
I think it should be possible to get the IDs from TWS.....
When TWS logs in it produces a list with standing orders. Maybe also from a database...? Best would be if a ticker could be entered in a 3rd party program. That program checks if TWS already has that ticker active. If not then it creates a new id. If kinda afraid of what happens if you add/delete something directly from TWS and after that start the program. Big chance it resubmits the order. Or am I overlooking something? --- In twsapi@y..., "Marcus Jellinghaus" <Marcus_Jellinghaus@G...> wrote: I store everything in a database, including the order details andthe order id.disconnect, close TWS, open TWS, and reconnect through the API to TWS, then TWSforget?s the API order ID.send all open orders again from my programm to TWS.need to store what was done, when, and why.exitOrderNumber.Besides, the IRS is coming on 4/15/2003 for sure, if not sooner.backup. They both point to the same table.updates the when,where,why fields. |
How to make the Java API work?
philipyeh
I am a new user of the TWS Java API.
I wrote a test program to test the reqMktData() method. But I can not get any ticks data. What's problem in my program? Could anybody help me? Below is my test java program: import com.ib.client.*; public class ATMClient implements EWrapper { static final int BID_SIZE = 0; static final int BID = 1; static final int ASK = 2; static final int ASK_SIZE = 3; static final int LAST = 4; static final int LAST_SIZE = 5; EClientSocket m_client = new EClientSocket(this); int m_id = 100000; int o_id = 200000; public static void main (String[] args) { ATMClient myapp = new ATMClient(); myapp.start("gw4.ibllc.com", "4000"); } public void start(String host, String port) { m_client.eConnect(host, Integer.parseInt(port)); System.out.println("connect ok!"); Contract m_contract = new Contract(); m_contract.symbol = "ESU2"; m_contract.secType = "FUT"; m_contract.expiry = "200209"; m_contract.strike = 0.0; m_contract.right = "C"; m_contract.exchange = "GLOBEX"; m_contract.currency = "USD"; m_client.reqMktData(m_id, m_contract); } public void tickPrice( int tickerId, int field, double price) { // received price tick System.out.println("id=" + tickerId + " " + getField(field) + "=" + price); } public void tickSize( int tickerId, int field, int size) { // received size tick System.out.println("id=" + tickerId + " " + getField(field) + "=" + size); } public void orderStatus(int orderId, String status, int filled, int remaining, double price, int permId) { // received order status System.out.println("id=" + orderId + " status=" + status + " filled=" + filled + " remaining=" + remaining + " price=" + price + " permId=" + permId); // make sure id for next order is at least orderId+1 ++o_id; } public void openOrder( int orderId, Contract contract, Order order) { // received open order System.out.println( "id=" + orderId + " " + order.action + " " + order.quantity + " " + contract.symbol); } public void nextValidId(int orderId) { // received next valid order id o_id = orderId; } public void error(String str) { // received error System.out.println("*** Error: " + str); } public void connectionClosed() { System.out.println("Connection Closed"); } private String getField(int tickType) { switch (tickType) { case BID_SIZE: return "bidSize"; case BID: return "bidPrice"; case ASK: return "askPrice"; case ASK_SIZE: return "askSize"; case LAST: return "lastPrice"; case LAST_SIZE: return "lastSize"; default: return "unknown"; } } public void updateAccountValue(String key,String value,String currency) { System.out.println("key=" + key + ", value=" + value + ", currency=" + currency); } public void updatePortfolio(Contract contract, int position, double marketPrice, double marketValue) { System.out.println("position=" + position + ", marketPrice=" + marketPrice + ", marketValue=" + marketValue); } public void updateAccountTime(String timeStamp) { System.out.println("timeStamp=" + timeStamp); } } Thanks. Philip Yeh. |
Re: Modifying an order & testing
tripack44
--- In twsapi@y..., ruffstuff123 <no_reply@y...> wrote:
The only thing that I'm really missing is a trailing stop.To modify an order, just reenter the order with the new price and contracts via the .placeorder method using the same TWS order id # (argument 1 in the "placeorder" method). Trailing stops take a bit of proper organization to work out correctly. You need to keep track of entry price, whether it is a buy or sell, MaxPnL for the open position and the Trail Stop amount. You use live data to figure the MaxPnL. For a long position the Trail stop price = Entry Price - MaxPnL. Those are the basics of setting up a trailing stop. Whether you choose to hold that stop on your machine or to transmit each new stop price to IB is a personal choice. You can cancel untransmitted stops easier than transmitted ones and know that you aren't going to be filled. Globex held stops will probably fill at a better price than local system held stops. Some of the complexities involved with trailing stops include: Multiple entries at different times with multiple entry prices. Partial exits and reentries. Formating your stop orders so that they are within the minimum tick range expected by the exchange you trade on. This is particularly important when you consider partial fills at different prices that may create an average price that is outside the minimum tick of your exchange. Doing a trailing stop for multiple symbols pretty much requires you to code so that multiple instances of the code can be created for each symbol you trade (class module). I'm not ambitious enough to create sample code for this, but hopefully this short discussion of the issues will help some who are trying to figure it out. |
Re: How to get - Account Number
tripack44
--- In twsapi@y..., multicen2002 <no_reply@y...> wrote:
I have 2 accounts.This issue may be more complex than just parsing the acct # from the title bar because you don't know which socket # is associated with which account #. But if you want to find all the windows title bars that contain the words "Interactive Brokers Trader Workstation" then the following VB source code from Karl Peterson will get you started. Web Site: Sample code: |
Re: twsapi: Trader Guard - ES NQ futures ready app.
tripack44
The twsapi web site on yahoo groups is:
I read all my mail from yahoo groups online. That way I can skip reading for a couple of weeks and then browse at my leisure. You can change your group settings to read your mail online. --- In twsapi@y..., "Shukrainternationals" <shukrainternationals@c...> wrote: Can anybody tell me what is the web site address of twsapi group?(NOT the email address). Thanks. |
AW: twsapi: Re: order IDs
开云体育That
is the reason why I do not use reqOpenOrders or
reqExecutions.
?
I just
request the portfolio/account data and check if "my accounting" gives the same
numbers as the values that I get from TWS.
I
found a problem with reqAccountData: If you request it several times, it doesn?t
work anymore.
?
I did
not use the permID, I have near to no problems with the OrderID that?I
provide when I post an order since I use the NextValidID that I get when I
connect to TWS. I store that ID and increase it every time I place an
order.
|
twsapi: Re: order IDs
kxlin99
Hi Marcus -
Have you ever tried reqopenorders and openorder1/openorder2? It seems to me they behave strangely. 1. openorder1/openorder2 only fire once after reconnect 2. only one open order id is returned no matter how many open orders you have 3. open order id changed upon reqopenorders called Do you know what the permID for ? Thanks |
Re: stockwatchpro
ruffstuff123
--- In twsapi@y..., "gugute01" <gugute01@y...> wrote:
Found this on silicon investor IB board. I tried stockwatchproalong with IB today, works pretty good. I wish IB removed BEST routing Is it possible to make a trailing stop systm with that formula language??? Orders can be initiated from Stock Watch Pro as follows: |
AW: twsapi: Re: order IDs
开云体育Hi
David,
?
I
use? a access database and MS-Access, which is included with MS-Office Pro.
I program in Access-VisualBasic for applications.
?
Normally, I get any change to the orderstatus immidiatly and store it
immidiatly in the database.
?
The
situation descriped below is just for the rare case that one application crashes
or the API connection breaks.
?
Marcus
|
Re: twsapi: Re: order IDs
David
开云体育I do not use that many orders but your idea, Marcus, is a
fanatastic way to have a good, even though delayed, control of your orders.
Do you use any special db or just free dbjet
engine?
well done.
David
|
Re: twsapi: Modifying an order & testing
ruffstuff123
--- In twsapi@y..., "marinindextrader" <marinindextrader@y...> wrote:
There is nothing in the files section that specifically deals withfrom now it willWow! Can't hardly wait :) As to your trailing stop question:(whole explanation is about long postions) IMO serverbased orders are always best (method B/C)because: - Method A can be dangerous when loosing a connection. (client/ISP down or internet overload with 11 sept like events) - Serverbased orders have an other advantage IMO Say there are 2 traders with a stop on MSFT. TraderA=client based TraderB=server based TraderB is better of because: a] The server 'knows' first about a stop being hit b] The server order is older then the the order that TraderA submits just after the stop is hit. And assuming the orders have the same stop the server will execute the one that is the oldest first. This can be an advantage when there is low volume or sudden declines. Stop system..... I use an 'advanced' stop system (manually) I use a adaptive stop system. Lemme explain. a] I enter the market with a 5% stop b] Calculate the expect price target (usually a res line) c] The stop at the resline is 2% So the stop gets gradually smaller as the stock rises. Market vs limit orders. I only use market orders as a last resort. In most cases a stock just pull back. No critical situation of any kind. Say from $100 to $98 Sell at $97.50 would be a 'fair' trade. But what if the next bid is absurtly low? You know the $0.06 kinda orders you see now and then.... If I get hit by such an trade I rather didn't use my stop. You won't have that problem with high volume stocks like MSFT that has 1000's of traders at each price. But with lower volume stocks before/after markets hours this can be a real danger. So we need to place a sell at the next bid (minus a few cents) If the next bid isn't realistic just place an higher sell order. that is ready to execute. You track the security price on your side,then if and when certain price events occur, you do one of two things:(an event occured that triggered your modified order to send).stopped out), or you cancel the order and resubmit a new order with yournew parameters based on a price action event. |
another java dev here, UNIX/Linux questions...
Hello everyone, I'm another professional Java developer more than
willing to lend a hand if anyone needs it. I also have more than 5 years of Java dev experience, on all levels but mostly involving UI development, and especially swing...and data vis. :) Also have a good bit of C++ experience. I'm curious about two things as I get started on my own Java project involving IB and their API. First, I think I'm understanding that you have to have TWS running locally and that the socket client checkbox must be checked in order to use the API. Is this correct? It seems it must be true because the API does not offer any login support. Second, does anyone have experience using the Linux/UNIX client or the Linux/UNIX APIs? Love to hear about any potential problems there. Thanks! Randy |
AW: twsapi: Re: order IDs
I store everything in a database, including the order details and the order
id. When you have a Limit order which doesn?t get executed, and you disconnect, close TWS, open TWS, and reconnect through the API to TWS, then TWS forget?s the API order ID. So I decided that I cancel all open orders manually in TWS and then send all open orders again from my programm to TWS. Marcus -----Ursprungliche Nachricht----- Von: kxlin99 [mailto:klin@...] Gesendet: Sunday, June 30, 2002 1:49 AM An: twsapi@... Betreff: twsapi: Re: order IDs Hi there - I would like to know how you manage order ids from session to session. I meant you place an order and store the order id in your table, what if the TWS/Windows crashed, and you need reboot the machine, how do you change/cancel your open orders? Thanks --- In twsapi@y..., Robert Carey <rcarey1@o...> wrote: You have to keep track of your trading over time. You have to keeptrack of what you or your Automated Trading System is doing. You need to store what was done, when, and why. Besides, the IRS is coming on 4/15/2003 for sure, if not sooner.backup. I choose to use the Microsoft .mdb format and access it from VBwith DAO 3.6. There is a table of trades. It has an entry order number and anexit order number in each record. There are lots of other fields to keep track of when, where, and why. A recordset RS.TradesEnter is created indexed on theopenOrderNumber. A recordset RS.TradesExit is created indexed on the exitOrderNumber.updates the when,where,why fields. When you or your ATS decides to close a position,RS.TradesExit "seeks" this ExitOrderNumber and updates the when, where, why fields. That should keep you and the IRS happy. Yahoo! Groups Sponsor ADVERTISEMENT To unsubscribe from this group, send an email to: twsapi-unsubscribe@... Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. |
Re: order IDs
kxlin99
Hi there -
I would like to know how you manage order ids from session to session. I meant you place an order and store the order id in your table, what if the TWS/Windows crashed, and you need reboot the machine, how do you change/cancel your open orders? Thanks --- In twsapi@y..., Robert Carey <rcarey1@o...> wrote: You have to keep track of your trading over time. You have to keeptrack of what you or your Automated Trading System is doing. You need to store what was done, when, and why. Besides, the IRS is coming on 4/15/2003 for sure, if not sooner.backup. I choose to use the Microsoft .mdb format and access it from VBwith DAO 3.6. There is a table of trades. It has an entry order number and anexit order number in each record. There are lots of other fields to keep track of when, where, and why. A recordset RS.TradesEnter is created indexed on theopenOrderNumber. A recordset RS.TradesExit is created indexed on the exitOrderNumber.updates the when,where,why fields. When you or your ATS decides to close a position,RS.TradesExit "seeks" this ExitOrderNumber and updates the when, where, why fields. That should keep you and the IRS happy. |
Tickers & 40 More Tickers....Someone Try This....See If It Works
marinindextrader
I wonder....wanting of more Ticker's....
[in regards to the 40 ticker limit to API users] If one logged on through multiple instance of the API moduel via an array or segragate naming could they pull more than 40 or multiples of 40? I will bet ya dozen Krispy Kreme your good to go.... Dim iTemp As Integer For iTemp = 0 To UBound(TWS1) TWS1(iTemp).connect "", 7496 + iTemp Next iTemp If id <= 39 Then TWS1(0).reqMktData(yada yada) Else If id > 39 And id <= 79 Then TWS1(1).reqMktData(yada yada) End If makes one wonder doesn't it? If anyone has time to burn give this a rip and see if it works...I will get around to it eventually but I am focused elswhere... Scott Yhoo TWSAPI |
to navigate to use esc to dismiss