开云体育

ctrl + shift + ? for shortcuts
© 2025 Groups.io
Date

Re: reqPositionsMulti does not work as intended

 

Portfolio models and related to that model codes are for advisors to automate trading of instrument combinations. If you have not done so, take a look at and

闯ü谤驳别苍


Re: reqPositionsMulti does not work as intended

 

Fair enough if that was the case but then what is modelCode good for? I don't seem to be able to make use of it. Orders can be supplied with a model code and that modelCode can be entered into reqPositionsMulti. I don't see the benefit of that if it does not work...?


Re: reqPositionsMulti does not work as intended

 

Dojo321 wrote: ".. net position in TWS would be 0 but when I request positions I want to see two positions, .. "
This is not possible with an IB account. Your IB account is a netting account, meaning that only the net result of all trading activities in a ticker symbol is available as position size. IB does not provide a so-called "hedging account", which is what you would need for your purpose.


Re: Suggestions on how to deal with blocking pop up from TWS (like last week)

 

Great question. I didn't get a popup at all. But all orders stopped. And I had to a web interface to actually see to popup and agree.?

More interesting question is: how one could learn in advance about those? I.e. I didn't get any emails from IB that I have x days to review and agree/disagree. The message just popped up. And this is not somethin an algo trading can deal with.? It is actually second time in 2 years where IB stops my trading with no warning (last time it was brexit, and because of jurisdiction change a company needed a LEI number. took 4 days to get. But ib knew about that 6 months in advance. Could have put it in the migration plan.). Either I am (we are) missing some info or IB just not particularly careful with user experience. I.e. I bet those legal changes were known in advance and they could have warned people and gave them some time in advance to react.??


Re: About commissionReport.realizedPNL

 

Hi,Bart,

Thanks for your help.
It's a way to calculate realized PnL by adding dailyPnL.
Do you use this method by calculating yourself?


--


------
Forex trader
David Liao


Re: How to automatically accept (or disable) the paper trading notification?

 

I don't know enough about dockers, so I'll try Despair's suggestion for now. Thanks for your help anyway!


Re: How to automatically accept (or disable) the paper trading notification?

 

Great, thank you very much for your help, Despair!


Re: Best method for getting level 2 market depth snapshots on a large number of equities

 

Thanks for the response Jurgen, really appreciate it. Everything you said about the cancellation requests makes sense to me.

How long does it take to grab a snapshot for 30 instruments?

On average, I find I'm able to get about 1 per second if I limit myself to one stream maximum. With a two stream maximum I can get somewhere between 1.5 and 1.8 per second. With a three stream maximum I was getting a bit over 2 per second, but that's my maximum number of streams alas. This is all trading on my own account, so unfortunately I'm a wee bit short of the account values needed to get awarded bonus streams :-)??? and I'm not currently paying for any booster packs.

Cheers,

Colin


On Tue, 2 Aug 2022 at 17:34, 闯ü谤驳别苍 Reinold via <TwsApiOnGroupsIo=Reinold.org@groups.io> wrote:

I would have used the same approach and cannot see a way to do it differently. How long does it take to grab a snapshot for 30 instruments?

When you are done with a snapshot it will take a while for your request to be finalized. TWS sees it right away, but I am sure they won't add the feed back to the "available" pool until TWS receives a cancellation confirmation from the IBKR back-end. So I am not surprised that the next might get denied until TWS has received a cancellation confirmation from IBKR. Unfortunately, has no callback that indicates to you when it is safe to make the next request. This could potentially be an ongoing area of instability.

The hard limit for the number of simultaneous Level 2 streams must have been increased, since now says you can have up to 60. But you can only get 10 of them by purchasing booster packs. To get to 60 you must have enough equity or commission to "earn" them.

According to the fine print in

  • "There is no cap on the quantity of market data lines allocated per customer."
  • You get one market line per $8 in monthly commissions
  • Or for each $10,000 in equity

If my math is correct, $48,000 in monthly commission or an account value of $60Mio gets you to the 6,000 market line allocations you'd need for 60 simultaneous market depth feeds. Or half of that for 30 feeds :-)

闯ü谤驳别苍


Re: About commissionReport.realizedPNL

 

?The various options for PNL feeds are described in

闯ü谤驳别苍

On Tue, Aug 2, 2022 at 02:17 AM, <david03kimo@...> wrote:

Thanks,I think your quick example is exact what I want.
I'd like to know what callback function do you use to get realizedPNL without?commission reports?


Re: Best method for getting level 2 market depth snapshots on a large number of equities

 

I would have used the same approach and cannot see a way to do it differently. How long does it take to grab a snapshot for 30 instruments?

When you are done with a snapshot it will take a while for your request to be finalized. TWS sees it right away, but I am sure they won't add the feed back to the "available" pool until TWS receives a cancellation confirmation from the IBKR back-end. So I am not surprised that the next might get denied until TWS has received a cancellation confirmation from IBKR. Unfortunately, has no callback that indicates to you when it is safe to make the next request. This could potentially be an ongoing area of instability.

The hard limit for the number of simultaneous Level 2 streams must have been increased, since now says you can have up to 60. But you can only get 10 of them by purchasing booster packs. To get to 60 you must have enough equity or commission to "earn" them.

According to the fine print in

  • "There is no cap on the quantity of market data lines allocated per customer."
  • You get one market line per $8 in monthly commissions
  • Or for each $10,000 in equity

If my math is correct, $48,000 in monthly commission or an account value of $60Mio gets you to the 6,000 market line allocations you'd need for 60 simultaneous market depth feeds. Or half of that for 30 feeds :-)

闯ü谤驳别苍


Re: About commissionReport.realizedPNL

 

Thanks,I think your quick example is exact what I want.
I'd like to know what callback function do you use to get realizedPNL without?commission reports?


--


------
Forex trader
David Liao


Re: No historical market data for AAL/STK@VALUE Last 1d

 

When you say "I'm retrieving the contract object fresh" are you talking about reqContractDetails? If so, how many contracts does the request return?

When I ask for AAL:STOCK (no other fields initialized in the query contract) I get 31 contracts for three instruments:

  • 25 contracts relate to "AMERICAN AIRLINES GROUP INC" (conid 139673266) for the various exchanges it is listed on
  • 5 contracts relate to "ANGLO AMERICAN PLC" (conid 45024954)
  • 1 contract is for "AVIAAM LEASING AB" (conid 285940697)

Only that last contract for "AVIAAM LEASING AB" trades on the VALUE exchange. Any chance wires might get crossed and the historical data request sees that contract?

Attached a quick CSV with the contracts I get.

闯ü谤驳别苍

On Tue, Aug 2, 2022 at 12:02 AM, David Walker wrote:

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?


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):

  • It facilitates a code structure that "separates concerns". Meaning that you have a small specialized module that knows everything that needs to be known about instruments, trading hours, exchanges, and other contract object details. It knows the many things that can go wrong and what to do in case something does, and applies in a central location all validations and safety checks you care about. You don't want to realize during an urgent position close attempt that something has changed and the contract is no good for trading.
  • You are correct that reqContractDetails also needs a contract object for the request, but it has a different function, is more human oriented, and you can provide fewer details than what you'd need for placing orders or other API requests (machine usable). You can specify the instrument in the most convenient way for you (local symbol, CUSIP/ISIN, conid, ...) and, if that makes sense, you can even ask for all contracts of a certain type (say all active futures of a certain type, or the contracts for all currencies of a stock, ...) and you get trade hour details for the current session and the next week or so. Are you really sure you know all rules for trading around holidays and other, possibly short notice, trade hour changes?
  • take a look at Richard King's ContractInspector that you can get at . The ContractInspector allows to explore what reqContractDetails can do for you without having to create code first.

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 闯ü谤驳别苍

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

 

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 闯ü谤驳别苍

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.