开云体育

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

Re: Installing ib_async

 

Thank you. This is where it got messy. I noticed that the bin folder in my virtual env does not have 'activate'. It has only python, python3 and python 3.12. Also, this is a fresh install of Ubuntu.


Re: Installing ib_async

 

开云体育

I use venv in VS Code and it works simple for all my projects.? I haven't actually install ib_async yet, since ib_insync still works.? I should do that just to be sure.?
Also I'm using windows for most of my testing.
Mel





-------- Original message --------
From: "Pranav Lal via groups.io" <pranav@...>
Date: 2024-07-22 9:48 p.m. (GMT-08:00)
To: ib-async@groups.io
Subject: Re: [ib-async] Installing ib_async

Hi,

?

What happened when you tried using a virtual environment? I ask because I have always installed ib_insync this way.

?

Did you use the python native virtual environment? If yes, could you try virtualenv?

?

Pranav


Re: Installing ib_async

 

开云体育

Hi,

?

What happened when you tried using a virtual environment? I ask because I have always installed ib_insync this way.

?

Did you use the python native virtual environment? If yes, could you try virtualenv?

?

Pranav


Installing ib_async

 

Hello,

I tried to install the package on my Ubuntu laptop but got the error "This environment is externally managed".

After searching for resolutions online, first I tried the virtual environment option but that got messy. Instead I was able to install it using pipx with 'pipx install --include-deps ib_async' followed by 'pipx ensurepath'.

At this point, running 'pipx list' confirms that the package was installed but 'pip list' does not display it. (I think this is expected)

Now, when running my Python script to connect with IB and place orders, I'm getting 'ModuleNotFoundError' error.

Anyone know how to resolve this?

Thanks!


Re: Update order

 

开云体育

Confirmed, ?transmit=True is the solution.

Thanks for your inputs


On 13 Jul 2024, at 19:26, Gonzalo Saenz <yo@...> wrote:

?
This is what I thought too. I have updated my code, let’s see on Monday.

When I attach the stop loss order, I enter transmit=False to all orders, except the last attachment. I realised earlier today that on the log "Transmit=False”, which how I entered it.

Now I can only wait to Monday.

Thanks for your inputs.



On 13 Jul 2024, at 19:10, Jason via groups.io <muffles.amatory.0a@...> wrote:

The only other thing I can think of is that the STP isn’t getting transmitted (transmit=False) but I believe the default is transmit=True, however I don’t know offhand how a non-transmitted order’s order status presents.

On Sat, Jul 13, 2024 at 11:21 AM, Gonzalo Saenz via?<yo=gnzsnz.com_at_groups_io_k21bj418pxe6c8_756s0895@...> wrote:
Yes, STP has it’s parentId=MOO.orderId

Do you think this might be to problem?

On 12 Jul 2024, at 20:47, Jason via groups.io <muffles.amatory.0a@...> wrote:


Are you linking the STP order to the MOO via parentId?


On Fri, Jul 12, 2024 at 12:24 PM, Gonzalo Saenz via groups.io <yo=gnzsnz.com_at_groups_io_k21bj418pxe6c8_756s0895@...> wrote:
Hi,

I’m running an algo that triggers Market-on-Open orders. As it’s a MOO order the price is not known (although my logic will use a ticker to decide to trigger or not) at the time the order is created.

As I want to have a stop loss, I have added a commissionReportEvent handler. When orders are filled, I wait for the order to be fully filled, “trade.order.totalQuantity == fill.execution.cumQty” and I update the stop loss attached to the MOO order, with a stop loss price in line with the avg fill price.

This is working all fine. The problem that I have is that the updated order is never actually in status “submitted”. As per the orders notebook https://nbviewer.org/github/ib-api-reloaded/ib_async/blob/main/notebooks/ordering.ipynb, I update the order, execute placeOrder(contract,updated_order), status is ‘PendingSubmit’ then —> ‘PreSubmitted’ but it never reaches “Submited”

There is no error message, nothing on the log not TWS. I used to have some problems due to incorrect values on the order, but those were showing an actual error message. Now there is nothing.

Any pointer to the right direction will be appreciated.

Cheers











Re: What is the proper way to get an option's greeks?

 

is it fair to assume that it wouldn't work without?market?data subscription?

On Sun, Jul 14, 2024 at 12:21?PM Lipp F. via <flipp31a=gmail.com@groups.io> wrote:
Any code samples? TIA.


Re: What is the proper way to get an option's greeks?

 

During market hours you can do...


```
ticker = ib.reqMktData(option_contract,"",False,Flase)
ib.sleep(2)
ticker.modelGreeks
ticker.askGreeks
ticker.bidGreeeks
ticker.lastGreeks
```
See below for more details



What is the proper way to get an option's greeks?

 

Any code samples? TIA.


Re: Placing Trailing Stop Limit Orders

 

Hey please try this with PAPER account and assume everything I am saying is wrong, but from my experience it corresponds to the pct so trailingPct = 3 is 3% NOT 0.03. I talk about the specific example at 13:55 in video below.


Re: Placing Trailing Stop Limit Orders

 

Got it, thank you. Guess I'm unclear about the purpose of order.trailStopPrice and order.lmtPriceOffset fields. Is the following accurate?

order.trailStopPrice is calculated by the system as (1-trailingPercent) * (last price)
order.lmtPriceOffset is provided by the user

order.trailStopPrice is the price at which the order gets triggered with a limit price of (order.trailStopPrice - order.lmtPriceOffset)


Re: Update order

 

开云体育

?
This is what I thought too. I have updated my code, let’s see on Monday.

When I attach the stop loss order, I enter transmit=False to all orders, except the last attachment. I realised earlier today that on the log "Transmit=False”, which how I entered it.

Now I can only wait to Monday.

Thanks for your inputs.



On 13 Jul 2024, at 19:10, Jason via groups.io <muffles.amatory.0a@...> wrote:

The only other thing I can think of is that the STP isn’t getting transmitted (transmit=False) but I believe the default is transmit=True, however I don’t know offhand how a non-transmitted order’s order status presents.

On Sat, Jul 13, 2024 at 11:21 AM, Gonzalo Saenz via?<yo=gnzsnz.com_at_groups_io_k21bj418pxe6c8_756s0895@...> wrote:
Yes, STP has it’s parentId=MOO.orderId

Do you think this might be to problem?

On 12 Jul 2024, at 20:47, Jason via groups.io <muffles.amatory.0a@...> wrote:


Are you linking the STP order to the MOO via parentId?


On Fri, Jul 12, 2024 at 12:24 PM, Gonzalo Saenz via groups.io <yo=gnzsnz.com_at_groups_io_k21bj418pxe6c8_756s0895@...> wrote:
Hi,

I’m running an algo that triggers Market-on-Open orders. As it’s a MOO order the price is not known (although my logic will use a ticker to decide to trigger or not) at the time the order is created.

As I want to have a stop loss, I have added a commissionReportEvent handler. When orders are filled, I wait for the order to be fully filled, “trade.order.totalQuantity == fill.execution.cumQty” and I update the stop loss attached to the MOO order, with a stop loss price in line with the avg fill price.

This is working all fine. The problem that I have is that the updated order is never actually in status “submitted”. As per the orders notebook https://nbviewer.org/github/ib-api-reloaded/ib_async/blob/main/notebooks/ordering.ipynb, I update the order, execute placeOrder(contract,updated_order), status is ‘PendingSubmit’ then —> ‘PreSubmitted’ but it never reaches “Submited”

There is no error message, nothing on the log not TWS. I used to have some problems due to incorrect values on the order, but those were showing an actual error message. Now there is nothing.

Any pointer to the right direction will be appreciated.

Cheers










Re: Update order

 

The only other thing I can think of is that the STP isn’t getting transmitted (transmit=False) but I believe the default is transmit=True, however I don’t know offhand how a non-transmitted order’s order status presents.

On Sat, Jul 13, 2024 at 11:21 AM, Gonzalo Saenz via groups.io <yo=gnzsnz.com_at_groups_io_k21bj418pxe6c8_756s0895@...> wrote:

Yes, STP has it’s parentId=MOO.orderId

Do you think this might be to problem?

On 12 Jul 2024, at 20:47, Jason via groups.io <muffles.amatory.0a@...> wrote:


Are you linking the STP order to the MOO via parentId?


On Fri, Jul 12, 2024 at 12:24 PM, Gonzalo Saenz via groups.io <yo=gnzsnz.com_at_groups_io_k21bj418pxe6c8_756s0895@...> wrote:
Hi,

I’m running an algo that triggers Market-on-Open orders. As it’s a MOO order the price is not known (although my logic will use a ticker to decide to trigger or not) at the time the order is created.

As I want to have a stop loss, I have added a commissionReportEvent handler. When orders are filled, I wait for the order to be fully filled, “trade.order.totalQuantity == fill.execution.cumQty” and I update the stop loss attached to the MOO order, with a stop loss price in line with the avg fill price.

This is working all fine. The problem that I have is that the updated order is never actually in status “submitted”. As per the orders notebook https://nbviewer.org/github/ib-api-reloaded/ib_async/blob/main/notebooks/ordering.ipynb, I update the order, execute placeOrder(contract,updated_order), status is ‘PendingSubmit’ then —> ‘PreSubmitted’ but it never reaches “Submited”

There is no error message, nothing on the log not TWS. I used to have some problems due to incorrect values on the order, but those were showing an actual error message. Now there is nothing.

Any pointer to the right direction will be appreciated.

Cheers









Re: Placing Trailing Stop Limit Orders

 

开云体育

Hi,

TWS documentation has good examples




And the order reference

I’m using it like this and it works,?trailing_percent=1.5

In your case, you are missing a few fields there. As per the example from TWS

order = Order()
order.action = action
order.orderType =?"TRAIL LIMIT"
order.totalQuantity = quantity
order.trailStopPrice = trailStopPrice
order.lmtPriceOffset = lmtPriceOffset
order.auxPrice = trailingAmount

Trailing Stop Limit orders can be sent with the trailing amount specified as an absolute amount, as in the example below, or as a percentage, specified in the trailingPercent field.

In any case, there is nothing like testing different options until it works.


On 13 Jul 2024, at 17:52, R Malhotra <rachan.malhotra@...> wrote:

Hello,

Anyone who uses this order type, can you please confirm whether this code is correct to create an order with 1% trail? Most interested in the 'trailingPercent' field i.e. whether to pass the percent value as 1 or 0.01.

Are there any other fields needed for the order to correctly execute?

Thanks so much!

trailingStopOrder = ibi.Order(action=closingAction, totalQuantity=acccountPosition.position, orderType='TRAIL LIMIT', trailingPercent=1, account=acccountPosition.account, outsideRth= True, tif= "DAY")


Placing Trailing Stop Limit Orders

 

Hello,

Anyone who uses this order type, can you please confirm whether this code is correct to create an order with 1% trail? Most interested in the 'trailingPercent' field i.e. whether to pass the percent value as 1 or 0.01.

Are there any other fields needed for the order to correctly execute?

Thanks so much!

trailingStopOrder = ibi.Order(action=closingAction, totalQuantity=acccountPosition.position, orderType='TRAIL LIMIT', trailingPercent=1, account=acccountPosition.account, outsideRth= True, tif= "DAY")


Re: Update order

 

开云体育

Yes, STP has it’s parentId=MOO.orderId

Do you think this might be to problem?

On 12 Jul 2024, at 20:47, Jason via groups.io <muffles.amatory.0a@...> wrote:


Are you linking the STP order to the MOO via parentId?


On Fri, Jul 12, 2024 at 12:24 PM, Gonzalo Saenz via groups.io <yo=gnzsnz.com_at_groups_io_k21bj418pxe6c8_756s0895@...> wrote:
Hi,

I’m running an algo that triggers Market-on-Open orders. As it’s a MOO order the price is not known (although my logic will use a ticker to decide to trigger or not) at the time the order is created.

As I want to have a stop loss, I have added a commissionReportEvent handler. When orders are filled, I wait for the order to be fully filled, “trade.order.totalQuantity == fill.execution.cumQty” and I update the stop loss attached to the MOO order, with a stop loss price in line with the avg fill price.

This is working all fine. The problem that I have is that the updated order is never actually in status “submitted”. As per the orders notebook https://nbviewer.org/github/ib-api-reloaded/ib_async/blob/main/notebooks/ordering.ipynb, I update the order, execute placeOrder(contract,updated_order), status is ‘PendingSubmit’ then —> ‘PreSubmitted’ but it never reaches “Submited”

There is no error message, nothing on the log not TWS. I used to have some problems due to incorrect values on the order, but those were showing an actual error message. Now there is nothing.

Any pointer to the right direction will be appreciated.

Cheers









Re: Incorrect

 

Thanks, that is helpful

I had position = 800, order to sell 800, it initially filled 692/800
115708.497 positionEvent, position=108
115708.506 execDetailsEvent, Fill shares=692, cumQty=692, fill time=115707
115708.508 trade.fillEvent, Fill shares=692, cumQty=692, fill time=115707
115708.520 orderStatusEvent, filled=692
115708.535 execDetailsEvent, Fill shares=108, cumQty=800, fill time=115707
115708.537 trade.fillEvent, Fill shares=108, cumQty=800, fill time=115707
115708.540 orderStatusEvent, filled=800
Never received positionEvent, position=0

My current logic, which tries to work around the positionEvent bugginess, but is flawed, marks my position as verified if the positionEvent matches either all fills since the last verified time or an updatePortfolioEvent. In this case,
start: position = 800, verified
The first positionEvent sets position = 108, not verified
The first execDetailsEvent with the 692 fill makes it go back to verified as of the positionEvent time of 115708.497
The second execDetailsEvent with the 108 fill arrives, but the fill time of 115707 is before the time I verified the position, so I ignore it. This is wrong because the first positionEvent arrived after the remaining fill, even though it did not include it.

It sounds like I should just assume positionEvent is flawed and ignore it and only rely on execDetailsEvent or trade.fillEvent. Does that sound right?


On Fri, Jul 12, 2024 at 8:08?PM nkulki via <nkulki=hotmail.com@groups.io> wrote:
I don’t have much to add except to say that he’s 100% correct. I do the exact the same. Glad to hear others are doing what I do too


Re: Incorrect

 

I don’t have much to add except to say that he’s 100% correct. I do the exact the same. Glad to hear others are doing what I do too


Re: Update order

 


Are you linking the STP order to the MOO via parentId?


On Fri, Jul 12, 2024 at 12:24 PM, Gonzalo Saenz via groups.io <yo=gnzsnz.com_at_groups_io_k21bj418pxe6c8_756s0895@...> wrote:

Hi,

I’m running an algo that triggers Market-on-Open orders. As it’s a MOO order the price is not known (although my logic will use a ticker to decide to trigger or not) at the time the order is created.

As I want to have a stop loss, I have added a commissionReportEvent handler. When orders are filled, I wait for the order to be fully filled, “trade.order.totalQuantity == fill.execution.cumQty” and I update the stop loss attached to the MOO order, with a stop loss price in line with the avg fill price.

This is working all fine. The problem that I have is that the updated order is never actually in status “submitted”. As per the orders notebook https://nbviewer.org/github/ib-api-reloaded/ib_async/blob/main/notebooks/ordering.ipynb, I update the order, execute placeOrder(contract,updated_order), status is ‘PendingSubmit’ then —> ‘PreSubmitted’ but it never reaches “Submited”

There is no error message, nothing on the log not TWS. I used to have some problems due to incorrect values on the order, but those were showing an actual error message. Now there is nothing.

Any pointer to the right direction will be appreciated.

Cheers








Update order

 

Hi,

I’m running an algo that triggers Market-on-Open orders. As it’s a MOO order the price is not known (although my logic will use a ticker to decide to trigger or not) at the time the order is created.

As I want to have a stop loss, I have added a commissionReportEvent handler. When orders are filled, I wait for the order to be fully filled, “trade.order.totalQuantity == fill.execution.cumQty” and I update the stop loss attached to the MOO order, with a stop loss price in line with the avg fill price.

This is working all fine. The problem that I have is that the updated order is never actually in status “submitted”. As per the orders notebook , I update the order, execute placeOrder(contract,updated_order), status is ‘PendingSubmit’ then —> ‘PreSubmitted’ but it never reaches “Submited”

There is no error message, nothing on the log not TWS. I used to have some problems due to incorrect values on the order, but those were showing an actual error message. Now there is nothing.

Any pointer to the right direction will be appreciated.

Cheers


Re: unexpected keyword argument 'conid' in Contract()

 

The attribute is case sensitive, making conid an unsupported attribute verses conId.

>>> contract = Contract(conId=270639)
>>> contract
Contract(conId=270639)


















On Wednesday, July 10th, 2024 at 3:41 AM, Papageno via groups.io <hjm=pmeonline.net_at_groups_io_k289j40cpxdcc8_4b6s0895@...> wrote:

In the there is an example:?
Contract(conId=270639)
which should return a Contract Object. But I got the error:
Traceback (most recent call last):
? File "...\venv\lib\site-packages\IPython\core\interactiveshell.py", line 3577, in run_code
? ? exec(code_obj, self.user_global_ns, self.user_ns)
? File "<ipython-input-23-8d88e504d067>", line 1, in <module>
? ? Contract(conid=270639)
TypeError: Contract.__init__() got an unexpected keyword argument 'conid'

In the source:
...
@staticmethod
def create(**kwargs) -> "Contract":
"""
Create and a return a specialized contract based on the given secType,
or a general Contract if secType is not given.
"""
...
is no conId.

I thought if I have a conId, I dont need any further Contract description.

Am I wrong or is it a bug?

Regards
Hans