partial fills orders
Hello, I have an issue handling the partial fills orders, in my code, I need to make sure that all partial orders are executed to process the next steps, I use the remaining function from trade object to check if the remaining shares is equal to 0 or not, below is my code, the issue here is that it give always remaining == 0 even there are some remaining shares. I use this event: self.ib_client.execDetailsEvent += self.on_exec_details` ` def on_exec_details(self, trade, fill): symbol = trade.contract.symbol if symbol in self.positions: trade_type = trade.order.orderType side = fill.execution.side order_id = trade.order.orderId shares = fill.execution.shares while not trade.isDone(): logger.info(f"{symbol} : Trade type: {trade_type}/{side}, Trade Status {trade.orderStatus.status}," f"remaining shares: {trade.orderStatus.remaining}") self.ib_client.sleep(1) logger.info( f"Execution of {trade_type} order for {symbol}, side = {side}, " f"shares = {shares}, order_id = {order_id}, Trade Status = {trade.orderStatus.status}" f"remaining shares: {trade.orderStatus.remaining}" ) self.ib_client.sleep(1) if trade.remaining() != 0: return Could you please help me understand why this is not working properly?
|
Cannot invoke "java.io.DataInputStream.read(byte[], int, int)" because "this.m_dis" is null
Lately, since a couple of weeks, am I getting this error message every now and then: Exception: Cannot invoke "java.io.DataInputStream.read(byte[], int, int)" because "this.m_dis" is null I have tried to figure out whether it is somehow related to my application software. It occurs after I disconnect a client from Gateway. I believe that this exception message is coming from the API Java class EClientSocket (method eConnect()), but am not sure. I am using API10.19 and Gateway 10.31. Is this an indication that there is something wrong in my application software? Or should I simply ignore this because I already disconnected the client?
|
One cancels all : Group contains orders for Personal Account
3
Hello, I get this error while creating the trail and the stop order using the one cancels all logic (OCA), it's working fine in the paper account but not in the live account, below is the error message: ERROR - Error 10224, reqId 673: One-cancels-all group of orders should contain orders with exactly the same account. OCA group '0913e328-d9c4-4b4a-99b8-f6b921824f25' contains orders for Personal Account (account_name), Undefined. What can be the issue here please ? below is the code if this help : oca_group_name = str(uuid.uuid4()) if position["enable_trailing_stop"]: trailing_stop_order = Order( orderType="TRAIL", action="SELL", totalQuantity=position["current_shares"], trailingPercent=position["trailing_stop"] * 100, tif="GTC", outsideRth=True, ocaGroup=oca_group_name, ocaType=1, ) trade = self.place_order(position["contract"], trailing_stop_order) position["trailing_stop_order_id"] = trade.order.orderId position["trailing_stop_order"] = trade.order stop_loss_order = StopOrder("SELL", position["current_shares"], stop_loss_price, tif="GTC", outsideRth=True) stop_loss_order.ocaGroup = oca_group_name stop_loss_order.ocaType = 1 trade = self.place_order(position["contract"], stop_loss_order)
|
Dividend Yield
5
Hey TWSAPI guys, I have seen a couple of messages about retrieving dividend information, adding tick types 256 and 456 in the stringlist and capturing field 56, sadly to no avail. Is that an issue with requesting data using SMART routing? Any hint to at least get the SPX dividend yield would be great for a start. Thanks
|
Re forecast trader
Hi everyone I got an email about forecast trader quote (Trade your view on economics — Predict outcomes of economic indicators with simple YES/NO trades. Start today at IBKR! ) Doesn't look like there is any info on the API docs. Has anyone trade this thing looks like a joke to be honest at first glance? Not sure I like the direction ibkr is going also it looks like only ibkrs exchange is offering it. Full contract list at forecastex.com
|
How do folks here front load their databases with TWS?
9
Hello All, I have a fairly straight forward program that scans the market and looks for custom TA indicators with the One Hour bar. However, front loading my database causes some real headaches. I download available symbols from the NASDAQ FTP site daily ~7,000 symbols, sort them and remove warrants, preferred shares, etc. and then req.Historical Data usually 6 months of 1 hour bars (~850 bars) to front load my database. IB's limitation of no more than 60 requests in any ten minute period is brutal. (~7,000 symbols / max 360 per hour = ~20 hours of front loading ) However, after trial and error, it does not appear that IB has a limitation on req.HistoricalData when the data is less than 5 trading days in the past. If I do a req.HistoricalData for 4 days of one hour data (28 bars), it only gives an error when I exceed the 50 messages per second limitation--my database fills 7,000 stocks with 4 days of data in about 3 minutes. I've seen other folks post here and can request a years worth of data in seconds in some cases. I'm wondering if any others have experience with this or if there's a workaround that others employ. Thanks to all in advance,
|
Any updated TWS API C++ library?
2
Hi all, I am building a trading model in C++. TWS API is not easy to use so I am looking for a helpful library that abstracts away many low level details and ease the development process. Google suggested me this library https://github.com/JanBoonen/TwsApiCpp which was used in this video https://youtu.be/ZxwdTgMY44g?si=cGRbH1MLUYw0X-Cp too. BUT the repo has not been updated in the last 8-9 years. Are there any actively updated C++ library repo for TWS API? Thank you in advance!
|
Time of order submission
4
When I ask TWS API for a list of the orders that I have placed recently, I get back a number of attributes of each order (PermId, Action, LmtPrice, etc.) https://interactivebrokers.github.io/tws-api/classIBApi_1_1Order.html However, the order placement time does not appear to be here, which seems odd. Am I correct in thinking that TWS API is not able to tell me the time at which I placed orders, and thus it is up to me to keep track of those times? Or am I missing something? It seems odd that time of order placement would not be among the order attributes that TWS API reports to me.
|
API/CTCI orders for canadian stocks are not allowed error message
5
Hello We are trying to use the IB Python API to place an order in a paper trade account. We can get historic market data OK in our program, so there is some connectivity to IB working. But we get an error saying "API/CTCI orders for canadian stocks are not allowed" does this mean that the IB API can not be used to place orders on the TSX ? Hopefully we have just done something dumb but I googled a bit and am now worried its not achievable. Does anyone have any wisdom on this please ? Or does anyone know of an alternative API/broker we could use instead of IB if they don't support this anymore. Thanks for any help people can give us. Dave
|
How many reqHistoricalData requests with keepUpToDate=true can be run in parallel
Gents, Is there a limit on how many historical data requests (reqHistoricalData call) with keepUpToDate=true can be run in parallel? Also, if for the same security I request historical data (with keepUpToDate=true) of various bar sizes, does each bar size count to the limit, or only one "slot" is used?
|
Error Code -> 366 w/ reqHistoricalData() in ib_insync for realtime stream
Hi, Anyone else seeing this error start popping up today? Only started since about 3 P.M. The contract is valid and has been working since this morning. This is through ib_insync and is using callbacks with self.ib.run() following the call below catching event updates. Here is the following error: reqHistoricalData: Timeout for Future(conId=563947733, symbol='NQ', lastTradeDateOrContractMonth='20241220', multiplier='20', exchange='CME', currency='USD', localSymbol='NQZ4', tradingClass='NQ') Error 366, reqId 5: No historical data query found for ticker id:5, contract: Future(conId=563947733, symbol='NQ', lastTradeDateOrContractMonth='20241220', multiplier='20', exchange='CME', currency='USD', localSymbol='NQZ4', tradingClass='NQ') Call: bars = self.ib.reqHistoricalData( self.contract, endDateTime='', durationStr='1 D', barSizeSetting='5 mins', whatToShow='Trades', useRTH=False, formatDate=1, keepUpToDate=True ) #event handler for updates to realtime historical OHLC data... bars.updateEvent += self.OnBarUpdate
|
Submitting many orders simultaneously
7
Hi. I am new here, so I apologize if this question has been covered already. Until recently I was trading on IBKR using the Client Portal API. Each day I would simultaneously place about 100 limit orders for various U.S. stocks, and I did this using the /orders REST endpoint. If one uses an array of orders as the payload of the post request, the orders are all submitted simultaneously. Sadly, on Sept 4 IBKR stopped allowed one to submit multiple orders this way. Only single orders are allowed now. But if I try to submit ~100 orders sequentially, it will take too long. I need to submit them all within a few seconds of each other. So, I am considering using the TWS API for this. My questions are: Is it possible to simultaneously place ~100 limit orders using TWS API (with ib-async)? If yes, how? In case people here are familiar with the Client Portal API, does anyone know an alternative way to submit simultaneous orders with the Client Portal API? (I submitted this question to IBKR, but there is no reply.) Thanks very much for any guidance that anyone can give me.
|
new IBKR desktop APP
6
As you guys probably know by now, there is a new desktop APP. I was wondering if anyone here knew what the long term plan is? Would it be to stop TWS completely and have everyone move to the new desktop app? I hope they will continue to support trading via a API. Its probably going to be a lot of work for us to learn and debug the API once thats available. I was wondering what thoughts you guys have about this pending change
|
API data not the same as TWS data?
2
Hi there. I'm retrieving data from stocks using a Python script and the methods tickPrice, tickSize and updateMktDepthL2 It looks like it is working, but checking the data I get from the API is not similar at all to the data shown in TWS (or other apps). I'm wondering if I'm doing things right. I have been reading about this on the internet and it happens to be a common subject. I know I should count with some deviation, the bars I could build with fetched data are not going to be exactly the same as the TWS bars, but the samples I have checked are far away from being close. I'm trying to build a system that takes data from the order book and trades (prices) to make a study, but with the provided accuracy is impossible. I don't need a 100% accuracy, let's say a 98% will be fine. By the way, I haven't found any documentation about the retrieved data, is there someone who can give me a link or confirm my understanding is right: 05/09/2024 15:29:59.427 HBAN tickPrice reqId: 3 tickType: BID price: 14.85 attrib: CanAutoExecute: 1 PastLimit: 0 PreOpen: 0 05/09/2024 15:29:59.427 HBAN tickSize reqId: 3 tickType: BID_SIZE size: 2300 The first line means an order has been filled in the BID side at 14.85 The second line means the order had a size of 2300 So the last crossed price will be 14.85 The same is true for ASK side orders. 05/09/2024 15:30:00.275 HBAN tickPrice reqId: 3 tickType: LAST price: 14.85 attrib: CanAutoExecute: 0 PastLimit: 0 PreOpen: 0 05/09/2024 15:30:00.276 HBAN tickSize reqId: 3 tickType: LAST_SIZE size: 2300 This is much more tricky, it could be: 1) a confirmation of the previous trade, so they are always redundant, 2) Market orders crossed with other market orders Could anyone confirm? Thank you,
|
What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)
24
The latest TWS API for Java added a new required parameter to the existing method EClient::cancelOrder. It now takes a string for manualOrderCancelTime which can be left null. What does this parameter do? Cancel an order if not already filled at a specific time in the future? It's not documented:
|
Expired contract & TimeZoneId
2
I found that when I request ContractDetails for an expired future contract, the contractDetails object I receive has TimeZoneId propertiy set to Null. But if I want to download HistoricalData for that contract I need to know its TimeZoneId to correctly send the request. So how can I to solve the problem?
|
Rolling futures to the next expiry
2
Hi all, I was trying to roll my future to the next expiry (RTY Sep, CME -> RTY Dec, CME) with a negative current position (RTY Sep, CME: -1) on TWS GUI, i.e. from RTY Sep, CME: -1 RTY Dec, CME: 0 to RTY Sep, CME: 0 RTY Dec, CME: -1 I'm also connecting to TWS through TWS API. However, when the callback function "openOrder" is called, i get the wrong action (BUY/SELL) for the respective orders. Details: 637533627: RTY Sep, CME 654503362: RTY Dec, CME contract.comboLegsDescrip: 637533627|-1|CME,654503362|1|CME Leg. conId: 637533627 action: SELL Leg. conId: 654503362 action: BUY To my best knowledge, isn't it supposed to be contract.comboLegsDescrip: 637533627|1|CME,654503362|-1|CME Leg. conId: 637533627 action: BUY Leg. conId: 654503362 action: SELL However, in the end, i'm able to get the correct execution details: 637533627: BOT 654503362: SLD So I was wondering if I misunderstood the definition, or could this be a bug from TWS?
|
Using Excel
I appreciate this may have been answered (please point me to the thread - or a vba code example). I have the TWS_ActiveX.xls working But I am unable to automate pulling down Account, Portfolio and Open order data using one button - I have to go to each tab and request data. I am sure its a scoping/hierarchy within the code but I have been unable to make it work . Any pointers - just want to press one button (preferably not on either of the account portfolio or open order tabs) and all data is refreshed Many thanks P
|
C++ TWS API reqMktDepth() giving 309 error
6
Hi, I have had the same setup for streaming the level 2 market depth for a long time now. Yesterday, I started receiving this error "[20240905-12:58:19] Error [Id, Code, Msg]: 1001 : 309 -> Max number (3) of market depth requests has been reached". My code makes the stream request right before entering my main trading logic loop, and it only makes it once, so I am confused as to why this is happening now. The contract I am trying to stream is a future w/ these details: TICKER -> "NQ" EXP_MONTH -> "202412" LOCAL_SYMBOL -> "NQZ4" EXCHANGE = "CME" CURRENCY = "USD" Any help would be appreciated, especially if a change has been made to the API without my knowledge. Here is the line where I am making the request, m_sPtrIbc is a smart pointer that represents the client I built out. ReqMarketDepth() is simply a one liner -> m_pClient->reqMktDepth()... //launch streaming of orderbook depth... m_reqMktDepthId += 1; m_sPtrIbc->ReqMarketDepth(m_reqMktDepthId, m_contract, 5, false, TagValueListSPtr());
|
API server failed to start
2
Can anyone help me please.. My paper trading account's API server fails to start. Every time i log into TWS, it says the API server failed to start since the specified port 7497 is already in use by another application. I don't have another TWS application running but it keeps on saying socket port in use. Tried reinstalling the TWS, changed the versions, even tried changing the socket port number but nothing is working.
|