有这样一个问题:我学习TWS API(Interactive Brokers),了解方法、类等。我注册了下单的逻辑控制单元,现阶段我无法理解-如何在终端下单不同条件下从终端收到的价格?可能这个问题是通过多线程解决的,但是,我不能完全理解如何实现这个。我求你帮忙。下面是从终端获取数据的代码,在 main () 块中 - 用于下订单的代码。我不明白如何附加到下订单 - 触发条件。提前感谢您提供的任何帮助和信息。
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.order import *
class TestApp(EWrapper,EClient):
def __init__(self):
EClient.__init__(self,self)
def error(self,reqId,errorCode,errorString):
print("Error: ",reqId," ",errorCode," ",errorString)
def updateMktDepth(self, reqId, position: int, operation: int,side: int, price: float, size: int):
print(price)
def main():
app = TestApp()
app.connect("127.0.0.1", 7497, 0)
es = Contract()
es.localSymbol = "ESZ9"
es.symbol = "ES"
es.secType = "FUT"
es.exchange = "GLOBEX"
es.currency = "USD"
app.reqMarketDataType(4)
app.reqMktDepth(1, es, 2, False, [])
app.reqPositions()
app.reqAllOpenOrders()
# QUESTION - how to place order, using any conditions with price? (for example: if price > 3000)
order = Order()
order.account = "DU1656058"
order.action = "SELL"
order.totalQuantity = 1
order.orderType = "LMT"
order.lmtPrice = 3055
app.placeOrder(11000, es, order)
app.run()
app.disconnect()
if __name__ == "__main__":
main()