Hello, IB API newbie here so don't be too harsh...Please... I have a system that generate buy and sell limit orders on both side of the order book and does a lot of cancel/replace... That part is fine... Limit orders update fine... The problem is I don't know how to request if one of the 2 orders have been filled. I use an id generator for orders so I obviously don't know what the ids are for my 2 open orders and I want to enter new orders as soon as one is filled. What is the easiest way to know what are your position in your portfolio? Is their a way to just get your current position on IB portfolio without having to get the order id. Also, if someone wants to share a well made id generator , it would be great 'cause mine is quite crooked... Thanks a lot and good trade.
The best way to generate an ID is have IB do it for you... when you connect to the socket IB will call a function on your eWrapper called next valid id: Function virtual void nextValidId(OrderID orderId) Parameters orderId - The next available order ID received from TWS upon connection. Increment all successive orders by one based on this ID. Notes This function is called after a successful connection to TWS. If you want an example for this, checkout http://code.google.com/p/tradelink/source/browse/trunk/BrokerServers/TWSServer/TWS_TLWM.cpp SendOrder function on line 136 nextValidid function on line 234 The other thing you can do if you don't want to track IDs, is you can do a reqAccountUpdates, which will then call updateAccountValue and updatePortfolio whenever your positions change... OR you can just handle orderStatus and look for the 'Filled' status id. http://individuals.interactivebrokers.com/php/apiguide/apiguide.htm
If your trading frequently you will run into problems with excel/DDE positions, there is latency and is too unstable for most high frequency trading apps.
Thank you both for your help. Tradelink, I believe you're refering to java API when you talk about reqaccountupdates, PortfolioValue, ... right ? I don't know how do it with DDE... What I'm currently doing is the last option ( watching if status = filled but if I don't know the id... ). I think I have found a way to do it with a new id generator. I will look at the ib function as well. Knocks, yes I know. However, it is the first time I program this kind of system and I 'm not good at all at programming. I'm always in front of the computer and the instrument on which I trade don't move fast... So I think it's ok until I learn a decent language...
Can you designate two cells which will be the order ID of the two orders? Then anytime you cancel/replace, you put the new order ID into the old order cell. You will always have the current two order IDs to look up either order for status.
sorry trad... you're right I didn't see DDE in the subject of your post, I just read the post contents and you didn't mention dde there... my bad. actually I was talking about the c++ api, but they're all pretty similiar... the DDE api is a wrapper around the c++ to my understanding, with some functionality removed. the dde api docs say that the clientId should always be zero for DDE, maybe setting the ID directly isn't supported in dde? http://individuals.interactivebrokers.com/php/apiguide/interoperability/dde_excel/programextend.htm clientId The ID of the client who placed the order. NOTE: The DDE client ID is always "0." in any case, you can infer whether an order has been filled using the same thing I suggested... the portfolio page in the sample DDE spreadsheet corresponds to the updatePortfolio/updateAccount calls I mentioned before.... here is the DDE spreadsheet portfolio : http://individuals.interactivebrokers.com/php/apiguide/interoperability/dde_excel/tabportfolio.htm you can then write a simple function in excel which queries against this portfolio page... eg PosSize(symbol) and it searches the symbol column until it finds a row with the requested symbol value and returns the value of the 'Position' column from the same row.
Thanks. In fact, I just made my system from "scratch" on excel so I don't use the IB spreadsheet. I don't really understand the DDE syntax for "acct" and "exec"... I will look at the example sheet from IB. I have a few ideas on what to do now. Thank you all.