Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

ib_insync connection issue on a Mac #661

Open
semiter1 opened this issue Nov 25, 2023 · 8 comments
Open

ib_insync connection issue on a Mac #661

semiter1 opened this issue Nov 25, 2023 · 8 comments

Comments

@semiter1
Copy link

I have problem connecting to IB using ib_insync on a Mac, but without any problem on a PC. Below are some details:

The ib_insync code I ran is simple, and the same across systems. The setup for TWS seems to have no issue.
import ib_insync as ibis
ib = ibis.IB()
ib.connect('127.0.0.1', 7497, clientId=1)

Once I ran these three lines on a Mac, the Spyder console keeps running without any error message. I have two Macs, both having the same issue. I have no problem connecting to IB on a PC using this code.

I have no issue to connect to IB using IB's own code. That is,
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
class MyWrapper(EWrapper):
def init(self):
super().init()
wrapper = MyWrapper()
client = EClient(wrapper)
client.connect("127.0.0.1", 7497, clientId=1)
client.run()

However, when I ran the ib_insync code above after this, it freezes again. When I restart the kernel, the IB code no longer works, unless I restart the TWS and re login.

@tashmore
Copy link

tashmore commented Dec 6, 2023

What TWS version are you using? (Help -> About Trader Workstation, something like "Build 10.26.1i, Dec 5, 2023 4:14:06 PM")

@semiter1
Copy link
Author

semiter1 commented Dec 7, 2023

What TWS version are you using? (Help -> About Trader Workstation, something like "Build 10.26.1i, Dec 5, 2023 4:14:06 PM")

This is it:
Build 10.19.2g, Nov 7, 2023 4:31:02 PM Jolt Build 1.18.9, Jul 5, 2022 05:27:19 PM Nia Build 2.24.4, Apr 5, 2023 03:59:03 PM ModelNav Build 1.13.2, Jan 24, 2022 04:59:21 PM Riskfeed Build 2.45.4, Nov 21, 2022 05:49:05 PM

@tashmore
Copy link

tashmore commented Dec 7, 2023

Could it be a conflict between Spyder IDE and async run loops? What happens if you create a python file with this example code: https://github.com/erdewit/ib_insync#example , and run it from the command line (ie: python ./myfile.py)

@semiter1
Copy link
Author

semiter1 commented Dec 7, 2023

Could it be a conflict between Spyder IDE and async run loops? What happens if you create a python file with this example code: https://github.com/erdewit/ib_insync#example , and run it from the command line (ie: python ./myfile.py)

Thanks, tashmore. I had no problem downloading the data by running the example you provided. In this case, do you know how can I fix the issue I had?

@tashmore
Copy link

tashmore commented Dec 8, 2023

Try https://pypi.org/project/nest-asyncio/

pip3 install nest_asyncio

Then, before any async code, put:

import nest_asyncio
nest_asyncio.apply()

@semiter1
Copy link
Author

semiter1 commented Dec 9, 2023

Try https://pypi.org/project/nest-asyncio/

pip3 install nest_asyncio

Then, before any async code, put:

import nest_asyncio
nest_asyncio.apply()

Thank you. My code includes the nest_asyncio call exactly as you mentioned, and the program freezes. I think it is probably related to something else.

@erdewit
Copy link
Owner

erdewit commented Jan 14, 2024

To rule out any network issues, you can try the following code:

from ib_insync import *
util.patchAsyncio()
util.sleep(1)

If this doesn't work then I suspect Spyder on Mac just doesn't work with ib_insync. Spyder on Linux does work.

@halterc
Copy link

halterc commented Feb 5, 2024

To rule out any network issues, you can try the following code:

from ib_insync import *
util.patchAsyncio()
util.sleep(1)

If this doesn't work then I suspect Spyder on Mac just doesn't work with ib_insync. Spyder on Linux does work.

Tried this. It seems to be a problem with asyncio in Spyder on Mac M1. No solution found.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants