lolokraus / DegiroAPI

An unofficial API for the trading platform Degiro, with the ability to get real time data and historical data
MIT License
215 stars 86 forks source link

Search products #55

Open AureliusMarcusHu opened 1 year ago

AureliusMarcusHu commented 1 year ago

The code below works, that's not the problem. My problem is: there is always only one element in the list of dicts. While some the isin code will be traded on different exchanges, you will expect that there are more elements in the list. But it is not. How i search a product by isin on a specific exchange. For example: below a copy from deGiro. As You can see: name, isin and symbol are the same, the only difference is the exchange. How I search the product traded on the Milan exchange ?

example

` def login(): global dgr dgr = degiroapi.DeGiro() dgr.login("nnnnn", "xxxxxx")

prdcts = dgr.search_products(isin) for prd in prdcts: print(prd) `

Jakub-CZ commented 1 year ago

When you examine the products returned by search_products, you'll notice different value of exchangeId in each of them.

The meaning of those IDs can be found here: https://trader.degiro.nl/product_search/config/dictionary. With that, you can simply loop through the products until you find the one whose exchangeId matches the exchange that you want.

For myself and others, I've added this functionality to my fork of this abandoned project: https://github.com/Jakub-CZ/DegiroAPI/commit/2f89f91836db37f6a7337bbb01d739b058e893ef

My latest version can be installed like this:

pip install -U git+https://github.com/Jakub-CZ/DegiroAPI.git

A little demo:

dgr = degiroapi.DeGiro()
...
print(dgr.id_dictionary["exchanges"]['196'])
prods = dgr.search_products("DE0005785604", limit=10)
print(tabulate([(p["id"], p["name"], dgr.id_dictionary["exchanges"][p["exchangeId"]]["name"]) for p in prods],
               tablefmt="fancy_grid"))
{'id': 196, 'code': 'XGAT', 'hiqAbbr': 'TDG', 'country': 'DE', 'city': 'Frankfurt', 'micCode': 'XGAT',
 'name': 'Tradegate AG'}
╒══════════╤════════════════════════╤═══════════════════════╕
│ 19747326 │ Fresenius SE & Co KGaA │ Tradegate AG          │
├──────────┼────────────────────────┼───────────────────────┤
│     3959 │ Fresenius SE & Co KGaA │ Xetra                 │
├──────────┼────────────────────────┼───────────────────────┤
│  8368522 │ Fresenius SE & Co KGaA │ Borse Frankfurt       │
├──────────┼────────────────────────┼───────────────────────┤
│ 10902626 │ Fresenius SE & Co KGaA │ Borsa Italiana S.p.A. │
╘══════════╧════════════════════════╧═══════════════════════╛