¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 ¿ªÔÆÌåÓý

Re: Rolling futures to the next expiry

 

I have been looking into calendar spreads for a few weeks and it looks to me that what you experience is intended this way. By default and documented as such in the tool tips, TWS seems to
  • sort the legs in the order <earlier expiration>, <later expiration>. Meaning RTYU4-Z4? and RTYZ4-U4 both are treated as RTYU4-Z4 (and RTYH5-Z4 becomes RTYZ4-H5)
  • sells contracts for the future with the earlier expiration and buys the one with the later expiration

If you BUY 1 spread of RTYU4-Z4 you will get positions: -1 RTYU4 and +1 RTYZ4

If you SELL 1 spread of RTYU4-Z4 you will get positions: +1 RTYU4 and -1 RTYZ4

With the "Spread Trader" in TWS or via the API you can define this the other way around, but I got myself turned around a few time when buying and selling the various combinations. So I decided to stay with that "front -1, back +1" convention for my TWS API implementation calendar spread order placement.

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

?
On Mon, Jun 24, 2024 at 03:52 AM, Brian wrote:

Hi all,

I was trying to roll my future to the next expiry (RTY Sep, CME -> RTY Dec, CME) with a negative current position (RTY Sep, CME: -1) on TWS GUI, i.e.

from?

RTY Sep, CME: -1

RTY Dec, CME: 0

to

RTY Sep, CME: 0

RTY Dec, CME: -1


I'm also connecting to TWS through TWS API. However, when the callback function "openOrder" is called, i get the wrong action (BUY/SELL) for the respective orders.


Details:
637533627: RTY Sep, CME

654503362: RTY Dec, CME

contract.comboLegsDescrip: ?637533627|-1|CME,654503362|1|CME

Leg. conId: 637533627 action: SELL
Leg. conId: 654503362 action: BUY

To my best knowledge, isn't it supposed to be

contract.comboLegsDescrip: ?637533627|1|CME,654503362|-1|CME

Leg. conId: 637533627 action: BUY
Leg. conId: 654503362 action: SELL


However, in the end, i'm able to get the correct execution details:

637533627: BOT

654503362: SLD

So I was wondering if I misunderstood the definition, or could this be a bug from TWS?


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

In client API 10.19 the method's signature suggests an object of type OrderId for the first operand, which appears to be equivalent to a single int, i.e. a primitive integer type. Since square brackets indicate a list of objects in Python, it goes against the signature, and although typing annotations in Python are purely suggestive, in fact the source of the method itself indicates this shouldn't really work.
?
I frankly didn't pay much attention to this artefact assuming it could be some type of symbolic notation but if it's a direct quote then it definitely doesn't look right to me unless newer API versions introduce changes to the method allowing to pass it a list of order ids.
?
--
Best,
DS


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Just to wrap this up (since we are moving from an TWS API issue that applies to all 6000++ members to basic Python programming skills).

Shouldn't it be self.cancelOrder(orderId, OrderCancel()) instead of self.cancelOrder([orderId], OrderCancel()) ?

cancelOrder() defines orderId as an integer value and doesn't [orderId] make it a list of one integer value?

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

?

?
On Wed, Sep 11, 2024 at 10:44 AM, ds-avatar wrote:

Yes, this should work.
--
Best,
DS


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Yes, this should work.
--
Best,
DS


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Hello DS,
?
Thank you for your response to my query. So if I understand correctly, should my call for cancellation of an order look like this instead?
?
self.cancelOrder([orderId], OrderCancel())
?
Kind regards,
Scott.


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

You should use OrderCancel() for the operand in question. This is how Juergen's suggestion of instantiating an object is translated to Python.
?
Seeing that you are highly dependent on the documentation you might consider installing the "stable" client API 10.19 which I believe most of docs are centered around.
?
Also while this group is dedicated mostly to the original IBKR's client API, when it comes to Python the excellent independent alternative ib_async package is arguably much easier to use. But even then limitations of a naive copy-and-paste approach without learning key concepts and practices of the underlying programming language will betray themselves pretty soon. (Note that beside Python, the original client API is also available in C, C# and Java, so there's plenty of choices that could be more suitable to your experience).
?
--
Best,
DS


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Hello ´³¨¹°ù²µ±ð²Ô,
?
Thank you for this additional information. I have done as you suggested and changed the call for order cancellation to the following:
?
self.cancelOrder([orderId], OrderCancel)
?
Unfortunately this results in the following error, which terminates the program:
?
type object 'OrderCancel' has no attribute 'manualOrderCancelTime'
?
I have taken a look at the source code for Python for order cancellation (order_cancel.py)? and it looks like this:
?
"""
Copyright (C) 2024 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
?and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable.
"""
from ibapi.const import UNSET_INTEGER
from ibapi.object_implem import Object
from ibapi.utils import intMaxString
?
class OrderCancel(Object):
? ? def __init__(self):
? ? ? ? self.manualOrderCancelTime = ""
? ? ? ? self.extOperator = ""
? ? ? ? self.externalUserId = ""
? ? ? ? self.manualOrderIndicator = UNSET_INTEGER
?
? ? def __str__(self):
? ? ? ? s = "manualOrderCancelTime: %s, extOperator: %s, externalUserId: %s, manualOrderIndicator: %s" % (
? ? ? ? ? ? self.manualOrderCancelTime,
? ? ? ? ? ? self.extOperator,
? ? ? ? ? ? self.externalUserId,
? ? ? ? ? ? intMaxString(self.manualOrderIndicator),
? ? ? ? )
?
? ? ? ? return s
?
Unfortunately I am not well versed in Python beyond the basics from what I have learned from the sample code provided in the IBKR tutorials, so I am just unsure what I am doing wrong here and why this error is occurring. It is disappointing that the API documentation has not been updated by IBKR to reflect the changes made to this function from version 10.30+ so I at a loss as to how I can move past this error.
?
I am most grateful for your assistance.
?
Regards,
Scott.
?


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

If in doubt, the source code is still the best documentation, Scott.

I am not a Python practitioner, but I assume the OrderCancel class has a no-argument constructor that initializes the four fields with meaningful "empty" values. At least the Java implementation has one. Assuming you cancel orders infrequently, I'd replace the empty string "" parameter with something like new OrderCancel()?or the equivalent in Python.

My framework already has a convenience method void cancelOrder( int orderId ) that hides the extra parameters from the business logic (since I don't need the manualCancelTime or OrderCancel logic). In that case, a single shared and constant OrderCancel object will work, too.

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

?

?

On Tue, Sep 10, 2024 at 06:32 PM, <scott_hopgood@...> wrote:

Hello ´³¨¹°ù²µ±ð²Ô,
?
Thank you for your reply and apologies for not providing the version number I am using. I can confirm that I am using version 10.30.01 and so it seems that passing an empty string as per the original (and latest) documentation is no longer correct.?
?
In this case, would you know what should be passed for OrderCancel instead of an empty string? I searched the latest API documentation in IBKR Campus but I was unable to locate any information regarding the fields of the new OrderCancel class, so I am unable to adjust my call to include the default fields of this class in order to test it.
?
I appreciate your assistance with this.
?
Regards,
Scott.


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Hello ´³¨¹°ù²µ±ð²Ô,
?
Thank you for your reply and apologies for not providing the version number I am using. I can confirm that I am using version 10.30.01 and so it seems that passing an empty string as per the original (and latest) documentation is no longer correct.?
?
In this case, would you know what should be passed for OrderCancel instead of an empty string? I searched the latest API documentation in IBKR Campus but I was unable to locate any information regarding the fields of the new OrderCancel class, so I am unable to adjust my call to include the default fields of this class in order to test it.
?
I appreciate your assistance with this.
?
Regards,
Scott.


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Ah, thanks Juergen, this likely explains the problem. I use the "stable" client API source which is 10.19.01 and this feature's implementation in it seems outdated now.
?
--
Best,
DS


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Scott did not tell us, which TWS API version caused the issue. But I suspect it is 10.30 or higher.

Looks like 10.30.01 changed the cancelOrder() request signature:
  • from cancelOrder(self, orderId: OrderId, manualCancelOrderTime: str)
  • to cancelOrder(self, orderId: OrderId, orderCancel: OrderCancel)

That is true for all languages, not just Python. The new class OrderCancel has several fields, among them a string field called manualOrderCancelTime.

Programing languages other than Python should give you compilation errors since the second argument changed from type String to type OrderCancel.?Also, cancelOrder requests will likely fail unless and instance of OrderCancel is passed. An object with default fields might work, but I have not checked that.

The shiny new official TWS API documentation on IBKR Campus does not reflect that change yet and still suggests passing "" will work.
?
´³¨¹°ù²µ±ð²Ô
?
On Tue, Sep 10, 2024 at 01:39 PM, ds-avatar wrote:

This looks so weird that I felt curious enough to sift through the source further.
?
The Python IBAPI source does not contain text 'manualOrderCancelTime' at all so it totally escapes me how it could even throw an error message that you quoted, featuring this text. Beside all this, the error message itself does not follow from anything I see in the API source code.
?
That said, in Java and C# API that same argument is named 'manualOrderCancelTime'. But Python API is not dependent on either.
?
Pretty mind-boggling to say the least, and I still have only questions, no answers...
?
--
Best,
DS


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

This looks so weird that I felt curious enough to sift through the source further.
?
The Python IBAPI source does not contain text 'manualOrderCancelTime' at all so it totally escapes me how it could even throw an error message that you quoted, featuring this text. Beside all this, the error message itself does not follow from anything I see in the API source code.
?
That said, in Java and C# API that same argument is named 'manualOrderCancelTime'. But Python API is not dependent on either.
?
Pretty mind-boggling to say the least, and I still have only questions, no answers...
?
--
Best,
DS


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

The error is pretty strange but, FWIW, judging by the API source, the correct spelling must be 'manualCancelOrderTime' instead of 'manualOrderCancelTime':
?
? ? def cancelOrder(self, orderId:OrderId, manualCancelOrderTime:str):
?
?
--
Best,
DS


Using Excel

 

I appreciate this may have been answered (please point me to the thread - or a vba code example).
?
I have the TWS_ActiveX.xls working?
?
But I am unable to automate pulling down Account, Portfolio and Open order data using one button - I have to go to each tab and request data.
?
I am sure its a scoping/hierarchy within the code but I have been unable to make it work .
?
Any pointers - just want to press one button (preferably not on either of the account portfolio or open order tabs) and all data is refreshed
?
Many thanks
?
P
?


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Hey guys,
?
I was searching for some information about manualOrderCancelTime and came across this thread. I have been having some issues when attempting to cancel orders by way of Order ID. The orders are placed via the API and not via the TWS directly. I am using the following command in my python program to cancel orders by Order ID:
?
self.cancelOrder([orderId], "")?
?
This throws the following error and the program terminates:
?
'str' object has no attribute 'manualOrderCancelTime'
?
When I use the following command instead, to close all active orders, this works without any issues:
?
self.reqGlobalCancel()
?
I cannot figure out what is wrong here as I have seen by the earlier responses in this thread that I should only need to specify a single argument (the Order ID) and an empty string in order for this command to execute order cancellation.
?
Any assistance with this would be most appreciated.
?
Regards,
Scott.


Re: C++ TWS API reqMktDepth() giving 309 error

 

And I have no other contracts being requested in TWS.


Re: C++ TWS API reqMktDepth() giving 309 error

 

Ya that has to be it. I just ran it in my simulated account and it works no problem getting market depth.
?
Brendan


Re: C++ TWS API reqMktDepth() giving 309 error

 

Suppose I have windows open in my TWS platform requesting market depth. Would that count against the limit? That seems to be the only thing I can think of as I am 99% sure I am requesting only once in these projects and nothing else is running against TWS in my task manager.
?
Thanks,
Brendan


Re: C++ TWS API reqMktDepth() giving 309 error

 

No problem here. Just tried NQZ4 as the third subscription through a paper account that already had two active reqMktDepth subscriptions for other instruments. Worked as expected.

Any chance you are indeed requesting market depth subscriptions for more than three different instruments simultaneously? Keep in mind that TWS L2 tools count against the three subscription limit, in case you use those.

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

?
?
On Tue, Sep 10, 2024 at 08:16 AM, Brendan Lydon wrote:

Anyone else experiencing this? Same error code / thing happening in a python dummy script I put together as well for reqMktDepth() w/ ib_insync() api. My subscriptions all seem to be in tact too...


Re: C++ TWS API reqMktDepth() giving 309 error

 

Anyone else experiencing this? Same error code / thing happening in a python dummy script I put together as well for reqMktDepth() w/ ib_insync() api. My subscriptions all seem to be in tact too...