python-在 Interactive Broker 的 API 中为订单添加时间条件
发布时间:2022-07-10 01:49:13 325
相关标签: # node.js
晚上好,我需要很大的帮助,我们将不胜感激。我试图在订单中添加时间条件,但我不理解IBKR的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: ", reqId, " ", errorCode, " ", 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: ", orderId, ", Status: ", status, ", Filled: ", filled, ", Remaining: ", remaining, ", LastFillPrice: ", lastFillPrice)
def openOrder(self, orderId, contract, order, orderState):
print("OpenOrder. ID:", orderId, contract.symbol, contract.secType, "@", contract.exchange, ":", order.action, order.orderType, order.totalQuantity, orderState.status)
def execDetails(self, reqId, contract, execution):
print("ExecDetails. ", reqId, contract.symbol, contract.secType, contract.currency, execution.execId,
execution.orderId, execution.shares, execution.lastLiquidity)
def start(self):
contract = Contract()
contract.symbol = "AAPL"
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"
contract.primaryExchange = "NASDAQ"
order = Order()
order.action = "BUY"
order.totalQuantity = 10
order.orderType = "MKT"
order.lmtPrice = 185
self.placeOrder(self.nextOrderId, contract, order)
def stop(self):
self.done = True
self.disconnect()
def main():
app = TestApp()
app.nextOrderId = 0
app.connect("127.0.0.1", 7497, 9)
Timer(3, app.stop).start()
app.run()
if __name__ == "__main__":
main()
订单条件的文档可在以下位置找到:
https://interactivebrokers.github.io/tws-api/order_conditions.html
如何在上述代码中插入时间条件。假设我在2023年7月20日下午2:30买入100只AAPL股票?任何帮助都将不胜感激。
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报