gpt4 book ai didi

python - 下订单时出现错误201交互式经纪人tws

转载 作者:行者123 更新时间:2023-12-03 08:40:14 27 4
gpt4 key购买 nike

我试图通过模拟交易在模拟账户上下达期权定单。我遵循了该教程,但是在运行代码时,出现错误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类中使用其他订单属性指定将订单发送到的帐号。例如。

order.account = "DU12345"
如果可用于交易的分区标记为“DU12345”。它的末尾可能有一个“C”。您应该能够在交易平台的右上角找到该帐号,或者通过建立连接后自动调用的API managedaccts()回调找到该帐号。
http://interactivebrokers.github.io/tws-api/financial_advisor_methods_and_orders.html#api_orders

关于python - 下订单时出现错误201交互式经纪人tws,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62178597/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com