Код: Выделить всё
ib.qualifyContracts(*contracts)Код: Выделить всё
Exception in callback _SelectorSocketTransport._read_ready()
handle:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/events.py", line 88, in _run
self._context.run(self._callback,self._args)
RuntimeError: cannot enter context: is already entered
Код: Выделить всё
#!/usr/bin/env python
# coding: utf-8
import settings
from ib_async import *
util.patchAsyncio()
ib = IB()
connection = ib.connect(settings.host, settings.port, clientId=settings.master_client_id)
def options_trade(trade):
print ("Getting option greeks and other data...")
contracts = []
contracts.append(trade.contract)
print (contracts)
ib.qualifyContracts(*contracts)
# rest of code to execute would go here
def on_exec_details(trade:Trade, fill:Fill):
print ("Start execution details")
print ("Order status: ", trade.orderStatus.status)
print ("Fill execution price: ", fill.execution.price)
print (trade.contract)
print (trade.contract.secType)
if (trade.contract.secType != 'OPT'):
print ("Not an option contract, will not load greeks")
else:
# get greeks for this contract
print ("This is an option contract, will load greeks and IV data and save to spreadsheet")
print (trade.filledEvent)
options_trade(trade)
print ("End execution details")
ib.execDetailsEvent += on_exec_details
ib.run()
Подробнее здесь: https://stackoverflow.com/questions/785 ... -ib-insync
Мобильная версия