簡體   English   中英

下期權訂單時出現錯誤 201 交互式經紀人 tws

[英]Error 201 interactive brokers tws while placing options order

我正在嘗試通過 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 模擬賬戶通常有一個分區賬戶結構來演示該功能。 在分區設置中,賬戶的一部分被“分區”以供財務顧問使用,而賬戶的 rest 由賬戶所有者交易。 每個部分都有一個唯一的識別號,用於查詢頭寸或進行交易。

向分區賬戶下訂單時,您只需在 IBApi 訂單 class 中指定您發送訂單的帳號以及其他訂單屬性。 例如

order.account = "DU12345"

如果可用於交易的分區標記為“DU12345”。 它的末尾可能有一個“C”。 您應該可以在 TWS 的右上角找到帳號,或者通過連接后自動調用的 API managedaccts()回調找到該帳號。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM