【问题标题】:Place order with API IB向 API IB 下订单
【发布时间】:2019-08-09 19:15:49
【问题描述】:

在决定离开 Ibpy 并学习 API IB 后,我什至无法下订单。我究竟做错了什么?

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.order import *




#Def Market Order

class TestApp(EClient, EWrapper):
    def __init__(self):
        EClient.__init__(self, self)

    def nextValidId(self, orderId:int):
        self.nextOrderId = orderId
        print(orderId)
        self.start()


    def start(self):

        contract = Contract()
        contract.symbol = "ES"
        contract.secType = "FUT"
        contract.exchange = "GLOBEX"
        contract.currency = "USD"
        contract.lastTradeDateOrContractMonth = "201903"


        order = Order()
        order.action = "BUY"
        order.orderType = "MKT"
        order.totalQuantity = 1
        order.outsideRth = True

        self.placeOrder(self.nextOrderId, contract, order)

    def stop(self):
        self.done = True
        self.disconnect()

def main():
    app=TestApp()
    app.connect("127.0.0.1", 7496,420)
    app.nextOrderId = 0
    app.run()



if __name__ == "__main__":
    main()

删除了更多的 Ibpy 并替换为 ibapi

现在得到

%运行基本.py 394 错误 -1 2104 市场数据农场连接正常:usfuture 错误 -1 2104 市场数据农场连接正常:usfarm 错误 -1 2106 HMDS 数据场连接正常:ushmds ERROR 394 200 未找到请求的安全定义

【问题讨论】:

  • 'Contract' 对象没有属性 'conId

标签: python-3.x interactive-brokers


【解决方案1】:

from ib.ext.Contract import Contract from ib.ext.Order import Order

这些来自 IbPy,仅使用以 ibapi 开头的类。

【讨论】:

  • 感谢您指出这一点。所以 IBAPI 不喜欢我的安全定义?
  • 不要更改问题,以免答案变得无关紧要。
  • 你的新问题是contract.lastTradeDateOrContractMonth = "201903" 三月结束,使用201909
  • 非常感谢。复制和粘贴不是最好的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-29
  • 2021-12-02
  • 2021-12-07
  • 2018-07-07
  • 2016-02-19
  • 2020-10-26
相关资源
最近更新 更多