【问题标题】:How to suppress Interactive Broker error warnings Jupyter, Python如何抑制 Interactive Broker 错误警告 Jupyter、Python
【发布时间】:2021-07-12 20:04:39
【问题描述】:

在 Jupyter 笔记本中,我试图抑制来自 Interactive Broker 的 TWS API 的错误 200 消息,例如:

错误 200,reqId 12755:未找到请求的安全定义,合约:Option(symbol='SPY', lastTradeDateOrContractMonth='20210721', strike=407.5, right='P', exchange='SMART' )

错误 200,reqId 12761:未找到请求的安全定义,合约:Option(symbol='SPY', lastTradeDateOrContractMonth='20210721', strike=412.5, right='P', exchange='SMART' )

我使用以下代码无济于事:

import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')

或

import warnings
warnings.filterwarnings('ignore')

【问题讨论】:

    标签: python jupyter interactive-brokers tws


    【解决方案1】:

    您可以通过编写自己的错误处理例程来抑制带有特定代码的消息。此回调方法检查代码并仅打印不是错误 200 的消息:

    @iswrapper
    def error(self, req_id, code, msg):
        if code != 200:
            print('Error {} for request {}: {}'.format(code, req_id, msg))
    

    【讨论】:

    • 有没有办法在 Jupyter 笔记本中实现这一点?我正在使用 ib_insync 与 API 交互。
    • error 方法由EWrapper 类提供。我确定有人使用 ib_insync 编写了自定义 error 回调。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-14
    • 1970-01-01
    • 2018-03-03
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多