¿ªÔÆÌåÓý

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

TWS option "Never Lock Trader Workstation" no longer available in version 10.26 ?

 

After upgrading Trader Workstation software recently, the Global option "Never Lock Trader Workstation" is no longer available. Now the only option available is "Lock Trader Workstation after 30 minutes of Inactivity".

I wonder if other users have the same experience after upgrade ?
The version I have after upgrade is : Build 10.26.1i, Dec 5, 2023


Re: Running the TWS Python API Multi-threaded?

 

You will get error code 100 if you actually go over the IBKR limit of 50 messages/second (not minute). So if you don't get that, source of your issue is likely code efficiency. You can multi-thread, but like other guy mentioned, based on your description, does not seem necessary.


Re: Market subscription

 

I do not believe there is. There is a error code 354 if you try and subscribe to data you do not have.


Re: How to access L2 Options Data with ib_insync? Or with other tools? Logs included

 

Just to make sure, can you verify on client platform (TWS) if you see L2 on the option you are testing?


Re: How to access L2 Options Data with ib_insync? Or with other tools? Logs included

 

I found my first issue, not all exchanges support the deep market data, now I found the list of supported exchanges and I'm trying to get META Option Deep Market Data however it's still not giving anything but doesn't throw the earlier error.

The new error is saying that, requested data is not subscribed, however I did subscribe to AMEX Options L2 Data, and the exchange on the contract is AMEX. Any idea what might be wrong??

?

Maybe there is not deep market data when market is closed or I'm truly not?subscribed.


How to access L2 Options Data with ib_insync? Or with other tools? Logs included

 

I'm trying to access the market-depth data for options, I subscribed to NYSE Arca Options Data however I'm not able to access the data, i tried for SPX, below are the relevant info:

option:

Option(conId=586551475, symbol='SPX', lastTradeDateOrContractMonth='20240118', strike=200.0, right='C', multiplier='100', exchange='CBOE', currency='USD', localSymbol='SPX ? 240119C00200000', tradingClass='SPX')


ticker:
Ticker(contract=Option(conId=586551475, symbol='SPX', lastTradeDateOrContractMonth='20240118', strike=200.0, right='C', multiplier='100', exchange='CBOE', currency='USD', localSymbol='SPX ? 240119C00200000', tradingClass='SPX'))

error:
Error 10092, reqId 7: Deep market data is not supported for this combination of security type/exchange, contract: Option(conId=586551475, symbol='SPX', lastTradeDateOrContractMonth='20240118', strike=200.0, right='C', multiplier='100', exchange='CBOE', currency='USD', localSymbol='SPX ? 240119C00200000', tradingClass='SPX')

[] []

[] []


Re: TwsSocketClient c++ Exception thrown: read access violation

 

I don't run the DLL version and use static lib to ease maintenance. (paradox maybe) So hereafter are suggestion only.
You may have an issue related to your method in building project (not sure project directory are insulated by kind), or an issue with a missing Compile directive to export DLL methode.

0- Clean your whole project and then ONLY compile one project at time (TestSocketClient, check that the DLL now appears, then compile TestCppClient)

1- Your stack dump and screen shoot (too low res) deal with Microsoft strlen CRT code itself, which frankly is not an interesting one.?
Code crashed in strlen trying to access an invalid buffer. ('host')
This is strange because you seems to get back from eConnect with bRes == true hence TestCppClient object should exist (eConnect does fill m_host and it should crash in setHost method if something wrong. unless eConnectImpl mess up)

In Debug mode, setup VS to display the debug tab "Auto", this would give a view of 'variable of interest' hence a better clue on what is inside m_pClient.
once stop or crashed, click on call stack for TestCppClient.exe!TestCppClient::connect? that will fill stack context of "Auto" which help way more than strlen.

2- First thing I would check is the reality of the pointer to the object m_pClient,
does it exist ? still or ever ?
At beginning of TestCppClient::connect(.....) add some tests,
_ASSERTE(_CrtIsValidPointer(this,sizeof(*thisTRUE));
_ASSERTE(_CrtIsValidPointer(m_pClient,sizeof(*m_pClient),TRUE));

And for now
1- put a break point in 'bool EClientSocket::eConnect' on' ? return eConnectImpl( clientId, extraAuth, &resState);'
and see if this->m_host look valide string wit relevant content before AND also still after call to
eConnectImpl()

2- put a break point in your code at the printf to look at the
m_pClient and see what the debugger give you as object content,
if gibberish, more likely you have an issue with the creation/heap alloc or transmission of this object.

3- Compare
m_pClient? between project 'static' with 'DLL' content to educate your opinion



Market subscription

 

Hi all,

Is there a way to see which market-subscription you have by an API call?

Kind regards


TwsSocketClient c++ Exception thrown: read access violation

 

Hi,

I am using version: 10.19.02 of the C++ API.
When I run the "TestCppClient" program
the following error is received:

Exception thrown: read access violation.
**it** was 0x2E302E30.
The line in the code that crashes the program:
printf( "Connected to %s:%d clientId:%d\n", m_pClient->host().c_str(), m_pClient->port(), clientId);

The program tries to access this string:
m_pClient->host()
and the program crashes.

But when I run the program: "TestCppClientStatic"
The program ran without crashing.

I would appreciate your help, how can I run the
The program "TestCppClient" without the above error.

Call Stack:

> ucrtbased.dll!common_strnlen_c<0,unsigned char>(const unsigned char * const string, const unsigned int maximum_count) Line 72 C++
? ucrtbased.dll!common_strnlen_simd<0,1,unsigned char>(const unsigned char * const string, const unsigned int maximum_count) Line 130 C++
? ucrtbased.dll!common_strnlen<0,unsigned char>(const unsigned char * const string, const unsigned int maximum_count) Line 185 C++
? ucrtbased.dll!strnlen(const char * string, unsigned int maximum_count) Line 203 C++
? ucrtbased.dll!__crt_stdio_output::output_processor<char,__crt_stdio_output::console_output_adapter<char>,__crt_stdio_output::positional_parameter_base<char,__crt_stdio_output::console_output_adapter<char>>>::type_case_s_compute_narrow_string_length(const int maximum_length, char __formal) Line 2353 C++
? ucrtbased.dll!__crt_stdio_output::output_processor<char,__crt_stdio_output::console_output_adapter<char>,__crt_stdio_output::standard_base<char,__crt_stdio_output::console_output_adapter<char>>>::type_case_s() Line 2340 C++
? ucrtbased.dll!__crt_stdio_output::output_processor<char,__crt_stdio_output::stream_output_adapter<char>,__crt_stdio_output::standard_base<char,__crt_stdio_output::stream_output_adapter<char>>>::state_case_type() Line 2066 C++
? ucrtbased.dll!__crt_stdio_output::output_processor<char,__crt_stdio_output::stream_output_adapter<char>,__crt_stdio_output::standard_base<char,__crt_stdio_output::stream_output_adapter<char>>>::process() Line 1704 C++
? ucrtbased.dll!common_vfprintf::__l2::<lambda>() Line 48 C++
? ucrtbased.dll!__crt_seh_guarded_call<int>::operator()<void <lambda>(void),int <lambda>(void) &,void <lambda>(void)>(__acrt_lock_stream_and_call::__l2::void <lambda>(void) && setup, common_vfprintf::__l2::int <lambda>(void) & action, __acrt_lock_stream_and_call::__l2::void <lambda>(void) && cleanup) Line 204 C++
? ucrtbased.dll!__acrt_lock_stream_and_call<int <lambda>(void)>(_iobuf * const stream, common_vfprintf::__l2::int <lambda>(void) && action) Line 301 C++
? ucrtbased.dll!common_vfprintf<__crt_stdio_output::standard_base,char>(const unsigned __int64 options, _iobuf * const stream, const char * const format, __crt_cached_ptd_host & ptd, char * const arglist) Line 37 C++
? ucrtbased.dll!__stdio_common_vfprintf(unsigned __int64 options, _iobuf * stream, const char * format, __crt_locale_pointers * locale, char * arglist) Line 61 C++
? TestCppClient.exe!_vfprintf_l(_iobuf * const _Stream, const char * const _Format, __crt_locale_pointers * const _Locale, char * _ArgList) Line 645 C++
? TestCppClient.exe!printf(const char * const _Format, ...) Line 960 C++
? TestCppClient.exe!TestCppClient::connect(const char * host, int port, int clientId) Line 75 C++
? TestCppClient.exe!main(int argc, char * * argv) Line 48 C++
? TestCppClient.exe!invoke_main() Line 78 C++
? TestCppClient.exe!__scrt_common_main_seh() Line 288 C++
? TestCppClient.exe!__scrt_common_main() Line 331 C++
? TestCppClient.exe!mainCRTStartup(void * __formal) Line 17 C++
? kernel32.dll!75e67ba9() Unknown
? [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
? ntdll.dll!7747bd2b() Unknown
? ntdll.dll!7747bcaf() Unknown
File:
strlen.cpp




Thanks in advance
?


Re: No or delayed response on placed orders using IB Python API TWS 10.19 on Linux EC2

 

Definitely not in the api thread.
What do you mean by your own queue? Are you sure this is thread safe? Most probably your problem stems from this. If your queue is not fast enough or prone to race, it will give you the delays that clutter the api queue.


Re: No or delayed response on placed orders using IB Python API TWS 10.19 on Linux EC2

 

In which function are you running this bit of code? Inside the EWrapper callbacks (ie tickSize, tickPrice etc)?
If you do time.sleep() on the api thread, wouldn't messages get lost when they are sent to you but not received?

Btw my solution was to not do any handling of the messages received in the callbacks, but instead enqueue them to my own queue, then handle that queue at a later time in a different thread.


Re: No or delayed response on placed orders using IB Python API TWS 10.19 on Linux EC2

 

If your instance of IBapi() is called app like mine, in every thread I check app.msg_queue.qsize().?
Make sure to use semaphores, as the .qsize() reading itself can create race if a few threads try to do it all at once.
Here is how I do it:
?
with semaphore_apiq:
?
len_var = app.msg_queue.qsize()
?
log_msg = symbol + ' ### length of api msg_queue: ' + str(len_var)
?
logger.info(log_msg)
?
info_dict['api_qsize'] = str(len_var)
?
if len_var > max_len_var:
?
max_len_var = len_var
?
info_dict['max_api_qsize'] = str(max_len_var)
?
if len_var > 100: # delay to sort backlog
?
time.sleep(random())
?
In effect, if the queue grows to over 100 messages, the thread is pause for up to 1 sec letting callbacks work its course.
?
I am sure this is not the smartest solution, and I don't like it, but it works apparently. Maybe you or someone can come up with a better idea, please do share.


Re: No or delayed response on placed orders using IB Python API TWS 10.19 on Linux EC2

 

Hi,
Thanks for the response, race conditions were my initial concern. Mind explaining how would I go about monitoring the api message queue and keep race conditions from happening?


Re: Running the TWS Python API Multi-threaded?

 

IMHO this is hardly possible unless you're ready to rewrite the api itself. Anyway 10-20 trades per minute is not much. What's your current time per "a trading logic cycle"? I now have around 50ms per check if no transaction is triggered, or around 150ms if there is a trade triggered. Which is enough to make 5-6 trades per second, and should be definitely enough to make the same in a minute. Review your code for holes, especially paying attention where and how you process incoming messages. The correct approach seems to be "unload first, process later", as trying to process messages within callback functions hold the queue, so I would keep that to the bare minimum.


Re: No or delayed response on placed orders using IB Python API TWS 10.19 on Linux EC2

 

For me the delay happened on race conditions when unloading the api message queue. Once I found a way to monitor it, I have noticed it could grow to thousands of unprocessed messages, which caused the delay. Make sure it's not get cluttered, I used semaphores etc. to make sure different threads do not race on the same queue. Now it never happens.


Re: Unrealisedpnl

 

Yes @biney59? does same as I, you have to compute it.

1- it's simple enough

2- It's somewhere a real time information related to latest Bid or Ask depending upon your trade direction. (as current ticker price)
You can use latest price, give a good enough clue, since this will stay an hypothesis until your really close your position.

3- There could be some subtleties in the way IB does compute it, as IB may also incorporate some other revenues, like on stocks if you rent your shares. (not sure about that, just that I am not expecting to find exactly same figures as they delivers)


Running the TWS Python API Multi-threaded?

 

I am running a trading strategy that gathers data from many different instruments, and can make 10-20 trades in a matter of minutes. Sometimes the order don't get filled so there can be a high load on the api with many messages coming in at once, and I suspect it might cause some problems.

One solution I am looking at is making my app more multi-threaded. I think the most basic would be to separate the data subscriptions streams from the orderStatus, orderExecution etc callbacks.
Is this possible, and how?


Re: automatic adjustment of stop limit in bracket order based on fill price

 


Re: automatic adjustment of stop limit in bracket order based on fill price

 

There is no API that gives this automatically. The basic idea would be to have execution callback handler monitor fill average price, and re-adjust order after that.


Re: Unrealisedpnl

 

Unrealized PnL is basically ( avg_position_price - current_ticker_price ) * position_size for longs, and ( current_ticker_price?- avg_position_price?) * position_size for shorts.