¿ªÔÆÌåÓý

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

Re: TWS API 10.20 c++ windows

Franco Chiesa Docampo
 

¿ªÔÆÌåÓý

Thank you!

El 31 ene. 2023, a la(s) 23:49, David Armour <dave.armour@...> escribi¨®:

The TWS API source code comes with Visual Studio solution files which would only work with Visual Studio (not Visual Studio Code).

You would have to make all the configs yourself to get running in VS Code but why bother when VS is also free and far better for debugging.

Note someone mentioned below about switching to Win32. This is because the .SLN file only comes with Win32 configs but it is really easy to create x64 configs. Basically just duplicate the Win32 configs under x64.

I use TWS API C++ under Visual Studio 2020 Preview with C++ Latest standard set with x64 configs and never have any problems. The biggest headache of recent has been the switch to DECIMAL. For that I use VCPKG and installed the "intelrdfpmathlib"? which covers all the Decimal Floating Point Math libraries you will need.
_._,_._,_


Re: eroor 322 errorMsg "Error processing request.-'bW' : cause - Duplicate ticker id"

 

?I understand now. Yes I moved it outside to the main class and set counter as private so now it works fine


On Sun, Jan 29, 2023, 11:49 AM Dmitry Shevkoplyas <shevkoplyas@...> wrote:
Hi Liu,

The "foreach" execute nested code block concurrently.
Your code has "counter" incremented in one line and then used in another line.
The "counter" variable is shared across all you (many) code blocks expected in parallel, which means that between incrementing and later using your 'counter" another similar block (working in parallel) might sometimes be lucky to increment the same shared "counter" one more time, thus both blocks of code will send the request with the same Id.

When you're trying to debug this with breakpoints?and step-by-stem?execution it is millions time slower and it is completely different run-mode, thus you have close to zero chances?to witness that particular behaviour.

Unfortunately ´³¨¹°ù²µ±ð²Ô's suggestion to move counter increment into the separate f-n won't change anything - you'll still get duplicates from time to?time.

Cheers,
Dmitry

On Fri, Jan 27, 2023 at 8:40 PM ´³¨¹°ù²µ±ð²Ô Reinold via <TwsApiOnGroupsIo=[email protected]> wrote:

Well, somewhere in your program an API request is made with a duplicate requestId or tickerId. The error callback should give you the exact id at fault.

"reqId + counter" is a bad idea. You should have a function, such as nextRequestId(), that provides a new and unique Id every time the function is called. It is sufficient that the function simply returns the value of an incremented variable such as (pseudo language):

private integer _nextRestId = 10000000;
funtion integer nextRequestId()
{
??? return _nextRequestId++;
}


We found it helpful to start request Ids at a high number so that they cannot be confused with orderIds.? But "_nextRestId? = 1" will work just fine.

Now, every API request (not just reqMktData) gets a unique Id by a call to nextRequestId().

´³¨¹°ù²µ±ð²Ô


How to close very OTM Long options after disassembling one Iron Condor

 

Hi there!

I wonder if any of you have solved this problem or has any clues to try to solve it altogether:

I need to close two Long OTM options positions (which worked as a cover of an Iron Condor) after the SHORT legs combo is executed. as the Long legs are very OTM they usually?have no bid price (so you can not always sell them inside a 4 leg combo).

Example?

1) IC bought:
1? SPX? 4100C
-1 SPX? 4050C
-1 SPX? 4005P
1? SPX? 3955P

2) After I got into the position I place the exit disassembled combo order (just two legs) with SL price to exit the position:
-1 SPX? 4050C
-1 SPX? 4005P

3) after?position 2) the exit combo is executed/closed
This is what I can not solve:
I want to close/sell each of the long legs remaining: 4100C and 3955P (without having to monitor it) By attaching an order or creating a conditional order or any other way to close the position without having a program/algorithm to check this.

I've tried to add child orders of each of the legs, but needs to be the same type (combo) I tried Hedge legs but just get one closed and the other one cancelled

Have any of you have successfully?done this? Any workarounds, please?


Thank you


Re: TWS API 10.20 c++ windows

 

*** CORRECTION TO ABOVE ***

I use Visual Studio 2022 Preview....


Re: TWS API 10.20 c++ windows

 

The TWS API source code comes with Visual Studio solution files which would only work with Visual Studio (not Visual Studio Code).

You would have to make all the configs yourself to get running in VS Code but why bother when VS is also free and far better for debugging.

Note someone mentioned below about switching to Win32. This is because the .SLN file only comes with Win32 configs but it is really easy to create x64 configs. Basically just duplicate the Win32 configs under x64.

I use TWS API C++ under Visual Studio 2020 Preview with C++ Latest standard set with x64 configs and never have any problems. The biggest headache of recent has been the switch to DECIMAL. For that I use VCPKG and installed the "intelrdfpmathlib"? which covers all the Decimal Floating Point Math libraries you will need.


Re: TWS API 10.20 c++ windows

Franco Chiesa Docampo
 

¿ªÔÆÌåÓý

Hi Andrew, does this work for Visual Studio Code?

Cheers,
Frank

El 31 ene. 2023, a la(s) 16:43, Andrew Bannerman <bannerman1985@...> escribi¨®:

?Good to hear :)?

Regards
Andrew


Re: TWS API 10.20 c++ windows

 

Good to hear :)?

Regards
Andrew


Re: TWS API 10.20 c++ windows

 

Hello Andrew,

thank you frr this hint, now i can compile it.


Best Regards
Thobi?


Re: TWS API 10.20 c++ windows

 

Try loading the project with visual studio - then when loaded on main file - up top drop down win32. That worked for me.


Re: Live Cattle No security definition has been found for the request

 

Hello Jurgen,

Thank you, I have no idea why I did that, I think I have not use a futures contract for a while and just mess up

Thank you

Carlos


-----Original Message-----
From: ´³¨¹°ù²µ±ð²Ô Reinold via groups.io <TwsApiOnGroupsIo@...>
To: [email protected]
Sent: Tue, Jan 31, 2023 11:47 am
Subject: Re: [TWS API] Live Cattle No security definition has been found for the request

The time format you use for lastTradeDateOrContractMonth is incorrect. Check the in the for the correct use.
You can also make your life easier by simply using localSymbol, such as LEH3 for the current front month, along with secType FUT and Exchange CME.
´³¨¹°ù²µ±ð²Ô


Re: Live Cattle No security definition has been found for the request

 
Edited

The time format you use for lastTradeDateOrContractMonth is incorrect. Check in the for the correct use.

You can also make your life easier by simply using localSymbol, such as LEH3 for the current front month, along with secType FUT and Exchange CME.

´³¨¹°ù²µ±ð²Ô


Live Cattle No security definition has been found for the request

 

Hello,
I looked the messages here to see if anyone got this before.
Using API 10.20, TWS 10.20.01.
I am trying to get live data for Live Cattle using the following contract parameters, do not work, I am getting the error

"No security definition has been found for the request", do anyone knows what I am missing the contract parameters?
Thank you
CONTRACT PARAMETERS USED.
symbol LE
secType FUT
Exchange CME
lastTradeDateOrContractMonth 022023
?
or
?
symbol LE
secType FUT
Exchange CME
lastTradeDateOrContractMonth 022023
Multiplier 40000
?
or
?
symbol LE
secType FUT
Exchange CME
lastTradeDateOrContractMonth 042023
?
or
?
symbol LE
secType FUT
Exchange CME
lastTradeDateOrContractMonth 042023
Multiplier 40000
?
?


TWS API 10.20 c++ windows

 

Hello,

i have a basic question and i am sure this is boring for the most of you but I NEED YOUR HELP.

I am using the API since years but til now i have used an old on.
The old API software i have c# and coliped it with nmake. No problem on this.

NOW, i have to switch to API 10.20.
And i have problem to compile the c++ code on windows.

Did anyone of you have a good dicription that a normal people like me ould understand an can compile the 10.20 API c++ on windows.

I would be very thankful if anyone of you could send me some information.

Sorry again for this basic question.


Best regards
Thobi


Re: historical futures quotes for expired contracts

 

Although you don't mention which error message(s) you are getting, last time I checked you needed to set the end date/time parameter in the historical data request call to a date/time within the life of the expired futures contract (preferably near, or at, the expiration date of the contract). Hope this helps.

--


Re: historical futures quotes for expired contracts

 

While it worked overall--obtaining quotes for expired futures contracts---, your suggestion of combining (local?)symbol and exchange hasn't worked for me specifically because I did some custom modification to the 2019 version api which requires going under the hood. but not urgent at present.? For longest my practice has been locking it down with conId. But since I have the data I need, for now I am good.? Additionally, sometime last year, there was a huge IB move of futures contracts between exchanges-- from GLOBEX to CME which factored in my query.? Thank you kindly for your help and flexible thinking!


reqMktData returning wrong tickPrice for Index

 

Hi,
I am from India and trading on Indian Exchange (NSE) leveraging TWS API. Today, I have received a wrong NSE Banknifty index tick data at 2023-01-30 15:10:01,031. Please refer the log below
2023-01-30 15:10:01,031 ibapi.wrapper - INFO - ANSWER tickPrice {'reqId': 9, 'tickType': 4, 'price': 40103.0, 'attrib': 140654527663168: CanAutoExecute: 0, PastLimit: 0, PreOpen: 0}
The price report was 40103.0 which is completely wrong. Infact, it was trading around 40327

I have used reqMktData as below -
self.ibkr_app.reqMktData(reqId=evt_id,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? contract=self._getUnderlyingContract(instr),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? genericTickList="",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? snapshot=False,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? regulatorySnapshot=False,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? mktDataOptions=[])

Within one milisecond, I received the right price though, i.e. 40327 -
2023-01-30 15:10:01,032 ibapi.wrapper - INFO - ANSWER tickPrice {'reqId': 9, 'tickType': 4, 'price': 40327.0, 'attrib': 140654527663168: CanAutoExecute: 0, PastLimit: 0, PreOpen: 0}

1. May I know if this is normal to receive such wrong data intermittently ? And how should it be handled in the program ?
2. What is the best practice to receive market data repeatedly ?

Thanks,
Souvik


Re: historical futures quotes for expired contracts

 

What data are you trying to request and what error do you get?

Just tried 1min bars through reqHistoricalData for a few days in February 2022 and promptly got 8,000++ records back.

Making your own Contract objects is often hit or miss since you never know exactly which Contract object fields IBKR expects for the various requests. And there are differences between historical data, tick by tick data, and order placement.

A best practice is that you call (as described in ) and use the contract object they return for your requests. You can, for example, request the contract by symbol and exchange (such as 6MH2 and CME) or just the conId (as I did since you had provided it)

´³¨¹°ù²µ±ð²Ô


On Sun, Jan 29, 2023 at 11:28 PM, tessse2 wrote:
hi, anyone have any luck obtaining Historical data for Expired Futures Contracts???Trying to get historical futures quotes for expired contracts for currencies below.??Subscribed to Level I market data.? What I am missing?? Already added criteria?contract.includeExpired(true).? -- Any updates/changes.??Thanks.
?
Looking for year 2022 only.
Mexican Peso
Canadian Dollar
?
?
///================
? ? public static Contract MXP_FXFutureContract() {
? ? ? ? Contract contract = new Contract();
? ? ? ? contract.symbol("MXP");
? ? ? ? contract.secType("FUT");
? ? ? ? contract.currency("USD");
? ? ? ? contract.exchange("CME");
? ? ? ? contract.lastTradeDateOrContractMonth("20220314");
? ? ? ? contract.conid(439961927);
? ? ? ? contract.includeExpired(true);
? ? ? ? return contract;
? ? }
?


historical futures quotes for expired contracts

 

hi, anyone have any luck obtaining Historical data for Expired Futures Contracts???Trying to get historical futures quotes for expired contracts for currencies below.??Subscribed to Level I market data.? What I am missing?? Already added criteria?contract.includeExpired(true).? -- Any updates/changes.??Thanks.
?
Looking for year 2022 only.
Mexican Peso
Canadian Dollar
?
?
///================
? ? public static Contract MXP_FXFutureContract() {
? ? ? ? Contract contract = new Contract();
? ? ? ? contract.symbol("MXP");
? ? ? ? contract.secType("FUT");
? ? ? ? contract.currency("USD");
? ? ? ? contract.exchange("CME");
? ? ? ? contract.lastTradeDateOrContractMonth("20220314");
? ? ? ? contract.conid(439961927);
? ? ? ? contract.includeExpired(true);
? ? ? ? return contract;
? ? }
?


Re: I am trying to setup IBAPI for interactive brokers using python 3 and pycharm

 

I realize this is an old thread, but I'm responding anyway, as it may help someone who runs into this in the future.

I was running fine until I decided to upgrade from python 3.10 to 3.11. I reinstalled the TWS API, but it continue to complain that IBAPI is not installed. The problem in my case was the multiple python versions. I set the path to default to python 3.11. Checked to make sure that it was defaulting to 3.11 by checking the version when I run python from the command-line. Then I ran C:\TWS API\source\pythonclient\setup.py again. Restarted VS Code and it works fine now.


Re: eroor 322 errorMsg "Error processing request.-'bW' : cause - Duplicate ticker id"

 
Edited

I don't understand your comment, Dmitry, why centralizing the ID generation still can get duplicate IDs.

I presented a pseudo language example but every language has concepts that make nextRequestId() a strictly monotonically increasing function. In other words, each call returns a number this is higher than all other numbers returned before and no number will ever be returned again. And that is guaranteed regardless of how many threads and loops execute in parallel.

In Java, for example, you can simply declare the function as public synchronized or use an AtomicInteger instead of simply int. For many years we run applications with many parallel threads on systems with several processors and have never seen error 322.

Now, the real solution here is an application architecture that completely removes request Ids (and other API details) from the business logic. Such as wrapping a thin controller layer around TWS API calls so that these implementation details are completely hidden from client code. A good example is the ApiController class that is part of the TWS API Java version. So, instead of calling the TWS API method

reqMktData( int tickerId, Contract contract, String genericTickList, boolean snapshot, boolean regulatorySnapshot, List<TagValue> mktDataOptions )

and having to manage request ids and having to implement routing code for returned data by requestId to your appropriate logic you simply call

reqTopMktData( Contract contract, String genericTickList, boolean snapshot, boolean regulatorySnapshot, ITopMktDataHandler handler )

and the controller automatically routes the data stream directly to your handler function.

Or look at Ewald de Wit's very well architected ib_insync Python library, and you receive the subscribed data streams via asynchronous events whenever they arrive.

´³¨¹°ù²µ±ð²Ô


On Sun, Jan 29, 2023 at 10:49 AM, Dmitry Shevkoplyas wrote:

Hi Liu,
?
The "foreach" execute nested code block concurrently.
Your code has "counter" incremented in one line and then used in another line.
The "counter" variable is shared across all you (many) code blocks expected in parallel, which means that between incrementing and later using your 'counter" another similar block (working in parallel) might sometimes be lucky to increment the same shared "counter" one more time, thus both blocks of code will send the request with the same Id.
?
When you're trying to debug this with breakpoints?and step-by-stem?execution it is millions time slower and it is completely different run-mode, thus you have close to zero chances?to witness that particular behaviour.
?
Unfortunately ´³¨¹°ù²µ±ð²Ô's suggestion to move counter increment into the separate f-n won't change anything - you'll still get duplicates from time to?time.
?
Cheers,
Dmitry

On Fri, Jan 27, 2023 at 8:40 PM ´³¨¹°ù²µ±ð²Ô Reinold via <TwsApiOnGroupsIo=[email protected]> wrote:

Well, somewhere in your program an API request is made with a duplicate requestId or tickerId. The error callback should give you the exact id at fault.

"reqId + counter" is a bad idea. You should have a function, such as nextRequestId(), that provides a new and unique Id every time the function is called. It is sufficient that the function simply returns the value of an incremented variable such as (pseudo language):

private integer _nextRestId = 10000000;
funtion integer nextRequestId()
{
??? return _nextRequestId++;
}


We found it helpful to start request Ids at a high number so that they cannot be confused with orderIds.? But "_nextRestId? = 1" will work just fine.

Now, every API request (not just reqMktData) gets a unique Id by a call to nextRequestId().

´³¨¹°ù²µ±ð²Ô

?

?