python - IB API : Checking if in trade or have open order

标签 python api interactive-brokers ib-api

在交互式经纪商 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()

关于python - IB API : Checking if in trade or have open order,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69559894/

相关文章:

python - cv2.solvePnP 方法标志的 Python 常量是什么?

Python 字典 : there a speed difference between matching a numeric key over a word in python?

api - 我应该共享 Paypal API 凭据吗

python - 下订单时出现错误201交互式经纪人tws

algorithmic-trading - IBPY 获取正确的历史成交量数据

python - 匹配nltk语法中的字母数字字符串

python - 在 basemap 中使用 pcolormesh 填充区域

android - 网络图像在 android Flutter 中不显示

c++ - 从 C++ 应用程序自动构建 Lua api

python - 如何从盈透证券获取证券的 ISIN?