¿ªÔÆÌåÓý

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

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


 

?

hymagik is correct about the somewhat messy C++ Decimal support and the fact that IBKR has selected a decimal size of 8 bytes (64 bits). To be more precise, IBKR decimal uses a "MathContext with a precision setting matching the IEEE 754R Decimal64 format, 16 digits, and a rounding mode of HALF_EVEN.". I also fully support when hymagik says 'Once in "Decimal" you should stay in Decimal'.

The other three language have native language support for decimal math so that no overloading of 8 bytes integer values is required. The use of TWS API V10 decimals is much smoother and type safe in these languages:
  • built-in "decimal" type for C#
  • the IBKR class Decimal that wraps around the native BigDecimal in Java
  • the module "decimal" in Python.
´³¨¹°ù²µ±ð²Ô


On Tue, Jan 3, 2023 at 03:20 PM, <hymagik@...> wrote:

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.


?

Join [email protected] to automatically receive all group messages.