¿ªÔÆÌåÓý

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

Error 110. The price does not conform to the minimum price variation for this contract

 

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

Yes, I run into that all the time.? I use Excel (aarggh!) and I think it's even worse.

So I round at the very last step in an order right before I'm done.? I had to do this when trading Forex on IB and it drove me nuts.

As always, thanks again and be well,
Lou Dudka


Multiple symbol request speed

 

Hello i new here i try get data for multiple symbol,
about 580 +-,
but it take allot time and not always finish this.
this how i try make this.

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
import pandas as pd
import threading
import time
from datetime import timedelta
import datetime
tickers=list(pdToList[0:600]) #########-> list example i put here <-#########
listnumb = []
from ibapi.common import BarData
from random import random
start = datetime.datetime.utcnow()
class IBapi(EWrapper, EClient):
????def __init__(self):
????????EClient.__init__(self, self)
????????self.data = []
????def error(self, reqId, errorCode, errorString):
????????print("Error. Id: ", reqId, " Code: ", errorCode, " Msg: ", errorString)
????def historicalTicksBidAsk(self, reqId, ticks, done):
????????for i in listnumb:
????????????mama = int(''.join(filter(str.isdigit, i)))
????????????if str(reqId) == str(mama):
????????????????symbllll = str(i)
????????????????result = ''.join([i for i in symbllll if not i.isdigit()])
????????????????symbllll = str(result)
????????????????break
????????for tick in ticks:
????????????print("HistoricalTickBidAsk. ReqId:", reqId , "symb : " + symbllll, tick)
????????????
????# include this callback to track progress and maybe disconnectwhen all are finished
????def historicalDataEnd(self, reqId: int, start: str, end: str):
????????print("finished")
def run_loop():
????app.run()
app = IBapi()
app.connect('127.0.0.1', 4001, 123)
api_thread = threading.Thread(target=run_loop, daemon=True)
api_thread.start()
time.sleep(1)
reqId = 1
sym_dict = {}
start_time = time.time()
for sym in tickers:
????contract = Contract()
????contract.symbol = str(sym)
????sym_dict[reqId] = sym
????contract.secType = "STK"
????contract.exchange = "SMART"
????contract.currency = "USD"
????listnumb.append(sym + str(reqId))
????app.reqHistoricalTicks(reqId, contract, "20211022 04:09:40", "", 1, "BID_ASK", 1, False, [])
????reqId += 1


Re: Error 110. The price does not conform to the minimum price variation for this contract

 

Thank you, Lou. Glad we pointed you in the right direction.

You won;t be able to "round yourself" out of the problem completely. Even double precision floating point math can be pretty tricky and randomly generates very imprecise results in certain cases. Take the 35.16, for example (one of your prices). Here a couple example with Java double values:

35.16 + 0.01 = 35.169999999999995

35.16 * 1.01 = 35.511599999999994

It is common practice in financial software to use a Decimal or fixed point data type instead of? float and double. In fact IBKR introduced a Decimal data type in TWS API 10.10 and changed the size fields for many objects from double to Decimal (probably for crypto support). Interesting though that they left all price fields unchanged as double. Here the results with a Java decimal type:

35.16 + 0.01 = 35.17

35.16 * 1.01 = 35.5116

Internally, we use a Decimal type for all our applications as well. Makes calculations a little more cumbersome to code but makes for much better and controlled outcomes.

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


Error 110. The price does not conform to the minimum price variation for this contract

 

Nick/´³¨¹°ù²µ±ð²Ô,

You guys are good!

Sure as anything prices of 41.3999 and 44.3999 were sent!

I'll have to check my code b/c I always round up/down to the correct amount before submitting an order, except, obviously, this time.

Thanks, as always, and be well,
Lou Dudka


Re: Error 110. The price does not conform to the minimum price variation for this contract

 

That was my first reaction as well. The ? say:

An entered price field has more digits of precision than is allowed for this particular contract. Minimum increment information can be found on the IB Contracts and Securities Search page.

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

On Fri, Oct 22, 2021 at 06:09 PM, Nick wrote:
...

Depending on the language and how floating point numbers are converted
to text their may be differences in rounding from what you show in your
logs.

...


Re: Error 110. The price does not conform to the minimum price variation for this contract

Nick
 

You can check the api log to see what was actually sent to IB.

Depending on the language and how floating point numbers are converted to text their may be differences in rounding from what you show in your logs.

The api log should help you track down the issue (either sending an invalid price or an issue on IB's end).

On 10/22/2021 6:50 PM, Lou Dudka wrote:
and received the error on the BKT StopLoss order STPLMT Shr:290 Limit:45.40 Aux:41.40
Error 110. The price does not conform to the minimum price variation for this contract


Re: Get and close all positions at a specific time

 

Your approach will work most of the time, but things do go wrong and you exposure yourself to some degree of risk that your orders and positions do not get closed and will stay open past the end of the trading session:
  • Your power goes out or your application crashes
  • Your TWS locks up or loses connection with IBKR
  • Your network or your ISP is down around 3:45pm
  • ...
The combination of OCA groups and conditional orders allows you to define the exit condition for each position so that it is executed by IBKR without you(r application) having to be around,
´³¨¹°ù²µ±ð²Ô


Error 110. The price does not conform to the minimum price variation for this contract

 

Hi All,

There is a topic on this subject from 2016.? It just doesn't seem to add up.

I tried to place a bracket Sell Order for NIO thru the API.? This is the output from my logs:
BKT Entry order??? STPLMT Shr:290 Limit:38.96 Aux:38.96
BKT Profit order?? LMT??? Shr:290 Limit:35.16
BKT StopLoss order STPLMT Shr:290 Limit:45.40 Aux:41.40

and received the error on the BKT StopLoss order STPLMT Shr:290 Limit:45.40 Aux:41.40
Error 110. The price does not conform to the minimum price variation for this contract

The Entry and Profit order both went thru just fine.

I received this simultaneously on the test and production systems.

Thanks and be well,
Lou Dudka


Re: Get and close all positions at a specific time

 

Thanks Jurgen!
I saw your approach and it's a really good one. However my use-case turned out to be really straight forward (cancel all api and tws orders and close all positions at 3:45). So I ended up using reqGlobalCancel() for cancelling orders and reqAccountUpdated() alongwith updatePortfolio() to get positions on each entity and place orders opposite to positions.??


Re: Fractional shares rounding issue

 

Just like in all API implementations, MinClientVersion and MaxClientVersion in ib_insync are constants. They are attributes of the client class and while I am not a Python practitioner, I am sure it is straight forward to extract their values in client programs on-the-fly. Along with the server version.

I also did some more digging on and it looks like what you are doing requires a TWS of Version 979 or above. TWS 10.10 or API level 165 are not required.

TWS 10.10 and API level 165 are required for crypto support and fractional sizes in market data related objects (Bar, TickByTick*, ...)

Not sure what to suggest other than maybe going trying a stable TWS below 10.10 (say 981.3d). We had lots of issues with 10.10 versions of earlier this month.

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


Re: how to keep the python script running during the TWS auto-restart ?

 

On Mon, Sep 27, 2021 at 03:19 PM, <lotfi.bensassi15@...> wrote:
connectionClosed

Hi Lofi,?

Can you please share a code snippet of the solution that worked. I am facing a similar issue?


Re: Get and close all positions at a specific time

Nick
 

¿ªÔÆÌåÓý

You could have the exit orders in an OCA group and add one more to buy/sell at market with a "good after" time of 3:45.


On 10/20/2021 3:38 PM, movais996@... wrote:

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?



Re: Get and close all positions at a specific time

 

Take a look at the of the API Reference Guide.

When you place orders, you can also use to attach a condition for when the order should become active. One such condition is the TimeCondition which allows you to place an order sometime throughout the day but that does not become active until 3:45pm (or any other time).

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


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?

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