Package: python-degiro
DegiroAPIAn unofficial API for the trading platform Degiro written in Python with the ability to get real time data and historical data for products.DEPRECATED!The packagedegiro-connectorcontains the same and much more functionality.
It is also maintained well. Hence, the decision to deprecate this repository.CreditsThis project is a fork fromDegiroAPIbylolokrauz.
It was not actively maintained anymore, hence the creation of this repository.Added changesOver the original repository the following things were added:Pre-commit hooks.Style and type checking.Dependencies handled by the setup instead of the user.Typing information all over the code.Removed logic from__init__.Renaming of function, parameters and variables to adhere to pythons snake_case.Getting StartedInstallingpipinstalldegiroapiLogging infrmodegiroapi.degiroimportDeGirodegiro=DeGiro()degiro.login("username","password")Logging outdegiro.logout()Available Functionsloginlogoutget_datasearch_productsproduct_infotransactionsordersdelete_orderreal_time_priceget_stock_listbuy_ordersell_orderget_dataPrinting your current cash funds:fromdegiroapi.data_typeimportDataTypecashfunds=degiro.get_data(DataType.CASHFUNDS)fordataincashfunds:print(data)Printing your current portfolio, argument True to filter out products with a size of 0, False or no Argument to show all:fromdegiroapi.data_typeimportDataTypeportfolio=degiro.get_data(DataType.PORTFOLIO,True)fordatainportfolio:print(data)search_productsSearching for a product:products=degiro.search_products('Pfizer')print(Product(products[0]).id)product_infoPrinting info for a specified product ID:info=degiro.product_info(331823)print(info["id"],info["name"],info["currency"],info["closePrice"])transactionsPrinting your transactions in a given time interval:fromdatetimeimportdatetime,timedeltatransactions=degiro.transactions(datetime(2019,1,1),datetime.now())print(pretty_json(transactions))ordersPrinting your order history(the maximum timespan is 90 days)
With argument True, this function only returns open ordersfromdatetimeimportdatetime,timedeltaorders=degiro.orders(datetime.now()-timedelta(days=90),datetime.now())print(pretty_json(orders))orders=degiro.orders(datetime.now()-timedelta(days=90),datetime.now(),True)print(pretty_json(orders))delete_orderDeleting an open order with the orderIdorders=degiro.orders(datetime.now()-timedelta(days=1),datetime.now(),True)degiro.delete_order(orders[0]['orderId'])degiro.delete_order("f278d56f-eaa0-4dc7-b067-45c6b4b3d74f")real_time_priceGet the real time price and the historical data of a stock:fromdegiro.interval_typeimportIntervalTypeproducts=degiro.search_products('nrz')# Interval can be set to One_Day, One_Week, One_Month, Three_Months, Six_Months, One_Year, Three_Years, Five_Years, Maxrealprice=degiro.real_time_price(Product(products[0]).id,IntervalType.One_Day)# getting the real time priceprint(realprice[0]['data']['lastPrice'])print(pretty_json(realprice[0]['data']))# getting historical dataprint(realprice[1]['data'])get_stock_listGet the symbols of the S&P500 stocks:sp5symbols=[]products=degiro.get_stock_list(14,846)forproductinproducts:sp5symbols.append(Product(product).symbol)Get the symbols of the german30 stocks:daxsymbols=[]products=degiro.get_stock_list(6,906)forproductinproducts:daxsymbols.append(Product(product).symbol)buy_orderPlacing a buy order is dependent on the order Type:Limit orderYou have to set a limit order price to which the order gets executed.arguments: order type, product id, execution time type (either 1 for "valid on a daily basis", or 3 for unlimited, size, limit(the limit price)fromdegiroapi.order_typeimportOrderTypedegiro.buy_order(OrderType.LIMIT,Product(products[0]).id,3,1,30)StopLimit orderSets a limit order when the stoploss price is reached (not bought for more than the limit at the stop loss price):arguments: order type, product id, execution time type (either 1 for "valid on a daily basis", or 3 for "unlimited"), size, limit(the limit price), stop_loss(stop loss price)fromdegiroapi.order_typeimportOrderTypedegiro.buy_order(OrderType.STOPLIMIT,Product(products[0]).id,3,1,38,38)Market orderBought at the market price:arguments: order type, product id, execution time type (either 1 for "valid on a daily basis", or 3 for "unlimited"), sizefromdegiroapi.order_typeimportOrderTypedegiro.buy_order(OrderType.MARKET,Product(products[0]).id,3,1)StopLoss orderThe stop loss price has to be higher than the current price, when current price reaches the stoploss price the order is placed:arguments: order type, product id, execution time type (either 1 for "valid on a daily basis", or 3 for "unlimited"), sizefromdegiroapi.order_typeimportOrderTypedegiro.buy_order(OrderType.STOPLOSS,Product(products[0]).id,3,1,None,38)sell_orderPlacing a sell order is dependent on the order Type:
Equivalent to the buy orders:fromdegiroapi.order_typeimportOrderTypedegiro.sell_order(OrderType.LIMIT,Product(products[0]).id,3,1,40)fromdegiroapi.order_typeimportOrderTypedegiro.sell_order(OrderType.STOPLIMIT,Product(products[0]).id,3,1,37,38)fromdegiroapi.order_typeimportOrderTypedegiro.sell_order(OrderType.MARKET,Product(products[0]).id,3,1)fromdegiroapi.order_typeimportOrderTypedegiro.sell_order(OrderType.STOPLOSS,Product(products[0]).id,3,1,None,38)UsageFor documented examples seeexamples.pyContributingHow great this project will turn out to be, totally depends on you.
If you think you have a great addition, please create a PR :).
If you are unfamilar withpull requests, please take a lookhere.RequirementsIn order for your commit to be accepted, please install pre-commit.
This will run a couple of tools to make sure the formatting of the code is good and there are no obvious mistakes.Installing pre-commitpre-commitinstallNow everytime you will commit, it will automatically run the pre-commit hooks.
If you are using Pycharm, the errors appear ingit(left bottom) -> console.