【问题标题】:How to get the current bidding price for a contract如何获得合同的当前投标价格
【发布时间】:2017-06-30 17:47:09
【问题描述】:

有人可以帮助我开始使用 IBPY 做一些基本的事情吗?使用 IBPY,我只想能够查询商品的当前竞价价格,例如 Google 中单个股票的价格 - 或当前的欧元/美元汇率。

我在这里找到了页面底部的示例:

Fundamental Data Using IbPy

有用 - 但输出有点混乱。如何打印以仅筛选单个合同的当前出价/要价?

(只是一些生物信息——是的,我是 IBPY 和 python 的新手——但我确实有超过 20 年的 C 经验)

提前致谢!

【问题讨论】:

  • 执行与该示例相同的操作,但为 tickPrice 注册一个回调并实现一个处理程序。之后只需reqMktData 用于合同,如果您只想要一个报价,则应将isShanshot 设置为true。试试这个并编写一些代码,完成后给我留言,我会看看。

标签: ibpy


【解决方案1】:

使用您提到的示例,稍作改动:

import signal

from ib.opt import ibConnection, message
from ib.ext.Contract import Contract


def price_handler(msg):
    if msg.field == 1:
        print("bid price = %s" % msg.price)
    elif msg.field == 2:
        print("ask price = %s" % msg.price)


def main():
    tws = ibConnection(port=7497)
    tws.register(price_handler, message.tickPrice)
    tws.connect()

    tick_id = 1
    c = Contract()
    c.m_symbol = 'AAPL'
    c.m_secType = 'STK'
    c.m_exchange = "SMART"
    c.m_currency = "USD"
    tws.reqMktData(tick_id, c, '', False)

    signal.pause()


if __name__ == '__main__':
    main()

输出:

bid price = 149.55
ask price = 149.56
bid price = 149.59
ask price = 149.61
...

【讨论】:

    猜你喜欢
    • 2019-12-10
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 2017-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-05
    相关资源
    最近更新 更多