Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the --search key - search by part of the ticker or the full description of the instrument #7

Closed
Tim55667757 opened this issue Jul 1, 2022 · 1 comment
Assignees
Labels
Feature New feature, request or an idea
Milestone

Comments

@Tim55667757
Copy link
Owner

No description provided.

@Tim55667757 Tim55667757 added the Feature New feature, request or an idea label Jul 1, 2022
@Tim55667757 Tim55667757 self-assigned this Jul 1, 2022
@Tim55667757 Tim55667757 added this to the release-1.2 milestone Jul 11, 2022
Tim55667757 added a commit that referenced this issue Aug 17, 2022
…g `SearchInstruments()` has been implemented
Tim55667757 added a commit that referenced this issue Aug 17, 2022
Tim55667757 added a commit that referenced this issue Aug 17, 2022
Tim55667757 added a commit that referenced this issue Aug 17, 2022
@Tim55667757
Copy link
Owner Author

Added the ability to search for an instrument by part of the name, ticker or FIGI with--search key (or -s). A method for searching SearchInstruments() has been implemented, to which a search pattern can be passed as input: part of a word or a string with a regular expression. As a result, the method returns a dictionary of dictionaries, similar to variable iList, but containing only found instruments.

Find an instrument

To work with exchange instruments, receive information on them, request prices and make deals, you usually need to specify a ticker (key --ticker) or FIGI (key --figi). But there are hardly many people who know them by heart. Most often, there is only an assumption about a part of the ticker or the name of the company. In this case, you can use the search by pattern: part of the name, ticker or FIGI, or by specifying a regular expression. The search is performed by the standard python module re, case-insensitive.

Starting with TKSBrokerAPI v1.2.*, the --search key has been added, after which you need to specify the pattern. For example, you want to find all the instruments of the Russian Sber group of companies, then you can try to specify a part of the word: tksbrokerapi --search "sber". Or you want to know all the instruments of companies whose names contain the word "United" with "medical" or "rent". In this case, you can try to specify a regular expression: tksbrokerapi --search "(United.*).*(?:.*medical|rent)".

In addition to the --search key, you can specify the --output key and define the file name where to save the search results. By default, full search results are stored in search-results.md. Only the first 5 found instruments of each type are shown in the console.

After the desired instrument has been found and its ticker and FIGI have become known, you can view more detailed information with the command tksbrokerapi -t TICKER --info or tksbrokerapi -f FIGI --info (more).

Command to search for an instrument by part of its name
$ tksbrokerapi --search "sber"

TKSBrokerAPI.py     L:1067 INFO    [2022-08-11 23:42:54,569] # Search results

* **Search pattern:** [sber]
* **Found instruments:** [7]

**Note:** you can view info about found instruments with key `--info`, e.g.: `tksbrokerapi -t TICKER --info` or `tksbrokerapi -f FIGI --info`.

### Shares: [3]

| Type       | Ticker       | Full name                                                      | FIGI         |
|------------|--------------|----------------------------------------------------------------|--------------|
| Shares     | SBER         | Сбер Банк                                                      | BBG004730N88 |
| Shares     | SBERP        | Сбер Банк - привилегированные акции                            | BBG0047315Y7 |
| Shares     | SBER@GS      | Sberbank of Russia PJSC                                        | BBG001VBZR00 |

### Bonds: [4]

| Type       | Ticker       | Full name                                                      | FIGI         |
|------------|--------------|----------------------------------------------------------------|--------------|
| Bonds      | RU000A102CU4 | Сбер Банк 001P-SBER19                                          | BBG00Y9B45C2 |
| Bonds      | RU000A102RS6 | Сбер Банк 001P-SBER24                                          | BBG00ZZ927H8 |
| Bonds      | RU000A101C89 | Сбер Банк 001P-SBER15                                          | BBG00RKBQ4D2 |
| Bonds      | RU000A103G75 | Сбер Банк 001P-SBER32                                          | BBG0122KNFZ0 |

TKSBrokerAPI.py     L:1068 INFO    [2022-08-11 23:42:54,569] You can view info about found instruments with key `--info`, e.g.: `tksbrokerapi -t IBM --info` or `tksbrokerapi -f BBG000BLNNH6 --info`
TKSBrokerAPI.py     L:1074 INFO    [2022-08-11 23:42:54,569] Full search results were saved to file: [search-results.md]
Command to search for an instrument by regular expression
$ tksbrokerapi --search "(United.*).*(?:.*medical|rent)"

TKSBrokerAPI.py     L:1067 INFO    [2022-08-12 00:08:08,944] # Search results

* **Search pattern:** [(United.*).*(?:.*medical|rent)]
* **Found instruments:** [2]

**Note:** you can view info about found instruments with key `--info`, e.g.: `tksbrokerapi -t TICKER --info` or `tksbrokerapi -f FIGI --info`.

### Shares: [2]

| Type       | Ticker       | Full name                                                      | FIGI         |
|------------|--------------|----------------------------------------------------------------|--------------|
| Shares     | GEMC         | United medical group                                           | BBG011MCM288 |
| Shares     | URI          | United Rentals                                                 | BBG000BXMFC3 |

TKSBrokerAPI.py     L:1068 INFO    [2022-08-12 00:08:08,944] You can view info about found instruments with key `--info`, e.g.: `tksbrokerapi -t IBM --info` or `tksbrokerapi -f BBG000BLNNH6 --info`
TKSBrokerAPI.py     L:1074 INFO    [2022-08-12 00:08:08,945] Full search results were saved to file: [search-results.md]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature, request or an idea
Projects
None yet
Development

No branches or pull requests

1 participant