¿ªÔÆÌåÓý

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

Re: Fractional shares rounding issue

Nick
 

Yes, that's the api log but unfortunately IB isn't showing the fields from the initial connection which is where the version numbers are. I couldn't remember if they were included or not but figured if you already had the logs it was worth a chance.

Maybe you could ask in the ib_insync group and they could tell you how to get a version of the lib that has the features you need.

On 10/19/2021 11:16 PM, hieuimba@... wrote:
Just so we're on the same page,


Get and close all positions at a specific time

 

Hi,

I want to retrieve all open positions for a contract and then close them if the time is close to market closure (like 3:45 pm). Is there a way to do that in tws python api?


Active OCA Groups

 

All,

I update my orders frequently and want to prevent updating if any executions have occured on the oca group for that order.? Is there a way to request all oca groups that have had an execution from IB?

Mike


Re: Fractional shares rounding issue

 

Just so we're on the same page, I believe you are talking about this API log right:?
API Log

TWS and IB Gateway can be configured to create a separate log file which has a record of just communications with API applications. This log is not enabled by default; but needs to be enabled by the Global Configuration setting?"Create API Message Log File"

  • API logs contain a record of exchanged messages between API applications and TWS/IB Gateway. Since only API messages are recorded, the API logs are more compact and easier to handle. However they do not contain general diagnostic information about TWS/IBG as the TWS/IBG logs. The TWS/IBG settings folder is by default?C:\Jts?(or IBJts on Mac/Linux). The API logs are named?api.[clientId].[day].log, where [clientId] corresponds to the Id the client application used to connect to the TWS and [day] to the week day (i.e. api.123.Thu.log).
Due to privacy regulations, logs are?encrypted?before they are saved to disk. They can be decrypted from the associated TWS or IB Gateway session. In TWS: Classic TWS -> Account -> Diagnostics -> TWS Logs. In IB Gateway, File -> Gateway Logs.
If I have it correct it should be this file:

C:\Jts\oboecfmlfmiihkmhcllfnckaeplfhfnchppdchbn\api.0.20211019.162140.ibgzenc

However, I couldn't find any "API" text, here are the first few lines of the log:

============================== Log file: C:\Jts\oboecfmlfmiihkmhcllfnckaeplfhfnchppdchbn\api.0.20211019.162140.ibgzenc =============================
16:21:40:453 -> ---15-1-[MyAccountID]-
16:21:40:475 -> ---9-1-8-
16:21:40:476 -> ---54-2--1-2104-Market data farm connection is OK:usfarm-
16:21:40:476 -> ---34-2--1-2106-HMDS data farm connection is OK:ushmds-
16:21:40:476 -> ---84-2--1-2158-Sec-def data farm connection is OK:secdefnj-
16:21:40:477 <- 15-1-1-
16:21:40:477 <- 61-1-


Re: Fractional shares rounding issue

Nick
 

I haven't looked at the api logs in a while. If the logs include the connect processing (ie the very first things the client sends to tws) then the version numbers will be in there.

Assuming it's the newer protocol you will see the client sending the text "API" and "V100..NNN" where NNN is the max version the client can support. Then TWS will send the actual server version followed by connect time.

On 10/19/2021 10:28 PM, hieuimba@... wrote:
I might have to go ask the guys at ib_insync on how to track down MinClientVersion and MaxClientVersion


Re: Fractional shares rounding issue

 

Welp that explains it.
I might have to go ask the guys at ib_insync on how to track down MinClientVersion and MaxClientVersion?
However, the ibapi package probably came with the library because I didn't explicitly download or install it, which would imply that the API version is outdated in the package
But again I'm using the same or even older version of the library on my other machine and it works fine
Will have to confirm and see?


On Tue, Oct 19, 2021 at 08:14 PM, ´³¨¹°ù²µ±ð²Ô Reinold wrote:

Just curious, but which stocks allow fractional sizes?

Sure, a lot of them actually, I was quite surprised when I found out about this too. Pretty much all the large and medium caps, I've only had one instance where fractional sizes weren't supported and it was with a very small stock?


Re: Fractional shares rounding issue

 

client.serverVersion() refers to TWS and a value of 163 makes sense since you run a 10.10 TWS, The constants MinClientVersion and MaxClientVersion define your client's capabilities.

Just curious, but which stocks allow fractional sizes?

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


Re: Support and Resistance of a stock

 

¿ªÔÆÌåÓý

This is awesome thanks

On 10/19/2021 2:40 PM, ´³¨¹°ù²µ±ð²Ô Reinold via groups.io wrote:

The available market data is described in the section of the . The table is probably the most comprehensive list of Level I related data items.

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


Re: Fractional shares rounding issue

 

Okay I was able to go into ib_insync ib.py and look at the client object
Seems like client.serverVersion() is actually 163, no luck there
Also I was trading stocks if that helps

I should mention that this issue has happened to me once before and it ended quite abruptly - maybe after an update but I can't remember exactly what solved it.?

I also tested out the Settings theory and most likely it's not the case. I tried duplicating settings/ trying to replicate the rounding error on the working computer but nothing works.

Other information that might be helpful:
I used the Offline TWS Latest version (for Linux) -?Version?10.10.2r:?https://www.interactivebrokers.com/en/index.php?f=16044

I'm running this TWS on a cloud instance, with IBC 3.10.0:?


Re: Fractional shares rounding issue

 

Correct. As a matter of practice, we do record client min/max and server protocol levels in our session logs upon successful connects. Has saved us a lot of debug time over the years/


Re: Fractional shares rounding issue

Nick
 

I would also note that IB often allows TWS to accept quite old api versions. So a recent TWS version is not an indicator that a recent api version is being used.

On 10/19/2021 6:22 PM, ´³¨¹°ù²µ±ð²Ô Reinold via groups.io wrote:
The required minimum client protocol level for fractional size support is 163. So I'm sure, TWS will send rounded sizes to a client (any language) that indicates a MAX_VERSION of less than 163.


Re: Fractional shares rounding issue

 

Which instrument are you trading?

I can't tell you how to find the client and server versions with ib_insync, but there is probably a way. During connect(), TWS API client indicate the [min, max] protocol level they understand, and TWS replies with its level. Levels are defined (for example):

  • for Java as MIN_VERSION and MAX_VERSION in JavaClient/com/ib/client/EClient.java
  • for Python as MIN_CLIENT_VERSION and MAX_CLIENT_VERSION in pythonclient/ibapi/server_versions.py

The required minimum client protocol level for fractional size support is 163. So I'm sure, TWS will send rounded sizes to a client (any language) that indicates a MAX_VERSION of less than 163.

The protocol level for the connected TWS is available through the EClient object.

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


Re: Fractional shares rounding issue

 

Thanks for the pointers guys,
I looked at the API logging file and it looks like TWS is indeed sending rounded values

More specifically these values:
- Order quantity (open and closed)
- Position quantity
For example:
I inputted all orders manually and used fractional shares like 3.333, TWS has no problem with accepting and executing the order.
However the API sends/ I receive only 3 for quantity

My TWS version is: 10.10.2q - where do I find the API version?

Another interesting thing is that I tried the same script with the same account in another computer running version 10.10.2r and it gives the desired/correct qty amount in fraction.


Re: Support and Resistance of a stock

 

The available market data is described in the section of the . The table is probably the most comprehensive list of Level I related data items.

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


Re: Adding multiple Exchanges to a scanner

 

¿ªÔÆÌåÓý

Ok,
I created a tool to parse the XML GetScannerParameters results and
got this..



On 10/19/2021 10:26 AM, Colin B Maharaj via groups.io wrote:

Hi, firstly I got the scanner working with the tools I mentioned before.
What I want to know, when adding exchanges, do I comma separate
the list?
e.g.
NYSE,AMEX
etc

thanks



Support and Resistance of a stock

 

¿ªÔÆÌåÓý

Is it possible to either
1. Get via an API call,? the current support and resistance of a stock
or
2. Calculate if it is not available.


Re: Fractional shares rounding issue

 

Can you be a little more specific about a couple aspects of your issue?
  • Which instruments that support fractional quantities are you looking at?
  • Which quantities are being returned as rounded numbers (e.g. real-time data, orders, executions, ...)
  • Which version of TWS and TWS API are you running?
TWS API 10.10 (with TWS 10.10) has introduced a Decimal data type for many size and quantity fields. I would assume that you will get rounded quantities unless you run at least TWS 10.10 and your library fully implements the 10.10 API changes.

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


Re: Fractional shares rounding issue

Nick
 

I don't know if it's due to a setting but if you enable api logging you can see what TWS sent and verify if it's a TWS issue or something on the client side.

On 10/19/2021 1:59 PM, hieuimba@... wrote:
I'm having trouble getting data from TWS where the quantity amount is being returned as rounded numbers instead of their correct fractional shares value.


Fractional shares rounding issue

 

I'm having trouble getting data from TWS where the quantity amount is being returned as rounded numbers instead of their correct fractional shares value.
This happened with all positions and orders which led me to think that this option in Settings might have something to do with it:
But as you can see it is turned off here but the error still persists:


I use ib_insync btw but as far as I can tell it should not be the source of the issue.


Re: Scanning with IABSocketAPI in C++ Builder

 

¿ªÔÆÌåÓý

wow, ok, I got it working.


On 10/18/2021 1:37 PM, Nick wrote:

I doubt anyone here will be able to help since almost everyone uses one of the IB supplied libraries.

Your best best would be to contact the library developer if they are still around.


On 10/18/2021 1:23 PM, Colin B Maharaj wrote:

Hi,
I am using IABSocketAPI from hhssoftware.com and trying
to do a gap scanner. After months, I cant get the code working
Note: I dont do python, of Visual studio or Java. I got the hhssoftware
software component that I was able to successfully install in
C++ Builder , but I dont get a response from my event.

Below is the code I have to create the scanner.
and below that the onScannerData event

Any help will be appreciated thanks.


//------------------------------------------------------------------------------

TIABScanCriteria * ScanCriteria=NULL;
int ScanId = 2;
int sCount=0;

void __fastcall TForm4::InitScannerClick(TObject *Sender)
{
?? sCount=0;
?? ScanCriteria = new TIABScanCriteria;
?? ScanCriteria->StockTypeFilter = "CORP";
?? ScanCriteria->NumberOfRows = 20;
?? ScanCriteria->Instrument = "STK";
?? ScanCriteria->LocationCode = "STK.NYSE";
?? ScanCriteria->AbovePrice = 1.0;
?? ScanCriteria->BelowPrice = 15.0;
?? ScanCriteria->ScanCode = "TOP_PERC_GAIN";

?? ScannerSelect1->Enabled = false;
?? InitScanner->Enabled = false;
?? StopScanner->Enabled = true;


?? IABSocket1->Scanner->InitializeScanCriteria(ScanCriteria);
?? IABSocket1->Scanner->NewScan(ScanId, *ScanCriteria);

}

//---------------------------------------------------------------------------


void __fastcall TForm4::IABSocket1ScannerData(TObject *Sender, TIABScan *Scan)
{
?? int qr = Scan->Count+1;
?? if (qr==1) { qr=2; }
?? Grid2->RowCount =qr;
?? Label4->Caption = sCount++;

?? Grid2->Cells[0][0]="Symbol";
?? Grid2->Cells[1][0]="Rank";
?? Grid2->Cells[2][0]="MarketName";
?? Grid2->Cells[3][0]="TradingClass";
?? Grid2->Cells[4][0]="LocalSymbol";

?? for (int i = 0; i< Scan->Count; i++)
?? {
???? TIABScanResultItem * s = Scan->Items[i];
???? Grid2->Cells[0][i+1] = s->Symbol;
???? Grid2->Cells[1][i+1] = s->Rank;
???? Grid2->Cells[2][i+1] = s->MarketName;
???? Grid2->Cells[3][i+1] = s->TradingClass;
???? Grid2->Cells[4][i+1] = s->LocalSymbol;
?? }

}