问题描述
我使用 IB API
是为了在开市前时间自动触发订单。
我无法弄清楚为什么订单要等待开市时间而不是在开市前期间购买。查看 API
文档后,我添加了拍卖订单,但在开市前期间仍然无法购买。
这是我的代码示例:
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.order import *
from threading import Timer
class TestApp(EWrapper,EClient):
def __init__(self):
EClient.__init__(self,self)
def error(self,reqId,errorCode,errorString):
print("Error: "," ",errorString)
def nextValidId(self,orderId ):
self.nextOrderId = orderId
self.start()
def orderStatus(self,orderId,status,filled,remaining,avgFillPrice,permId,parentId,lastFillPrice,clientId,whyHeld,mktCapPrice):
print("OrderStatus. Id: ",",Status: ",Filled: ",Remaining: ",LastFillPrice: ",lastFillPrice)
def openorder(self,contract,order,orderState):
print("Openorder. ID:",contract.symbol,contract.secType,"@",contract.exchange,":",order.action,order.orderType,order.totalQuantity,orderState.status)
def execDetails(self,execution):
print("ExecDetails. ",contract.currency,execution.execId,execution.orderId,execution.shares,execution.lastLiquidity)
def start(self):
contract = Contract()
contract.symbol = "AAPL"
contract.secType = "STK"
contract.exchange = "IDEALPRO"
contract.currency = "USD"
contract.primaryExchange = "NASDAQ"
order = Order()
order.action = "BUY"
order.tif = "AUC"
order.totalQuantity = 10
order.orderType = "MTL"
order.lmtPrice = 1000
# order = Order()
# order.action = "BUY"
# order.totalQuantity = 10
# order.orderType = "LMT"
# order.lmtPrice = 1000
self.placeOrder(self.nextOrderId,order)
def stop(self):
self.done = True
self.disconnect()
def main():
app = TestApp()
app.nextOrderId = 0
app.connect("127.0.0.1",7497,0)
Timer(3,app.stop).start()
app.run()
if __name__ == "__main__":
main()
解决方法
不确定是否理解您的观点,但您无法在拍卖期间执行订单,直到它们结束(您只能下订单)。对于开盘竞价,意味着您的订单将在市场开盘后执行。