在交互式经纪人 API 中,我如何检查是否已经有未平仓订单,或者我是否正在为 python 中的特定合约进行交易。网上好像找不到答案
非常感谢
在交互式经纪人 API 中,我如何检查是否已经有未平仓订单,或者我是否正在为 python 中的特定合约进行交易。网上好像找不到答案
非常感谢
我相信只要您试图将未结订单打印在里面,我就找到了答案
openOrder() 函数直接取自文档
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):
self.nextValidId = orderId
self.start()
def start(self):
self.reqAllOpenOrders()
def openOrder(self, orderId, contract: Contract, order: Order,
orderState):
super().openOrder(orderId, contract, order, orderState)
print("OpenOrder. PermId: ", order.permId, "ClientId:", order.clientId, " OrderId:", orderId,
"Account:", order.account, "Symbol:", contract.symbol, "SecType:", contract.secType,
"Exchange:", contract.exchange, "Action:", order.action, "OrderType:", order.orderType,
"TotalQty:", order.totalQuantity, "CashQty:", order.cashQty,
"LmtPrice:", order.lmtPrice, "AuxPrice:", order.auxPrice, "Status:", orderState.status)
def run_loop():
app.run()
app = IBapi()
app.connect('127.0.0.1', 7497, 123)
# Start the socket in a thread
api_thread = threading.Thread(target=run_loop, daemon=True)
api_thread.start()
time.sleep(3)
app.disconnect()