¿ªÔÆÌåÓý

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

Re: Unable to parallelize entire python trade sequence

 

Hi ´³¨¹°ù²µ±ð²Ô, sorry for posting about this topic again, but I finally extensively tried what you suggested and I now understand what you meant by making the order self destruct.

I ran into the problem where an order did not fill at all and it did not self destruct after 3:50, so I am trying to take your advice into consideration now using the timecondition. Is this the correct way of doing it? I will try it on paper trade tomorrow once I have figured it out.

To ensure that if

  1. an order has not been filled, the order self destructs at 3:50pm

  2. an order has filled or partially filled, the trailing stop loss protects it and the closing trade is placed at 3:50 making sure that there are no open positions.

Is my code below correct?

def BracketOrder(self, parentOrderId:int, openinglimitPrice:float, quantity:Decimal, trailingPercent:float, timeswitch:str, adaptive_type:str):

    # 1st part: Buy Adaptive Algo order
    opening = Order()
    opening.orderId = parentOrderId
    opening.action = "BUY"
    opening.orderType = "LMT"
    opening.lmtPrice = openinglimitPrice
    opening.totalQuantity = abs(quantity)
    opening.transmit = False
    opening.tif = 'GTC'
    algo.FillAdaptiveParams(opening, adaptive_type)

    timeCondition = TimeCondition()
    timeCondition.time = timeswitch
    timeCondition.isMore = True
    opening.conditions.append(timeCondition)

    # 2nd part: Trailing Stop Sell order
    trailingStopLoss = Order()
    trailingStopLoss.orderId = opening.orderId + 1
    trailingStopLoss.action = "SELL"
    trailingStopLoss.trailingPercent = trailingPercent
    trailingStopLoss.orderType = "TRAIL"
    trailingStopLoss.totalQuantity = abs(quantity)
    trailingStopLoss.parentId = parentOrderId
    trailingStopLoss.tif = "GTC"
    trailingStopLoss.transmit = False

    # 3rd part: Sell Market order
    closing = Order()
    closing.orderId = opening.orderId + 2
    closing.action = "SELL"
    closing.orderType = "MKT"
    closing.totalQuantity = abs(quantity)
    closing.parentId = parentOrderId
    closing.tif = "GTC"
    closing.goodAfterTime = timeswitch
    closing.transmit = True
    closing.conditionsCancelOrder = False 

    timeCondition = TimeCondition()
    timeCondition.time = timeswitch
    timeCondition.isMore = True
    closing.conditions.append(timeCondition)

    bracketOrder = [opening, trailingStopLoss, closing]
    return bracketOrder


Re: build problem with cppclient

 

Thank you buddy;

??? I had messed up your first set of instructions because I wasn't paying attention.

??? I am able to build and run TestCppClientStatic

??? I've also placed these files into a repo of mine: redorca/tws-api-public branch CompilesOnLinux

Bill


Re: MNQ Incorrect and Inconsistent Fills with Order Type = STP and any Market Order

 

Thanks for the response, on using UI we din't see 10-15 ticks increments, but with API we observed it more, as our test cases with API were more extensive.
We will try and use STP LMT as you suggested and find out a way to flatten orders when needed using Price/Time conditions.


Re: buy order at open if market open between a minimum and maximum

 

For an opening auction, it cannot be done due to market mechanics. The exchange has to introduce a new order type or amend the current.


Re: MNQ Incorrect and Inconsistent Fills with Order Type = STP and any Market Order

 

What makes you believe those fill prices are incorrect? I agree 10-15 ticks are unfavorable but not unheard of for orders and contracts worth $4,400 (MES) and $15,100 (MNQ). Depending on the market situation or trading time, market order fills can be significantly away from the last displayed ask/bid. Market order provides no price protection and may fill at a price far lower/higher than the current displayed bid/ask.

If you want more price control, consider LMT or STP LMT orders. The trade-off is, obviously, time-to-fill.

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


MNQ Incorrect and Inconsistent Fills with Order Type = STP and any Market Order

 

Hi all,

We are using a TWS simulated account with live Market Data and are seeing the following inconsistencies with the fills.?
1. Behavior is pretty consistent with MNQ and sometimes we see the same with MES as well.
2. "LMT" Order Type works OK and results are accurate or sometimes there is a gap of 2 points
3. "STP" Order Type results in a gap of 10-15 points in case of MNQ
4. Market Order behavior is the same as "STP" Order Type results in a gap of 10-15 points in case of MNQ
5. Upon reviewing logs in TWS we see fills consistent with the behavior, so TWS
6. On TWS UI on creating similar Bracket Order results are accurate or sometimes there is a gap of 2 points
7. On contacting and sharing TWS logs with contact support response, a lot of people use the API.

Order created is a Bracket Order with?
Parent Order Type = "LMT"
Take Profit Order Type = "LMT"
Stop Loss Order TYpe = "STP" -- incorrect fills, gaps of 10-15 points

It seems like there is something that we are missing, gaps of 10-15 is quite high and if you see the screen shot Price is nowhere near what was filled. Any insight will help

thanks
Deep

StopLoss_FillPrice_15points.heic


Re: Time to Fill Orders During Paper Trading

 

Hi All,

Adding to other observations. I recently opened real account with IB for India as an Individual. There is certainly some problem with some accounts.?

I am facing issues with Paper Account Trades not filling quickly (Even the market orders).?

Interestingly, I have worked with a client who has same account as mine and I placed same order at the same time on both accounts, mine and his.?
His account processes the orders in a correct manner while mine keeps waiting indefinitely.?

So, even if their algorithm of Paper Trading is same for same market/securities, there is something that is missed and that is causing the delays in order fills.

Hope anyone finds solution and posts here.?

Thanks and Regards,
Pratik Babhulkar


Re: Having trouble submitting ZT (2 yr treas) futures orders thru API.

 

On Thu, Jun 22, 2023 at 01:29 PM, Lou Dudka wrote:

It'll take some work to upgrade my app from 9.17 to 10.19, but well worth it.

The deadline is looming... roughly three weeks I think. I just finished rolling my stuff out the other day.

On the bright side, it should take a couple of hours (max) to write a unit test in a virtual/paper-trading environment and confirm an update resolves that issue.

That's all I did, but since I've liberated myself from the MSFT eco-system, my help was of limited value. Sorry for that.

Good luck Lou.


Re: Having trouble submitting ZT (2 yr treas) futures orders thru API.

 

Richard - I checked once before and didn't realize they included it.? I was looking in the TwsActiveX directory and didn't look in Excel.

It'll take some work to upgrade my app from 9.17 to 10.19, but well worth it.? I still have to upgrade TWS so I might as well do it together.

buddy - you're the BEST!

Thanks (Again), as usual
Lou Dudka


Re: Having trouble submitting ZT (2 yr treas) futures orders thru API.

 

On Wed, Jun 21, 2023 at 10:58 PM, Lou Dudka wrote:

You saved me some testing - THANKS!

You're welcome. BTW... thanks for replying to the list instead of a direct email. My manager was getting a bit ticked that I was fielding support out of band. They keep me on a short leash :-(


Re: Having trouble submitting ZT (2 yr treas) futures orders thru API.

 

¿ªÔÆÌåÓý

Lou

?

What you call the ¡®¡®old¡¯¡¯ Excel API (ie using the ActiveX component and VBA, rather than DDE or RTD) is still very much in play and is included in every API version.

?

So it¡¯s not clear to me what you¡¯re asking for, or why. I do have some (but by no means all) older versions, but I think you¡¯d probably do best to install the current stable API which is 10.19.

?

Richard


Re: Having trouble submitting ZT (2 yr treas) futures orders thru API.

 

Hi buddy,

Just saw your post.

You saved me some testing - THANKS!

Yeah, I'm starting to think the same thing about the API.? I'm running an ancient version.

I know Richard (and rightfully so) doesn't distribute older versions anymore.

If someone has a later install for Excel API (the "old" way with VBA code in the XLS) could you please contact me?

Thanks, Once again to everyone,
Lou Dudka


Re: 2105: HMDS data farm connection is broken:ushmds

 

I may get a little bit more of this 2105 than usual. But I must admit that I don't care about it because:
1- It looks like there is a new pattern about it, like not using the data farm for some time (minutes) will make it disconnected, but it get back live ~instantly on next request.
2- The explanation IB gave about the reason may no longer be fully applicable.
,{??? 2105,LOG_WARN??? ,ACT_RETRY,??? ??? "A historical data farm is disconnected.",??? "Indicates a connectivity problem to an IB server. Outside of the nightly IB server reset, this typically indicates an underlying ISP connectivity issue."??? }

If I have to guess I would say that IB did implement a "disconnect on lazy usage" in a recent revision. (maybe the latest one)

Anyway, on a 'sleeping connection', a reqHistoricalData1 Month of days Bars AAPL wake up all the system with a minor impact, as it is processed in about ~400ms instead of < ~50ms.
But once done the connection seems staying alive for a while.? Didn't tried extensively but I would say that during RTH you are good for ~10 min kept alive without new data request, aside RTH you are good for 3 min (seems to disconnect faster)

So you should not be worried because either you do infrequent request then 400ms first latency is probably not an issue for you, or you should not experience it at all if you have a heavy load.
Unless you experienced this error while doing frequent data request (I means at least one every 10 sec), The question for you is: does it happens while you are in middle of a heavy traffic ?


2105: HMDS data farm connection is broken:ushmds

 

I am concerned about the many error messages code 2105 "HMDS data farm connection is broken:ushmds" I am receiving. I am receiving these day and night, and every day of the week. What surprises me is not only that it happens so often, but also that it is only ushmds which is apparently having issues. It is never any of the other IB servers which is having issues. For the current month of June have I received this message 148 times so far. In most cases I receive it when I'm requesting historical data, but there are also cases where I'm only asking for my account details, and am not requesting any historical data at all.

Are others here observing the same issue?


Moderated Looking for help with Python project (paid)

 

Hello dear members.?
?
I am in need of coding services in order to finish a python project. This project is based on the current session self updating Fibonacci levels for intraday trading and takes advantage of reversals using bracket orders. It is functional but is missing a bit of logic for unfilled order cancelation and it has a few bugs to be fixed. It also requires a general review before a complete GUI or a CSV can be created.? It will trade NQ/ES and MNQ/MES, each pair on a different login.
I am looking for someone available capable of delivering quickly at a fair price.
Interested members please contact me directly to ferreira.helhazar@....
?
Thanks,
?
Marcos

[subject edited by moderator]


Re: Error - 2157

 

Building on Gordon's comments here some thoughts:
  • Gordon pointed you to the documentation and as you can see from the heading for the 2xxx codes, they are warnings and not real errors.
  • Some error message say something like "XYZ has become inactive". Those are the cases Gordon mentioned, where TWS/IBGW has disconnected a data farm that is currently not in use, but will transparently reconnect that farm as soon as you'd make a related request.
  • Some error messages say something like "XYZ is disconnected". Those are cases, such as your code 2157, where TWS/IBGW connections got disconnected from the IBKR server that is mentioned in the error message. Shortly after that message you generally get an "all clear" message that indicates that the connection got reestablished.

Gordon is correct in that most of these "disconnect" events take place during the daily IBKR maintenance/reset window for your region and it takes only seconds (in fact often sub-seconds) for the "reconnected" message to come in. And if you have several accounts connected (such as a live and a paper trading account), each account will get the disconnect/reset at a different time within the daily reset window,

I suggest you do nothing special as long as your disconnects are brief and during the reset window. Restarting TWS/IBGW or your client will change nothing, will likely take much longer than the disconnect periods, and runs the risk of failing in case the connection is not back up yet. In case of 2157 you might just avoid making any requests that relate to instrument information (such as reqContractDetails, trading schedules, and similar) or be prepared to repeat the requests once the secdef farm is reconnected. But that should not be too hard, since you will likely make those calls when your client starts anyway.

The story changes considerably if your disconnects are for extended periods of time, outside the maintenance/reset window, several different 2xxx disconnects happen simultaneously, and you also get error 1100 as well. In those cases, look for a transient network issue between your TWS/IBGW and the IBKR infrastructure. Here a few situations that come to mind from real life experiences:
  • Your TWS/IBGW is connected to IBKR servers in a different region, data packets travel half around the world, and the natural higher packet loss rates causes brief outages. Just use the green "DATA" button in TWS/IBGW and check that they are connected locally.
  • Your firewall/internet security software might interfere with certain packets, ports, or protocols used by TWS/IBGW
  • A high packet loss rate or an unstable network hop between TWS/IBGW and IBKR may cause intermittent disconnects. If one of those legs is, for example, a Wifi connection, someone in your house with a craving for microwave popcorn might cause brief disconnects.
  • Any equipment between TWS/IBGW and IBKR might have to renew a DHCP lease (your server, routers, switches, Wifi access points, internet modems). Disruptions will take place even if the renewal is instantaneous and the equipment's IP address does not change.
  • Your ISP might reset/update the modem regularly and disconnect you entirely from the Internet during that time. Similarly, a piece of network equipment might get an automatic firmware or configuration update.

But chances are that your 2157 are brief during the reset window and you don;t have to do anything special.

Hope this helps,

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


Re: Error - 2157

 

Forgot to mention:
When I receive a 2000 class error, I keep pushing requests.
Otherwise said this is an informational message and while the code should be made aware that something happens, it should not be stopped querying,
Contrary to the implicit belief this could be for good.
My assumption is that in some circumstances, the Gateway go sleeping if such condition triggered and no new reason exist to re-establish the connection. Look at the message for error 2107. Not a clue just a suspicion but successful so far
TWS in itself is pretty active and have good reason to wake up IB connection to data farms, so it may hide that re-connection "on call" because you don't see TWS calling it.

Also you should ask yourself: when you got your 2157, how long was it after your last request for data to IB ?


Re: Error - 2157

 

IB designed the SDK ABI without special consideration to what we call "messages" (from them to us) , they are like "errors" (from them about us, understand bad behavior of our own code)
Do not consider everything that come through the error 'channel' as error. Even if it means something is not OK, it doesn't mean you can do something or that your code is culprit. (While generally this is the case)
They just inform you that there is reason your code doesn't behave as you expect and generally, they auto-fix it.


The 2157 you mention seems more frequent outside RTH (I suspect because they may do maintenance and reduce active farms),
There is nothing you can really do about it. It should? reconnect by itself a couple of second later and issue a 2158 Error code.
,{??? 2158,LOG_TRACE??? ,ACT_NOACTION,??? "Sec-def data farm connection is OK ",??? "A notification that connection to the Security definition data server is ok. This is a notification and not a true error condition, and is expected on first establishing connection ."}

?
but 2157 doesn't seems a documented one

If very critical you can try the lengthy process of closing your connection and re-opening it. but before considering new dev, check first that after your 2157 you do receive (or not) an error-message 2158 in a timely manner that may suite you.


SUIE code

 

Dear community,

I use coa code "SUIE" to retrieve unusual expense(inc) for Allianz SE (Ticker: ALV, Exchange:IBIS, Currency: EUR) and from unknown reasons my TWS does only provide me with values for 2017 up to 2021 but the value for 2022 is missing even though the value is available in the fundementals explorer of the TWS.

If I run the same query for Volkswagen (VOW3, IBIS,EUR) then my TWS provides me with unusual exp.(inc) for 2022.

Did someone experience the same problem or does someone have an idea what might be the reason for this strange outcome?

Kind regards,
Marc?


Re: build problem with cppclient

 

Sorry, the previous patch got malformed during copy & paste... assuming the groups.io preview function works, the one below should be used with instead.

--- makefile.~1~	2022-10-03 11:50:16.000000000 +0000
+++ makefile	2023-06-17 02:37:00.264457603 +0000
@@ -8,7 +8,7 @@
 TARGET=TestCppClient
 
 $(TARGET)Static:
-	$(CXX) $(CXXFLAGS) $(INCLUDES) $(BASE_SRC_DIR)/*.cpp ./*.cpp $(BASE_SRC_DIR)/lib/libbid.a -o$(TARGET)Static
+	$(CXX) $(CXXFLAGS) $(INCLUDES) $(BASE_SRC_DIR)/*.cpp ./*.cpp -lbidgcc000 -o$(TARGET)Static
 
 $(TARGET):
 	$(CXX) $(CXXFLAGS) $(INCLUDES) ./*.cpp $(BASE_SRC_DIR)/lib/libbid.so $(SHARED_LIB_DIRS)/$(SHARD_LIBS) -o$(TARGET)