Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Best method for getting level 2 market depth snapshots on a large number of equities
Hi all.
As most probably know, even if paying for extra streams, there is a hard limit of around 10 market depth streams that can be open at any one time. If I wanted to see a snapshot of level 2 depth data on, say, 30 stocks, what is the best way of accomplishing this? What I currently do is this: Let's say I'm allowed to have 5 open depth streams at once. Then in my code I have a loop that iterates through my list of 30 stocks, but ensuring that only a maximum of 5 streams are open at any one time. While a stream is open, the code checks whether I have data down to a specified depth, say, 10 levels, and as soon as I reach that depth on both bid and ask sides, I close the stream and open a new one. I also have a timeout, so that if any one stream has been open for too long it gets automatically closed. In this way I iterate through the list of 30 stocks, such that at the end, I have a snapshot of the depth across all 30 stocks. Obviously some of the data will be stale at this point, but for lightly traded stocks I haven't found it to be too much of an issue. One other point I should add is that in practice, I've found that I need to have one less stream than my maximum open at a time, otherwise sometimes things overlap and I get an automatic disconnection for attempting to open too many streams at once. So, are there any clever ways for improving on this approach that people are aware of, or is this about the best I can expect to do? BTW, I usually trade ASX equities, if that makes any difference. Cheers all, Colin |
||||||||||||||||||||||||||||
No historical market data for AAL/STK@VALUE Last 1d
Hi Everyone,
I'm receiving this error callback when making an historical data request for AAL: "No historical market data for AAL/STK@VALUE Last 1d"? (error code 162) I can't work out what's going on!? I'm retrieving the contract object fresh before sending the reqHistoricalData request.? The exchange in the contract object is 'SMART' and primaryExchange is 'NASDAQ', but the error message seems to indicate AAL is looking at the VALUE exchange. TWS shows historical data for AAL in the last 1 D, so it's not clear why the API would say there is no data. Most of my historical data requests are working fine (with all the same request parameters, except the contract object) - though there are a handful of others (say 1 in 100) that are also giving the same error above. Can anyone help solve this? |
||||||||||||||||||||||||||||
Re: reqPositionsMulti does not work as intended
To add, my goal is to tag orders with different modelCodes in order to keep positions apart. For example. If I buy 100 shares of Apple with modelCode "Strategy1" and short 100 shares of Apple with modelCode "Strategy2" my net position in TWS would be 0 but when I request positions I want to see two positions, one for each modelcode with their own averagePrice and positions. But I do not seem to be able to get there....
|
||||||||||||||||||||||||||||
reqPositionsMulti does not work as intended
I am having trouble with the C# API requesting positions via reqPositionsMulti with a modelCode. When I query with an empty string I get all open positions, however, when I populate modelCode with a non-empty string that was attached to the modelCode parameter in the Order class when submitting orders then? "positionMulti" does not return anything.?
Is there a special string that returns ALL positions, regardless of which modelCode was used when submitting orders? At this moment neither works.? |
||||||||||||||||||||||||||||
Re: opt out from: Secure Login required for trading
Thanks. Sounds like IB is moving towards 2fa. Guess it is time to bite the bullet. I was just I was hoping IB would do something more algo trading friendly, but of course any solution has pros/cons.? I am big fan of IBC. Been using it for 3 years, zero issues. One of my commits was even accepted in the code :) I tested over weekend how the latest version is handling 2fa. Very impressive, exactly how I was hoping a 3rd party app. would do it. I am switching 2fa on now with IBC. fingers crossed it will be as stable as without 2fa |
||||||||||||||||||||||||||||
Re: Duplicate Order ID
Hello Folks,
thanks a lot for your help again. I don't want to use more of your time. I have a workaround that works for me with creating a contract object. Its time for me now to figure out how i can use the contractdetails object and if i manage this i will publish this here. So thanks again for all the information and have a good time! Best wishes Robert |
||||||||||||||||||||||||||||
Re: Duplicate Order ID
You should not have to create all that code in order to use a contract object you received from reqContractDetails. And you should be able to use the entire object without having to copy individual fields. That defeats the purpose. Unfortunately, I don't have enough experience with Excel/VB (nor do we use MS/Office programs, LibreOffice/OpenOffice works much better for us) and I cannot give you additional pointers here. Maybe, for now, you should create contracts from scratch again. Using reqContractDetails to retrieve contract objects that IBKR creates for you with all fields they care about initialized is a "best practice" (but clearly not the only approach):
But again, this only makes sense if you can convince the Excel/VB environment that it should use the contract object from reqContractDetails without any extra coding or field copying. ´³¨¹°ù²µ±ð²Ô On Mon, Aug 1, 2022 at 05:37 AM, Metrodus79 wrote:Hello joanmarcel119, hello ´³¨¹°ù²µ±ð²Ô |
||||||||||||||||||||||||||||
Re: Duplicate Order ID
I think the best for you is to get the excel file which comes with the IB API and do some tests in their code.? What you have now developed I can not check if it is valid or it will work. I started the same way, by copying first the excel file of IB and then doing some minor changes and debugging. So if you already did this, then I recommend starting again. You should also debug the code to see how it works, like for example, setting a breakpoint?into the procedures called by the TWS usually?placed in the API module after your request has been sent. Hope that helps El lun, 1 ago 2022 a las 12:37, Metrodus79 (<robert.metasch@...>) escribi¨®: Hello joanmarcel119, hello ´³¨¹°ù²µ±ð²Ô |
||||||||||||||||||||||||||||
Suggestions on how to deal with blocking pop up from TWS (like last week)
¿ªÔÆÌåÓýHi all,Last week, I suddenly had this blocking pop-up from TWS asking me to read a document and confirm it. The message was about some rewritten parts in a particular agreement. The problem is, that message was triggered right when my algo tried to place an order. The order was then held back, until I read and manually confirmed the document (which was hours later). In the TWS settings itself, I have disabled all pop-ups, but also, these are only about trade warnings, not a legal document that the user is forced to read. Luckily, I haven't seen this type of intrusive pop-up before, but is there a work aroud for this? I'm sure many people had this pop-up too last week. Does the gateway have these blocking pop-ups? (I prefer using TWS so I can manually check what's going on) Thanks for any help, regards, Raoul |
||||||||||||||||||||||||||||
Re: Duplicate Order ID
Hello joanmarcel119, hello ´³¨¹°ù²µ±ð²Ô
I'm not anymore sure if the the request for the is valuable for me. To make the request i need a contract object and fill this with all the information that also need to place an order. I'm not sure if the contract object need all the information that i put in. Request for? Sub M_REAL_ORDER_KONTRAKT_DETAILS_ANFORDERN() Call M_GLOB_DEKLARATIONEN_EXCEC ?? ? ??? If Not (objTWSControl Is Nothing) Then ????? ? ??????? If objTWSControl.m_isConnected Then ?????? ? ??????????? 'Create object contract ??????????? Set contract = objTWSControl.contract ??????????? 'Fill this object it with contract information ??????????? With objTWSControl.contract ??????????????? .Symbol = UCase(wksRealImport.Cells(lngZ, flngFindeSpaltewksRealImport("SYMBOL"))) ??????????????? .secType = UCase(wksRealImport.Cells(lngZ, flngFindeSpaltewksRealImport("SECTYP"))) ??????????????? .lastTradeDateOrContractMonth = wksRealImport.Cells(lngZ, flngFindeSpaltewksRealImport("VERFALLSDATUM")) ??????????????? .multiplier = UCase(wksRealImport.Cells(lngZ, flngFindeSpaltewksRealImport("MULTIPLIKATOR"))) ??????????????? .exchange = UCase(wksRealImport.Cells(lngZ, flngFindeSpaltewksRealImport("B?RSE"))) ??????????????? .currency = UCase(wksRealImport.Cells(lngZ, flngFindeSpaltewksRealImport("W?HRUNG"))) ??????????? ? ??????????? End With ?????????? ? ??????????? Dim lngreqId As Long ?????????? ? ??????????? lngreqId = 1 ??????????? ?????????? 'Call for detailed contract information. ??????????? Call objTWSControl.m_TWSControl.reqContractDetailsEx(lngreqId, objTWSControl.m_contractInfo) ?????? ? ??????? End If ?? ?? End if end Sub Public Event send me the contract object in class modul Public WithEvents m_TWSControl As Tws Public contract As TWSLib.IContract Private Sub m_TWSControl_contractDetailsEx(ByVal lngreqId As Long, ByVal contract As ComContractDetails) Call M_REAL_ORDER_KONTRAKT_OBJEKT(lngreqId, contract) End Sub Do i get the same object back what i declared before? is This my problem here? Thanks again but I'm struggling with this. |
||||||||||||||||||||||||||||
Re: Duplicate Order ID
¿ªÔÆÌåÓýThere is no point in deleting it ¨C it has already been sent out to all the members (the vast majority) who receive posts via email. ? Just post again with the complete message, and you can add a comment explaining that the previous post was incomplete. ? Richard King Moderator ? ? From: [email protected] <[email protected]> On Behalf Of Metrodus79
Sent: 01 August 2022 11:08 To: [email protected] Subject: Re: [TWS API] Duplicate Order ID ? How i can delete the last message...i was not finish with this ;) |
||||||||||||||||||||||||||||
Re: Duplicate Order ID
As you mentioned: "
I think the object "contract" out of the??is not correct used. I tried different ways but I'm not sure if i can use the complete object or if i have to take all the information out and put this in a new object.?" I do think the same as you.? You need to "extract" the information received to fill the new object for the order to be sent.? I think?the most important is this one, in my implementation which may differ from yours: (The object conDetails comes from the Contract detail request) ? ? Set contract = conDetails.contract ? ? Debug.print "Api contractDetails " & contract.localSymbol & "-" & contract.Exchange & "-" & contract.secType ? ? Debug.print " ? ? ?-----------> " & conDetails.lastTradeTime & ";" & conDetails.contractMonth & ";" & contract.lastTradeDateOrContractMonth & ";" & conDetails.timeZoneId & ";" & contract.conId & ";" & conDetails.priceMagnifier This above piece of code will display on your excel debugger log some of the information which sends your the TWS once the request of contract details is received. Hope that helps you to fill the proper information for the new order request Hope that helps El dom, 31 jul 2022 a las 18:58, Metrodus79 (<robert.metasch@...>) escribi¨®: Hello Folks, |
||||||||||||||||||||||||||||
monthly data scanner
So I've been using the ib scanner for a while now, and I'm confused about how to scanne for stocks for a longer period than intraday. On tws we can choose between the mosaic market scanner or the advanced market scanner, looking deeper into the advanced market scanner I noticed that some features are missing compared to the mosaic market scanner like the month to month % change. Looking at?? ?it appears that the connection to the mosaic market scanner is not available. Am I? missing something? or does IB really doesnt provide access to the mosaic market scanner from it's API ?
|
||||||||||||||||||||||||||||
Re: Duplicate Order ID
Glad that worked, Robert. On the surface your approach looks fine. It is the contract object you receive with your object that you'd use for the order. There is a little more detail at Couple of thoughts:
I guess you have to do a little more digging. ´³¨¹°ù²µ±ð²Ô |
||||||||||||||||||||||||||||
Re: Duplicate Order ID
Hello Folks,
summarized briefly I could figure out that the problem was a confirmation what i had to do in my account. After that i could set the order placement. @Richard: Unfortunately I forgot to say that i had no problem on my paper account. Only on my live account and only for the future contracts. There absolutely no failure log were i could figure out why the order was not accepted. But i thank you for your time and that you tried this for me! @´³¨¹°ù²µ±ð²Ô: The hind with the order-ID is great and i implemented this in my program. I tried to implement the too but still now i couldn't manage this. Maybe you can give me a hind again. 1. I made the request for the contract details and i get a object called contract: m_TWSControl_contractDetailsEx(ByVal lngreqId As Long, ByVal contract As ComContractDetails) 2. In the next step i tried to use this object in the request for order placement 3. I create the object with the order information out of the class m_orderCom. This object comes for the class ComOrder and is defined as? Public m_orderCom As TWSLib.ComOrder: Set objTWSControl.m_orderCom = objTWSControl.m_TWSControl.createOrder 4. I fill that object with the significant order information ??????????????? With objTWSControl.m_orderCom ?? ? ??????????????????? .Action = "BUY" 'strOrderAktion? 'BUY, SELL, SSHORT" ??????????????????? .totalQuantity = 1 'lngOrderAnzahl 'ORDER ANZAHL ??????????????????? .orderType = "STP" 'strOrderTyp? 'MKT, MKTCLS, LMT, LMTCLS, PEGMKT, SCALE, STP, STPLMT, TRAIL, REL, VWAP, TRAILLIMIT ??????????????????? .auxPrice = 1 'dblOrderStoppPreis 'Stopp price ??????????????????? .timeInForce = "DAY" 'Order ist nur f¨¹r den Tag der Orderer?ffnung aktiv ??????????????????? .whatIf = 1 'bolwhatIf ?????????????? ? ??????????????? End With 5. I put the two objects (contract and objTWSControl.m_orderCom) in the request for the order placement and it doesn't work ?? ??????????? ?????????????? Set objTWSControl.m_orderCom.orderMiscOptions = objTWSControl.m_TWSControl.createTagValueList() ?????????????? Call objTWSControl.m_TWSControl.placeOrderEx(lngOrderId, contract, objTWSControl.m_orderCom) I think the object "contract" out of the is not correct used. I tried different ways but I'm not sure if i can use the complete object or if i have to take all the information out and put this in a new object. You helped me a lot to solve my problem. If this need to much time its absolute ok for me. i will figure out how it works by time. THANKS A LOT AGAIN! Robert ??? |
||||||||||||||||||||||||||||
Re: TWS Closing
Hello ´³¨¹°ù²µ±ð²Ô, thanks for your thoughts.
I am in Australia, and connect to the Hong Kong server. I have NBN internet fibre direct to the home, then cable to the PC. It was wireless, but I changed when problems started. IB have looked at my logs, for both when the connection is ok, and when IBG failed to re-connect to the Hong Kong server during the restart time (approx 23:02 Chicago time). IB even asked me to ping the server, so I set a ping script going every 2 seconds while IBG was trying to connect. There was no interruption in the ping sequence. So, we're at a loss to explain the situation. I am reluctant to change things at the moment as TWS is running successfully during the week. If it happens again, I'll come back to your post and look at the DNS aspects. Thanks again, KH |
||||||||||||||||||||||||||||
Re: TWS Closing
Nothing is impossible, but I cannot think of any reason why TWS would handle connection loss with IBKR any different or better than IBGW. The code is absolutely identical (65,817 identical class and 2,919 other files for version 10.16.1n) and only install4j scripts are slightly different between the two. We have seen the situation YQ describes where the disconnect was too long for the automatic re-connect without credentials. But tht happened very rarely and most cases took place over the weekend during extended IBKR maintenance periods. There can be many different reasons for re-connect failures and TWS/IBGW logs may be able to give you some pointers of what is going one, but most of them probably fall into one of three categories:
All of this assumed wired connectivity. Your mileage will be worse in case your TWS/IBGW communicates through WIFI or other wireless services. Just some thoughts, ´³¨¹°ù²µ±ð²Ô
On Fri, Jul 29, 2022 at 04:25 PM, Kevin wrote:
I recently experienced the exact same problem as Yilin Qin described, however it is with IB Gateway, not TWS. I ended up changing from IB Gateway to TWS (reluctantly). |
||||||||||||||||||||||||||||
How to automatically accept (or disable) the paper trading notification?
I'm opening TWS using IBC via Task Scheduler.
I'm paper trading while testing my strategy. TSI has an automatic notification pop up when I log in to remind me that I'm paper trading. Unless this notification is accepted, my bot can't connect to the TWS API. Is there a way to automatically accept (or disable) this notification? Thanks! |