utilmon / EasyIB

Python wrapper for Interactive Brokers Client Portal Web API
BSD 3-Clause "New" or "Revised" License
89 stars 24 forks source link

Feature: add ability to filter instruments and contracts #7

Closed GoldenChrysus closed 2 years ago

GoldenChrysus commented 2 years ago

get_conid by default returns the first contract of the first instrument it finds. This causes problems if multiple markets have instruments using this symbol, as a contract different from what was expected might be returned. I found this when looking up the $MUB US equity, which is not the first $MUB instrument returned by IB, so I didn't receive the contract ID I wanted.

Two parameters, instrument_filters and contract_filters, are added to get_conid. instrument_filters filters the instrument data, i.e. the name, chineseName, and assetClass fields. contract_filters filters the contract data, i.e the exchange and isUS fields. All filters must be fulfilled for the instrument/contract to be included. The filters can be used together.

I've added some samples of searching for US $MUB using the filters.

sourcery-ai[bot] commented 2 years ago

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 6.76%.

Quality metrics Before After Change
Complexity 0.62 ⭐ 2.83 ⭐ 2.21 👎
Method Length 39.50 ⭐ 44.86 ⭐ 5.36 👎
Working memory 6.16 ⭐ 4.99 ⭐ -1.17 👍
Quality 85.66% 78.90% -6.76% 👎
Other metrics Before After Change
Lines 277 302 25
Changed files Quality Before Quality After Quality Change
src/easyib/easyib.py 85.66% ⭐ 78.90% ⭐ -6.76% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
src/easyib/easyib.py REST.get_conid 12 🙂 165 😞 50.25% 🙂 Try splitting into smaller methods
src/easyib/easyib.py REST.get_bars 2 ⭐ 70 🙂 11 😞 69.46% 🙂 Extract out complex expressions
src/easyib/easyib.py REST.modify_order 1 ⭐ 62 🙂 10 😞 73.59% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

utilmon commented 2 years ago

Thanks for the improvement!