Я новичок в python и TWS API, моя проблема в том, что я хочу использовать идентификатор ошибки, который создается с помощью Error. Id: 441 Код: 200 Сообщение: Для запроса не найдено определения безопасности, хотя оно отображается в терминале, но я не могу получить его в переменной для дальнейшего использования в моем коде
вот мой код
[from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.order import *
import threading
import time
class IBapi(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def nextValidId(self, orderId: int):
super().nextValidId(orderId)
self.nextorderId = orderId
print('The next valid order id is: ', self.nextorderId)
def orderStatus(self, orderId, status, filled, remaining, avgFullPrice, permId, parentId, lastFillPrice, clientId, whyHeld, mktCapPrice):
print('orderStatus - orderid:', orderId, 'status:', status, 'filled', filled, 'remaining', remaining, 'lastFillPrice', lastFillPrice)
def openOrder(self, orderId, contract, order, orderState):
print('openOrder id:', orderId, contract.symbol, contract.secType, '@', contract.exchange, ':', order.action,
order.orderType, order.totalQuantity, orderState.status)
def execDetails(self, reqId, contract, execution):
print('Order Executed: ', reqId, contract.symbol, contract.secType, contract.currency, execution.execId, execution.orderId, execution.shares, execution.lastLiquidity)
def error(self, reqId, errorCode, errorString):
super().error(reqId, errorCode, errorString)
print("Error. Id:", reqId, "Code:", errorCode, "Msg:", errorString)
def run_loop():
app.run()
# Function to create STOCK Order contract
def STK_order(stock_ticker,):
contract = Contract()
contract.symbol = stock_ticker
contract.secType = "STK"
contract.exchange = "NSE"
contract.currency = "INR"
return contract
app = IBapi()
app.connect('127.0.0.1', 7497, 123)
app.nextorderId = None
# Start the socket in a thread
api_thread = threading.Thread(target=run_loop, daemon=True)
api_thread.start()
# Check if the API is connected via orderid
while True:
if isinstance(app.nextorderId, int):
print('connected')
break
else:
print('waiting for connection')
time.sleep(1)
# Create order object
def place_order(place_order_action, place_order_quantity, place_order_order_type):
order = Order()
order.action = place_order_action
order.totalQuantity = place_order_quantity
order.trailingPercent = 0.5
order.trailStopPrice = 1612
order.lmtPrice = 1613
order.orderType = place_order_order_type
order.trailingPercent = 5
return order
stocks_list = [['ICICINIFTY', '628.00', 'NSE', 'BUY', 1]]
oid = app.nextorderId
for stock_ticker, open_price, stock_market, stock_action, stock_quantity in stocks_list:
app.placeOrder(oid, STK_order(stock_ticker), place_order(stock_action, stock_quantity, 'LMT'))
oid = oid + 1
# app.nextorderId += 1
time.sleep(1)
app.disconnect()
вот результат:
The next valid order id is: 443
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:hfarm
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfarm
Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:hkhmds
Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:ushmds
Error. Id: -1 Code: 2158 Msg: Sec-def data farm connection is OK:secdefhk
ERROR -1 2104 Market data farm connection is OK:hfarm
ERROR -1 2104 Market data farm connection is OK:usfarm
ERROR -1 2106 HMDS data farm connection is OK:hkhmds
ERROR -1 2106 HMDS data farm connection is OK:ushmds
ERROR -1 2158 Sec-def data farm connection is OK:secdefhk
connected
ERROR 443 200 No security definition has been found for the request
Error. Id: 443 Code: 200 Msg: No security definition has been found for the request
я хочу получить Ошибка. Id: 443 в переменную для дальнейшего использования