Error. Id: -1, Code: 509, Msg: Exception caught while reading socket
5
Any idea what causes this? I also get this one: Error. Id: -1, Code: 509, Msg: Exception caught while reading socket - Numerical result out of range I found this similar thread: /g/twsapi/topic/4047617#33752 But I couldn't follow it to a solution.
|
Decimal remaining value retrival
2
Hello Folks, Is is possible to get Decimal remaining value in the below callback //! [execdetails] void execDetails(int reqId, const Contract& contract, const Execution& execution) { printf("ExecDetails. ReqId: %d - %s, %s, %s - %s, %s, %s, %s, %s\n", reqId, contract.symbol.c_str(), contract.secType.c_str(), contract.currency.c_str(), execution.execId.c_str(), longMaxString(execution.orderId).c_str(), decimalStringToDisplay(execution.shares).c_str(), decimalStringToDisplay(execution.cumQty).c_str(), intMaxString(execution.lastLiquidity).c_str()); like we receive in Order Status callback void orderStatus(OrderId orderId, const std::string& status, Decimal filled, Decimal remaining, double avgFillPrice, int permId, int parentId, double lastFillPrice, int clientId, const std::string& whyHeld, double mktCapPrice) { printf( "OrderStatus. Id: %ld, Status: %s, Filled: %s, Remaining: %s, AvgFillPrice: %s, PermId: %s, LastFillPrice: %s, " "ClientId: %s, WhyHeld: %s, MktCapPrice: %s\n", orderId, status.c_str(), decimalStringToDisplay(filled).c_str(), decimalStringToDisplay(remaining).c_str(), doubleMaxString(avgFillPrice).c_str(), intMaxString(permId).c_str(), doubleMaxString(lastFillPrice).c_str(), intMaxString(clientId).c_str(), whyHeld.c_str(), doubleMaxString(mktCapPrice).c_str()); I wan't to get decimalStringToDisplay(remaining).c_str() in execdetails callback. Thanks.
|
QQQ 1 Minute Data >6years?
24
Recently I have been trying to backtest a new strategy using 1 minute bars. I was able to get 10 years worth of 1 minute data for SPY, IWM and DIA but not for QQQ. The longest I can get for QQQ is ~6 years. For older dates the reqHistoricalData() call comes back with a strange error : "Unrecognised Contract". Does anyone know why this is? Note I tried, SMART, ISLAND, NASDAQ as the exchanges and all came back with the same issue. Wondering if it is a temporary glitch or a genuine problem and I will not be able to get data that far back for QQQ. Any input would be helpful.
|
C++ IBKR API implementation and biddll.lib Intel Math Library
6
Hi, After I failed with the Purebasic network functions (could not go farther than connecting and getting current date/time...) I decided to use the C++ IBKR API implementation. I am now stuck with things that are probably very simple for most of you ;-( Steps I made: - Operating system: Windows 10 64-bit. - Installed Microsoft Visual Studio 2022 for C++ - Reinstalled TWS API 10.30.01 - It appeared that "biddll.lib" the Intel "Decimal Floating-Point Math Library" was not found anywhere on my hard disk or anywhere else on the net. - As I found out that I had to recompile that library, I installed "mingw64" - After having waisted a lot of time with makes, nmakes, environment paths and many other things, no way to get past several errors (make mostly). Do you know where I can find that "biddll.lib" (precompiled for Windows 64 bits preferably) ? Or suggest simple steps in order to compile that damn library. Or find a work around. I still do not understand why things have become so complicated since the past 20/25 years where dropping and OCX control on a VB6 form was so simple ! Thanking you in advance for your help
|
Clarification on Identifying Order Status Callback for Modified Orders
2
Hello Folks, While sending a modification request for an existing confirmed order, I am receiving the following callbacks related to that specific order ID: OpenOrder OrderStatus Error: "Order rejected - Reason: Invalid Price" Upon sending the order modification request and subsequently receiving the OrderStatus callback, how can I ensure that the OrderStatus callback pertains to the modified order? In the example above, it was not related to the modified order. Thanks.
|
Time is a reserved name in VBA
3
The Excel versions of the API frequently use the variable 'time'. Declaring it as string or as long in numerous places. It is also in the TWSlib in at least five places. This is a problem because 'Time' is a built-in VBA function (which returns the current system time) and is part of the VBA standard library and cannot be redefined without causing conflicts. In other words Time is a reserved name in VBA. To verify this problem, one can create a module in an Excel workbook that is using the API and enter a simple function like this: Option Explicit Function testTimeProblem() testTimeProblem = Time End Function Notice that the Time will be changed to time... Which is an indication of the problem. This needs to be fixed. How do I report this problem to IB Developers or do they monitor this Group? Thanks!
|
Cancel on Client Disconnect/Logout
3
Hi, Is there any option in the TWS application to automatically cancel all open orders (an event triggered automatically by the TWS application) when the client disconnects? Or is there a specific field we can set when sending orders via the TWS API to achieve this? Thank you.
|
Not receiving previous close price from ReqMktData
3
I'm not regularly receiving tick #9 today through the API after calling ReqMktData for one particular stock. Admittedly, this is not the first time I ran into this bug for any random stock, but today this it's repeats frequently (most of the time, indeed) with one particular stock. So I managed to log this problem with ease and now I have not one, but two API log excerpts running for at least 5 minutes during regular trading hours with lots of ticks coming in from ReqMktData, but not the Close Price tick. The stock in question is XNYS:ATR, {Type='STK';LocalSymbol='ATR';PrimaryExchange='NYSE';Symbol='ATR';Exchange='SMART';Currency='USD';ContractId='4651'}. Its last closing price yesterday was 158.46 and it is displayed in TWS no problem in the respective Previous Close column, but is apparently not getting reliably reported through the API. I ask the group to see my logs to help decide how to go about this issue. I'm attaching the two decoded TWS API log text excerpts with everything before the respective REQ_CONTRACT_DATA and REQ_MKT_DATA calls removed due to representing sensitive account data and up to the point of API connection closing (about 5 minutes each), with a few short clarifying comments denoted with the starting symbol #. -- Best, DS
|
Fee Rate for opening a short position
Where does the fee rate show up? Is it folded into the commision charge? How can that be determined through the API? If I understand the fee rate correctly then taking for example I open a short position on NVDA that amounts to $10,000. The fee rate for today = .41% The fee then amounts to $10,000 * .41% = $41.00/365 = $0.11 cents for one day if I close the position before market closing? Assuming I'm correct where does this fee show up? is it folded into the commision fee? If I repeat the same transaction 5 times during day trading does that amount to $0.11 * 5 = $0.55? Can that be determined in an API call?
|
reqHistoricalTicks() & batching vs. reqTickByTick() vs. reqHistoricalData(), Backtesting vs. Realtime execution
21
Hi, I have discussed this with the API support team, but I am still fuzzy and was not given the most clear answer. I am backtesting a strategy where the data has been collected using reqHistoricalTicks() & whatToShow='TRADES' was selected going back to early 2023 for natural gas. In real time, I imagined I would use reqTickByTick() to get the most recent ticks and act accordingly to the strategy. However, I am aware that reqHistoricalTicks() uses a batching algorithm to batch all ticks to each second I believe. Atleast, that's what the timestamp suggests when received from IB. So, because reqTickByTick() is more granular and I do not believe batches to each second, I am concerned any strategy I form will not be reliable in execution because the data will be too granular and you cannot stream reqHistoricalTicks() in realtime I believe like you can with reqHistoricalData(). The main problem, is my strategy revolves a lot around large "tick" trades. So, more granularity means broken up matched orders, in turn large order sightings are not frequent. In practice, should I just be streaming some sort of 1 second bar using reqHistoricalData() as that is really what reqHistoricalTicks() is giving me? Or am I wrong? Thank you.
|
C++ preventing EReader reading when socket is closed
23
I have faced a problem with my code for a long time that only occurs during the call to EClientSocket::eDisconnect() I have a separate message processing thread running which looks like this: ftrMsgProcThrd_ = pool_->submit( [&]() { while (clientSocket_->isConnected()) { signal_.waitForSignal(); // This waits 2 seconds. reader_->processMsgs(); } }); I decided to tackle this annoying bug (not the first time) and have found that after the call to EClientSocket::eDisconnect() which calls EClientSocket::SocketClose() which just calls a Windows Sockets closesocket() on the open socket, I am still getting the message processing thread (EReader thread) trying to perform a Windows Sockets recv() messages on the closed socket resulting in a 509 error. I have traced that error to be socket error 10038 which confirms it is an invalid socket (in this case, a closed socket). Before the line "reader_->processMsgs()" I have tried checking for the socket still being open with if(clientSocket_->isConnected()) but it does not solve the problem. The EReader is running in its own thread as per the reader_->start() call. I thought, perhaps I need to close the EReader before calling eDisconnect so I tried deleting the object and removing the call to eDisconnect() because the destructor of the EReader calls eDisconnect() itself but this does not fix the error. i still get the 509 caused by a read on the closed socket. I am struggling here and would appreciate advise from any C++ coders that use a multi-threaded approach like the above. It is likely a threading issue but if anyone else has faced a similar "disconnect" issue I would be happy to hear what you did to resolve it.
|
Strange Behavior After TWS Update on Old API
12
I was successfully running my code using TWS 10.19.2a with IbPy (an old python 2.7 TWS API) due to tons of legacy code. I installed the latest standalone stable TW, version 10.30.1, logged in, and then noticed the API had problems. No problem I thought, I'll just go back to TWS 10.19.2a, but now it too is having the same problems that only showed up once I installed 10.30.1t. I wondered if the issue was a setting somewhere being changed because installing the newer TWS destroyed my settings, but I think I have everything back to how it was before and the API problems I'm facing don't seem obviously settings related. In particular, requesting trade executions and open orders often incorrectly return nothing now. Both requests will still return their final terminating/done-with-request messages, just no actual data execution or open order info like they should. When they fail, they consistently fail and return nothing. Then suddenly, for reasons I cannot figure out, they'll start working again consistently only to eventually start consistently failing again. Updating TWS also gave me the bug of the open order handler suddenly receiving an extra field, but that was easy enough to deal with. Does anyone have any idea what the problem could be or have any ideas? I've been putting off refactoring to the IBKR's API because it will take A LOT of rewriting and testing.
|
One more issue/thing about reqexecutions
Hi there, I've checked some of the older posts about reqExecutions and some of them are about the same, not getting the executions even the trade history has been set to x days before. I can explain my findings about this, maybe this can help somebody. I'm using TWS 10.30 and I can replicate the same behaviour on IBG 10.30 This behaviour just occurs on the PAPER account: - You won't get the executions until you visit the trade history page first. Once you click on the Trade History button or keyboard shortcut on TWS (ALT+A+T) then you are able to request the reqexecutions and you get them back on the execDetails and execDetailsEnd events. I can send a combination of keys to the TWS to solve this issue while testing on the Paper account but I can not replicate this on the IB Gateway. Hope this helps
|
How does a scanner with the Top % Gainers parameter in show % Change in pre-market?
Hi everyone, I know the TWS scanner with the 'Top % Gainers' parameter works outside regular trading hours. However, I¡¯m confused about how the % change is calculated for stocks during pre-market hours. Specifically, does the % change compare the current pre-market price to the close price of the previous trading day, or does it compare the current pre-market price to the close price of the day before that? For example: if it¡¯s Wednesday pre-market, is the % change based on the comparison of the current pre-market price of the stock and the stock¡¯s price at Tuesday¡¯s regular hours close, or is it compared to Monday¡¯s regular hours close?
|
Delphi and TWS
11
Hi Is anyone working with Delphi (pascal) to connect to TWS? I can't connect at all. Thanks
|
2FA with mobile AND old white card with numbers
Dear all, For the authentication I'm using the old white code card. Now I have a gateway on a server. For that user I want to login by getting a push message on my mobile device. Now I have several questions - Can I add my phone for 2FA WITHOUT loosing the option for my card with numbers? - If so how can I do the registration of my phone (WITHOUT loosing the option of my card) - How can I tell which account should use which 2FA (including paper trading users)? I only want one use for the gateway to use the phone authentication. All other accounts and users the number on the card.
|
Problem with RTD and Excel
9
All, I have a spreadsheet that has worked for years and updates a set of stock, fund, and option prices. A week or so ago, it stopped updating and gave me an error message as shown below. I have an if condition in the cells that forms the RTD statement according to whether the symbol is a stock or a fund as shown below. The cell reference A269 is for the stock/fund symbol STOCK =RTD(RTD_SERVER,,A269,"Last") FUND =RTD(RTD_SERVER,,"sym="&A269,"cur=USD","exch=FUNDSERV","sec=FUND","qt=CLOSE") I uninstalled both TWS as well as the API and reinstalled both. I had been using the 9.81 API and am now on the new one. But, it didn't make any difference. I get the same error. I also tried starting over again with a brand new spreadsheet, but that didn't fix the problem. Anyone have any suggestions? Regards, Jim --------------------------------- ERROR MESSAGE ------------------------------------------------------- "TwsRtdServer error: Error validating request.-'bP' : cause - Incorrect generic tick list of 100,101,106,165,221,225,232,236,258,293,294,295,318,460,619,104,411,456,595,105,576,577,578,614,623,586. Legal ones for (STK) are: 100(Option Volume),101(Option Open Interest),105(Average Opt Volume),106(impvolat),165(Misc. Stats),221/220(Creditman Mark Price),225(Auction),232/221(Pl Price),233(RTVolume),236(inventory),258/47(Fundamentals),292(Wide_news),293(TradeCount),294(TradeRate),295(VolumeRate),318(LastRTHTrade),375(RTTrdVolume),411(rthistvol),456/59(IBDividends),460(Bond Factor Multiplier),577(EtfNavLast(navlast)),586(IPOHLMPRC),587(Pl Price Delayed),588(Futures Open Interest),595(Short-Term Volume X Mins),614(EtfNavMisc(high/low)),619(Creditman Slow Mark Price),623(EtfFrozenNavLast(fznavlast))"
|
IB's New automated trading system questionnaire
12
I logged on to my account and found a must complete questionnaire about how I'm monitoring my automated api. It wanted to know 1) Did I write it or is it commercial and if so the vendor? 2) Is the API completely automated? If not to what extent it is manual? 3) How are critical errors handled (audible alert, email, text)? 4) Is it constantly monitored? 5) and more Apparently it is now being required by regulators. Given that, can anyone point to code that will allow me to send email/texts now that Google and Yahoo are requiring two factor authentication? I used to send emails and texts when single factor was good enough. Frank
|
Construct quote with greeks and prices
Trying to create a quote based on ticks coming from "reqMktData". Simplified code below. Question: There are two separate callbacks for option greeks and prices and both are important for my strategy but at the moment callback for prices is almost always executed before callback for greeks, so "PointStream" often receives quote with prices but without greeks. Is there an easy way to make sure that before I send final quote to the stream, its greeks are already calculated? void SubscribeToPoints(Contract contract) { var point = new PointModel(); void subscribeToComs(TickOptionMessage message) { point.Delta = message.Delta; point.Gamma = message.Gamma; point.Theta = message.Theta; point.Vega = message.Vega; point.Sigma = message.ImpliedVolatility; } void subscribeToPrices(TickPriceMessage message) { switch (message.Field) { case PropertyEnum.BidSize: point.BidSize = message.Data; break; case PropertyEnum.AskSize: point.AskSize = message.Data; break; case PropertyEnum.BidPrice: point.Bid = message.Data; break; case PropertyEnum.AskPrice: point.Ask = message.Data; break; case PropertyEnum.LastPrice: point.Last = message.Data; break; } PointStream(point); } client.TickPrice += subscribeToPrices; client.TickOptionCommunication += subscribeToComs; client.ClientSocket.reqMktData(id, contract, string.Empty, false, false, null); }
|
conditional order conditioned on execution of buy order only?
9
I have a question about conditional orders, where the condition is an execution condition, per https://interactivebrokers.github.io/tws-api/order_conditions.html#execution_condition https://interactivebrokers.github.io/tws-api/classIBApi_1_1ExecutionCondition.html#details The documentation says that the condition is defined by giving a symbol, an exchange, and a security type, and that the condition is met "whenever a trade occurs on the specified product at the given exchange." Per other discussions here (e.g. J¨¹rgen's comment) I assume that the trade must be a trade in the current account (one that would trigger an execDetails message). Here's my question: in the case that I have two standing orders for the symbol, namely a buy order and a sell order, is it possible to have the condition trigger only when the buy order executes (and not when the sell order executes)? (I don't see how, although I did think of one possible workaround: have two separate processes, each with its own connection to TWS, one managing the buy order, the other managing the sell order. Then (perhaps?) the execution condition set by the process that placed the buy order would only be triggered if the buy order executes. I don't know if this would work (I haven't tested it). I don't really want to resort to this, as having two separate processes, each with a separate connection to TWS, would complicate my code quite a bit.) Thanks, Neal
|