I found it difficult to get shortableShares data with ib.reqMktData(contract, genericTickList='236'), but it became very easy when 4 threads were turned on.
I guess there is something wrong with passing genericTickList in asyncio, but I haven't confirmed it.
My code is as follows:
from concurrent.futures import ThreadPoolExecutor
from ib_insync import *
import asyncio
def asy_shortableShares(symbol, clientId):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
ib = IB()
for i in range(5):
ib.connect('127.0.0.1', 4001, clientId=clientId)
with ThreadPoolExecutor(max_workers=4) as executor:
futures = [executor.submit(asy_shortableShares, symbol, clientId) for clientId in range(4)]
for future in futures:
result = future.result()
if result is not None:
return result
return None
I found it difficult to get shortableShares data with ib.reqMktData(contract, genericTickList='236'), but it became very easy when 4 threads were turned on. I guess there is something wrong with passing genericTickList in asyncio, but I haven't confirmed it. My code is as follows:
from concurrent.futures import ThreadPoolExecutor from ib_insync import * import asyncio
def asy_shortableShares(symbol, clientId): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) ib = IB() for i in range(5): ib.connect('127.0.0.1', 4001, clientId=clientId)
def get_shortableShares(symbol):
float clientId 1:4
if name == "main": symbol = "AAPL"