Chavithra / degiro-connector

This is yet another library to access Degiro's API.
BSD 3-Clause "New" or "Revised" License
205 stars 46 forks source link

Finding product id's in a script? #69

Closed 123m321 closed 6 months ago

123m321 commented 2 years ago

I noticed it's very cumbersome to find the product ID's for instruments. I can find the stock list, but finding Dutch FTI futures or german bund or eurostoxx futures is giving me headaches.

Wouldn't it be convenient to create a script where user input (select exchange, country, product type) will give the required product id?

Chavithra commented 2 years ago

Hello,

Do you want something like this ? python search_product.py --type stock --text="AAPL"

Which options do you think this script should have ?

Thanks

123m321 commented 2 years ago

I made a quick and dirty script to search and find id's. I think it may help (at least, it helped me!)

(updated it a bit, maybe include it in the docs?)

# IMPORTATIONS
import json
import pandas as pd
import degiro_connector.core.helpers.pb_handler as payload_handler

from degiro_connector.trading.api import API as TradingAPI
from degiro_connector.trading.models.trading_pb2 import Credentials, ProductSearch

# SETUP CONFIG DICT
with open("config/config.json") as config_file:
    config_dict = json.load(config_file)

# SETUP CREDENTIALS
int_account = config_dict.get("int_account")
username = config_dict.get("username")
password = config_dict.get("password")
totp_secret_key = config_dict.get("totp_secret_key")
one_time_password = config_dict.get("one_time_password")

credentials = Credentials(
    int_account=int_account,
    username=username,
    password=password,
    totp_secret_key=totp_secret_key,
    one_time_password=one_time_password,
)

# SETUP TRADING API
trading_api = TradingAPI(credentials=credentials)

# ESTABLISH CONNECTION
trading_api.connect()

print("search products in DeGiro\n")
print("(S) Stock / (B) Bond / (E) ETF / (O) Option / (F) Future")
category = input("which category are you looking for? (S/B/E/O/F) ")
if category.lower() not in ["s", "b", "e", "o", "f"]:
      category = input("try again, type a category (S/B/E/O/F)")

stockcode = input("Which search term?") 

# SETUP REQUEST
request_lookup = ProductSearch.RequestLookup(
    search_text = stockcode,
    limit=10000,
    offset=0,
    product_type_id=0,
)

# FETCH DATA
products_lookup = trading_api.product_search(request=request_lookup, raw=False)
products_lookup_dict = payload_handler.message_to_dict(message=products_lookup)
pretty_json = json.dumps(products_lookup_dict, sort_keys=True, indent=4)
df = pd.DataFrame(products_lookup_dict['products'])

if category.lower() == "f":
    df = df[df.productType == "FUTURE"]
elif category.lower() == "s":
    df = df[df.productType == "STOCK"]
elif category.lower() == "o":
    df = df[df.productType == "OPTION"]
elif category.lower() == "b":
    df = df[df.productType == "BOND"]
elif category.lower() == "e":
    df = df[df.productType == "ETF"]

if len(df) > 0:
    dfclear = df[['name','symbol', 'productType', 'currency']]
    print (dfclear)

    details = input("\nDetails on which number? ")
    print (df.loc[int(details),:])
else:
    print("{} returned no results".format(stockcode))
nine1zero commented 2 years ago

my quick and dirty way, is carefully put in favourites from web all products I am interested (country, exchange..), and then fetch fav table (containing product ids) to issue automatic buys... but the script very convenient thanks !

Chavithra commented 6 months ago

Closing the ticket.