简体   繁体   中英

How to suppress Interactive Broker error warnings Jupyter, Python

In a Jupyter notebook, I am trying to suppress Error 200 messages from the Interactive Broker's TWS API, such as the following:

Error 200, reqId 12755: No security definition has been found for the request, contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20210721', strike=407.5, right='P', exchange='SMART')

Error 200, reqId 12761: No security definition has been found for the request, contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20210721', strike=412.5, right='P', exchange='SMART')

I have used the following code to no avail:

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

or

import warnings
warnings.filterwarnings('ignore')

You can suppress messages with a specific code by writing your own error handling routine. This callback method checks the code and only prints messages that aren't Error 200:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM