期货互动经纪商下单价差Python

问题描述 投票:0回答:1

我正在尝试使用 python API 发送具有两个不同到期日的期货价差订单。

未来1 SR3Z7 未来2 SR3M8

我正在点击此链接来创建合同。 https://interactivebrokers.github.io/tws-api/spread_contracts.html

我点击此链接创建一个简单的订单。 https://interactivebrokers.github.io/tws-api/basic_orders.html

我的代码运行没有任何错误,但是当我签入TWS时,它不起作用。

当我使用TWS时,我可以手动发送具有相同期货点差的订单。

任何可以帮助我理解我的 python 代码有什么问题的人。


from ib_insync import *

ib = IB()
ib.connect('127.0.0.1', 7497, clientId=3)

### contract
contract = Contract()
contract.symbol = 'SR3'
contract.secType = "BAG"
contract.exchange = "CME"
contract.currency = "USD"

leg1 = ComboLeg()
leg1.conId = 385575897  # SR3Z7
leg1.ratio = 1
leg1.action = "BUY"
leg1.exchange = "CME"

leg2 = ComboLeg()
leg2.conId = 385575856  # SR3M8
leg2.ratio = 1
leg2.action = "SELL"
leg2.exchange = "CME"

contract.comboLegs = []
contract.comboLegs.append(leg1)
contract.comboLegs.append(leg2)

spread_order = Order()
spread_order.action = 'BUY'
spread_order.orderType = "MKT"
spread_order.totalQuantity = 1
spread_order.smartComboRoutingParams = []
spread_order.smartComboRoutingParams.append(TagValue('NonGuaranteed', '1'))

ib.placeOrder(contract, spread_order)

我已经尝试将 future 更改为 stock,它有效。

python interactive-brokers tws
1个回答
0
投票

尝试contract.secType =“FUT”

© www.soinside.com 2019 - 2024. All rights reserved.