如何抑制盈透证券错误警告 Jupyter, Python

时间:2021-07-12 20:04:39

标签: python jupyter interactive-brokers tws

在 Jupyter 笔记本中,我试图抑制来自盈透证券的 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')

1 个答案:

答案 0 :(得分:0)

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

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