简体   繁体   English

IB API:检查是否在交易或有未结订单

[英]IB API: Checking if in trade or have open order

In the interactive brokers API, How do I check if there is already an open order or if I'm in a trade for a specific Contract in python.在交互式经纪人 API 中,我如何检查是否已经有未结订单,或者我是否正在交易 Python 中的特定合约。 Can't seem to find an answer online网上好像找不到答案

Thanks a lot非常感谢

I believe I found an answer as long as you are trying to get the open orders be printed inside我相信只要您尝试将未结订单打印在里面,我就找到了答案

The openOrder() function was taken straight from the documentation 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM