我是 ib_insync 的新手,我正在用 django 实现 ib_insync。当我使用placeOrder()下订单时,我收到错误RuntimeError: There is no current event loop in thread 'Thread-1'。
我的意见.py
def placeOrder(request, account):
print("ACCOUNT: ", account)
symbol = 'AAPL'
action = 'BUY'
strike = 145
date = '20210430'
quantity = 1
currency = 'USD'
secType = 'OPT'
exchange = 'SMART'
right = 'C'
contract, order = create_contract(action, quantity, symbol, secType, date, strike, right,exchange, account)
trade = place_order(contract, order)
以下是方法
def place_order(contract, order):
place_order = ib.placeOrder(contract, order)
return place_order
def create_contract(action, quantity, symbol, secType, lastTradeDateOrContractMonth, strike, right, exchange, account):
contract = Option(symbol, lastTradeDateOrContractMonth, strike, right, exchange)
order = MarketOrder(action, quantity)
order.account = account
return contract, order
错误:
File "C:\Users\Jason\Desktop\TradeApp\venv\lib\site-packages\ib_insync\client.py", line 268, in sendMsg
loop = asyncio.get_event_loop()
File "c:\users\jason\appdata\local\programs\python\python39\lib\asyncio\events.py", line 642, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-1'