¿ªÔÆÌåÓý

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

Re: API error - Your API version does not support fractional size rules (during forex price extraction)

 

There are really no settings you can change. You would have to use a TWS API Version of at least "163" for any of the fractional size rules to work. rossh_yh mentioned that "163" is available in TWS API V10.10 and later. And it sounds like IBKR now requires fractional size support for AUD.USD real-time data.

The way this works internally is that IBKR introduces new features and increments the internal API version number. When your client connects to TWS/IGW, the two determine the highest common API version. That way, a client with a very old API version can work just fine with brand new TWS/IBGW as long as the client only utilizes features from it's version level and below. Feature 163 is called MIN_SERVER_VER_FRACTIONAL_SIZE_SUPPORT. You can find the list of the features in the API source code
  • for C++ in "CppClient/client/EDecoder.h"
  • for C# in "CSharpClient/client/MinServerVer.cs"
  • for Java in "JavaClient/com/ib/client/EClient.java"
  • for Python in "pythonclient/ibapi/server_versions.py"

Your client can also be aware of the maximum API version it understands and, after connection with TWS/IBGW, the highest common version. This is somewhat language dependent again, but in python, for example, these two lines below should be able to print the API version for you and it should print a number of 163 or higher for fractional siye support.

from ibapi.server_versions import *
print( MAX_CLIENT_VER )

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

PS. Excuse my PSL level python skills (Python-as-a-Second-Languge) but we speak Java at home



On Tue, Jan 3, 2023 at 03:31 PM, Mark Murari wrote:
Thanks Jurgen for the very comprehensive answer which is much appreciated. I need to dig around and figure out why this change is preventing specifically the download of Audusd Forex contract. It seems not to affect any other currency pair except Aud. I am using the python api so not clear what setting needs to be changed to allow the download to work.


Re: Building up a C++ Client

 

Did you try the IB exemple ?

From your code I wonder where is the reader thread launched. look for eConnectImpl and see what is inside
Raw from my notes: (written as ongoing job, not sure 100% accurate and can be cryptic)
/* Discussion:

The IB telco is not perfectly thread safe
I feel the "connect" is not safe enough to re-connect from within a thread.
need a lock to avoid 2 connect at same time on same gate_c

gate_c connection Principle
1- Create a connection
bool gate_c::connect()
?? ?m_pClient->eConnect(m_sHost.c_str(), m_iPort, m_iClientId, m_extraAuth);
?

2- Open a connection actutator
?? ?EClientSocket::eConnectImpl(int clientId, bool extraAuth, ConnState* stateOutPt)
?? ?which contain the
?? ?m_fd = (int /*glh++* /)socket(AF_INET, SOCK_STREAM, 0);
?? ?and the
?? ?if( (connect( m_fd, (struct sockaddr *) &sa, sizeof( sa))) < 0)
?? ?
3- See EClientSocket::eConnectImpl needed to get a first request sent
?? ?it use a heap EReader one time use to get Server version
?? ?Note: EReader object are protected by it's own Mutex m_csMsgQueue for thread safety.
?? ?And use a std::unique_ptr<ETransport> to access Connection info
?? ?See EReader::putMessageToQueue()
?? ????
4- Create the official permanent "reader"
?? ?m_pReader = new EReader
?? ?m_pReader->start();
?? ?
5- Which Launch independant reader thread
?? ?m_hReadThread = CreateThread(0, 0, readToQueueThread, this, 0, 0);

6- ??? Writer is part of Main thread that own gate_c
?? ?Reader have it's own recv then dispatch.


Note:
EReader reader can be used in main thread if not calling ->start()
Note:
EReader object are protected by there own Mutex m_csMsgQueue for thread safety.

*/


Re: trouble linking twsapi

 

I guess it's because you use 000, which if I remember well require that you call by reference.
Try 100

I use
Look at the readme and bid_conf.h
Makefile does generate a bunch of variety of lib to deal with various implementation and calling convention.

Things like
First digit require that you do use calling by reference. 100 is by value etc ...
Second digit is rounding options.
Third is about a global config for some implementation definition of exception.

I think I use 100blibbid
I use "by value" because the hidden type is 64 bits, which is same size as a ptr (64 bit cpu), it help (marginally) compilers to optimize procedure.

so either you learn the naming convention of the lib(s) you need,
or workaround you directly put the source file of the "Decimal" lib in your IBKR lib project compile and debug to see if it fits your calling convention.
There are only a dozen .c files needed. Not pretty but allow easier debug of it.


Re: API error - Your API version does not support fractional size rules (during forex price extraction)

 

¿ªÔÆÌåÓý

Thanks Jurgen for the very comprehensive answer which is much appreciated. I need to dig around and figure out why this change is preventing specifically the download of Audusd Forex contract. It seems not to affect any other currency pair except Aud. I am using the python api so not clear what setting needs to be changed to allow the download to work.


On 3 Jan 2023, at 20:43, ´³¨¹°ù²µ±ð²Ô Reinold via groups.io <TwsApiOnGroupsIo@...> wrote:

?

There have been many changes between TWS API V9 and V10, but the one with the most impact is the transition of most "size" fields in classes and method signatures from "int/long" or "double" types to a "Decimal" data type. You need to look at the TWS API source code for the language you are using so see what that means exactly for you, since their approach was a little different for each language. Take a look, for example, at the totalQuantity or filledQuantity fields of the Order class in one of the more recent V10 versions.

"Decimal" math assures stability to the right of the decimal point/comma well beyond what floating point math can achieve. That became important with the introduction of fractional shares and crypto trading. You don't want to lose a small fortune just because trade quantities accumulate impressions every time you do a simple math operation.

Even a simple addition such as 1.123 plus 1.456, for example, cannot be done precisely in binary floating point math::
  • You would get 2.5789999961853027 in standard "four byte float" math
  • You would get 2.5789999999999997 in standard "eight byte double" math.
  • While you get the expected 2.579 with a "Decimal" data type

"Decimal" types are generally more cumbersome to work with, though, since have to call methods even for simple arithmetic functions such as a.plus( b ).multiplyBy( c ). But details, as I said, are language specific.

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

On Tue, Jan 3, 2023 at 11:02 AM, Mark Murari wrote:
"IB support mentioned they changed the variable type of AUD.USD to decimal"

Having this issue myself. Could someone please shed some light on what is a 'decimal' variable type and how does differ from the variable type they used before?

Thanks!


Re: API error - Your API version does not support fractional size rules (during forex price extraction)

 

Atop excellent answer from ´³¨¹°ù²µ±ð²Ô
I may mention some caveats of Decimal from C/C++ perspectives (that may be source of inspiration for other language)

- On 64 bits machine (and I suspect regardless of the OS) the Decimal is hidden under a "long long" (it maybe language dependent although)
Default use can be seen signed as a __int64 for linking.
Warning, this allow some compilers to cast to/from double without any warning!! (can happen too with cast to/from __int64 or uint64_t)

Otherwise said it use 8 Bytes/ number (The official standard allow 32 bits as well as 128 bits encoding aside of 64 bits, I saw IB using it in 64 bits which is default and good enough)
"Decimal" should NOT be caste directly to a simple type as it use a very specific bits organization. (so different from a double or __int64 that it create huge errors that you will not missed on first run).
If you need type conversion, simplest way is go trough Decimal to String then String to double or int or whatever using regular ASCII to float/etc ...) generally fast enough if done only once.

- FYI: Decimal is not an invention from IB, it is standardized and there are various open source lib, like from Intel or IBM to help supporting it. (And IB does supply a Decimal lib with it's example)

- Once in "Decimal" you should stay in Decimal and use Decimal operators.


Re: API error - Your API version does not support fractional size rules (during forex price extraction)

 

There have been many changes between TWS API V9 and V10, but the one with the most impact is the transition of most "size" fields in classes and method signatures from "int/long" or "double" types to a "Decimal" data type. You need to look at the TWS API source code for the language you are using so see what that means exactly for you, since their approach was a little different for each language. Take a look, for example, at the totalQuantity or filledQuantity fields of the Order class in one of the more recent V10 versions.

"Decimal" math assures stability to the right of the decimal point/comma well beyond what floating point math can achieve. That became important with the introduction of fractional shares and crypto trading. You don't want to lose a small fortune just because trade quantities accumulate impressions every time you do a simple math operation.

Even a simple addition such as 1.123 plus 1.456, for example, cannot be done precisely in binary floating point math::
  • You would get 2.5789999961853027 in standard "four byte float" math
  • You would get 2.5789999999999997 in standard "eight byte double" math.
  • While you get the expected 2.579 with a "Decimal" data type

"Decimal" types are generally more cumbersome to work with, though, since have to call methods even for simple arithmetic functions such as a.plus( b ).multiplyBy( c ). But details, as I said, are language specific.

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

On Tue, Jan 3, 2023 at 11:02 AM, Mark Murari wrote:

"IB support mentioned they changed the variable type of AUD.USD to decimal"

Having this issue myself. Could someone please shed some light on what is a 'decimal' variable type and how does differ from the variable type they used before?

Thanks!


Re: trouble linking twsapi

 

Thanks! Pretty surprising that they didn't catch this.

Tried installing the file from??but when I run it for OSX (after having to fix some code in the source files) I get around 16 files in the form "gcc###libbid.a" and "gcc###blibbid.a" where the "###" range from 000 to 111. If I change the makefile link to one of these I can compile the sample TestCppClient comes with the api but get a seg fault when executing the program (which I assume has to do with the libbid file I'm using). Is there a recommended place to find a compatible file?


Re: API error - Your API version does not support fractional size rules (during forex price extraction)

 

"IB support mentioned they changed the variable type of AUD.USD to decimal"

Having this issue myself. Could someone please shed some light on what is a 'decimal' variable type and how does differ from the variable type they used before?

Thanks!


stupid ib authentication

 

It was always quite crap before. You had to open the IB app on your phone in order to get the automated alert to authenticate logging in.

Now even that is broken and I am pissed, I don't want to type in 20 numbers every god damn morning just to login.


Building up a C++ Client

 

I am required to build a C++ IB Feed Handler, This is how I connect to the IBGW Instance :?

?
? bool Connect() noexcept {
? ? LOG(INFO) << "Inside Connect";
? ? if (IsConnected())
? ? ? return true;
? ? if (host_.empty())
? ? ? return false;
?
? ? LOG(INFO) << "Connecting to " << host_ << ':' << port_ << ", client_id:" << client_id_ << '\n';
?
? ? bool bRes = client_socket_->eConnect(host_.c_str(), port_, client_id_, extra_auth_);
?
? ? if (bRes) {
? ? ? LOG(INFO) << "Connected to " << client_socket_->host().c_str() << ':'
? ? ? ? ? ? ? ? << client_socket_->port() << ",ClientID : " << client_id_ << '\n';
?
? ? } else
? ? ? LOG(INFO) << "Cannot connect to " << client_socket_->host().c_str() << ':'
? ? ? ? ? ? ? ? << client_socket_->port() << ",ClientID : " << client_id_ << '\n';
?
? ? return bRes;
? };

I'm able to connect to the IBGW instance using this, i.e. The Connection is ACKED,
but then when I use :

while (active() && IsConnected()) {
? ? ? auto contract_opt = m_provider_.GetNextContract();
? ? ? if (contract_opt.has_value()) {
? ? ? ? LOG(INFO) << "Requesting Contract Details for : " << contract_opt.value().first;
? ? ? ? client_socket_->reqContractDetails(contract_opt.value().first, contract_opt.value().second);
? ? ? } else
? ? ? ? break;
? ? }


I don't receive any contract details message back from the API using the following snippet :?

while (active() && IsConnected()) {
? ? ? reader_signal_->waitForSignal();
? ? ? try {
? ? ? ? LOG(INFO) << "Trying to read message!";
? ? ? ? p_reader_->processMsgs();
? ? ? } catch (std::exception& e) {
? ? ? ? LOG(ERROR) << "Error Processing Messages : " << e.what();
? ? ? }
? ? }

It shouldn't be an issue with market timings, as I've tried both during market hours and before/after them.

Furthermore, I connect to the IBGW instance using host: 127.0.0.1 and socket 4002 (I don't think this is relevant in any way though!)

I'd really appreciate any help I can get


Re: trouble linking twsapi

 

The libbid.a file they've provided is faulty, try re-making that file manually after cloning its repo from github


Re: reqHeadTimestamp and reqHistoricalMktData return Strange Error

 

@´³¨¹°ù²µ±ð²Ô, I read that topic and that is what led me to try to use Exchange = Primary Exchange. It worked for a similar case I had with the symbol "LIN" but failed to work with "VICI" hence my post.

Thanks to @buddy for the input on using AMEX which also worked for me but it should not be a requirement to handle this type of issue by trial and error.

I definitely think this is a bug from IBKR so I will do as you suggested and drop a message to them for a fix.

When/if I hear back from them I will update this thread.


Re: reqHeadTimestamp and reqHistoricalMktData return Strange Error

 

We had topic No historical market data for AAL/STK@VALUE Last 1d in august with a similar issue. At the end this is probably a question for IBKR, though.

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


Re: trouble linking twsapi

 

Hey having this same issue. Have tried a bunch of things but seems like libbid.a is the culprit. I know it's been a year but hoping someone can help. Thanks!


Re: reqHeadTimestamp and reqHistoricalMktData return Strange Error

 

Strange, I have the same problem but when I use AMEX as the exchange it works...

HeadTimeStamp: 20180201 14:30:00


reqHeadTimestamp and reqHistoricalMktData return Strange Error

 

I am placing a reqHeadTimestamp() to get the starting point for the data for the symbol VICI which is traded on the NYSE. It was added to the S&P500 in June '22 so the available data may be short, but it exists. TWS confirms data is available and it is traded on NYSE exchange.

I have tried the following with the CONID set, and without it set.? (CONID = 292080616)
?- I have tried setting EXCHANGE to SMART and PRIMARY EXCHANGE to NYSE
?- I have tried setting EXCHANGE to NYSE and PRIMARY EXCHANGE to NYSE.
?- I have tried exchange NYSE and PRIMARY blank.

All of the above give me the following error which makes no sense to me as nowhere do I mention VALUE as my exchange.

??? Code: 162 / ID: 10000002 / Historical Market Data Service error message:No historical market data for VICI/STK@VALUE Last 0

I am hoping someone can point me in the right direction to solve this problem.


Re: Time conditions

 

Now I get this message , about the timecondition :?'TimeCondition' object has no attribute 'append'
I understand that it means that timecondition is not a list although it should be one ... but I don't know what I have done wrong


Question about News and Broad Tape ( BRFG, DJNL, BZ)

 

Hi,

I have activated Benzinga API free trial and successfully get the news and the articles if I request, I can get BRFG, DJNL and BZ, no issues but...

1. For some articles I get no stock ticker code in the news article. When I check the news content from TWS, I see the text without any clickable link in it but there is a small box/button at the bottom which contains ticker code. But this ticker code is not placed in the article which I receive from the API.

2. More importantly, I see some BZ hot news entries in the company specific news of a stock but they are not listed in the Broad Tape news panel. I assume Broad Tape is the news selection for all the subscribed news and should contain company specific news also but it is not. The news entry which I see in the company specific new panel is not listed in the Broad tape panel and also not sent to API. I could not find any option to exclude/include some news about company on broad tape.

Anyone has an idea ??

Thanks in advance.

Here the code for getting all the news.?
Contract contractBRFG = new Contract();
contractBRFG.symbol("BRFG:BRFG_ALL"); //Briefing.com General Market Columns (BRFG)
contractBRFG.secType("NEWS");
contractBRFG.exchange("BRFG");?
? ? ? ??
Contract contractDJNL = new Contract();
contractDJNL.symbol("DJNL:DJNL_ALL"); //Dow Jones Newsletters (DJNL)
contractDJNL.secType("NEWS");
contractDJNL.exchange("DJNL");?
? ? ? ??
Contract contractBZ = new Contract();
contractBZ.symbol("BZ:BZ_ALL"); //BroadTape All News
contractBZ.secType("NEWS");
contractBZ.exchange("BZ"); //Benzinga Pro

clientSocket.reqMktData(1000, contractBRFG, "mdoff,292", false, false, null);
clientSocket.reqMktData(1001, contractDJNL, "mdoff,292", false, false, null);
clientSocket.reqMktData(1002, contractBZ, "mdoff,292", false, false, null);
?
?
?
?


Re: Time conditions

 

I had never seen this samples folder ! thank you so much for your help !


Re: Child order when main position is closed

 

If you close the main position manually you will also have to cancel the child orders manually.