错误 201 盈透证券在下期权订单时 TWS



我正在尝试通过TWS在模拟账户上下期权订单。我按照教程进行操作,但是当我运行代码时,它给了我错误 201,"帐号无效或丢失"。我花了一些时间试图修复它,但似乎无法解决它。任何帮助将不胜感激。

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("Order Status ID: ", orderId, ", Status", status, ", Fiilled", filled, ", Remaining: ", remaining, ", Last Fill price: ", 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 = "VMW" ##self.symbol
contract.secType = "OPT"
contract.exchange = "SMART"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "20200619" #self.expirationDate
contract.strike = 152.5 #self.strikeP
contract.right = "C" #self.callorput
contract.multiplier = "100"
order = Order()
order.action = "BUY" #self.buyorsell
order.totalQuantity = 10
order.orderType = "MKT"
self.placeOrder(self.nextOrderId, contract, order)
def stop(self):
self.done = True
self.disconnect()
def main():
app = TestApp()
app.nextOrderId = 0
app.connect(host = 'XXXX', port=XXXX, clientId=X)
Timer(3, app.stop).start()
app.run()
if __name__ == '__main__':
main()

IB模拟账户通常有一个分区账户结构来演示该功能。在分区设置中,帐户的一部分被"分区"以供财务顾问使用,而帐户的其余部分由帐户所有者进行交易。每个部分都有一个唯一的识别号,用于查询头寸或进行交易。

向分区账户下订单时,您只需在 IBApi 订单类中指定发送订单的帐号以及其他订单属性。 例如

order.account = "DU12345"

如果可用于交易的分区标记为"DU12345"。它的末尾可能有一个"C"。您应该能够在TWS的右上角找到账号,或者通过APImanagedaccts()回调找到,该回调在建立连接后会自动调用。

http://interactivebrokers.github.io/tws-api/financial_advisor_methods_and_orders.html#api_orders

相关内容

  • 没有找到相关文章

最新更新