Lemons Can Be Sweet

Maximilian Wimmer
4 min readJul 17, 2021

Discovering Trading Liberty with lemon.markets

I started with learning python after I finished my studies in behavioral finance at uni. Coding my own equity trading strategy with the information available is always my first step before I actually decide to buy or sell a stock. Once the strategy is stable I apply it manually to my real portfolio. I wanted to optimize the process of trading so I was searching for an trading API. I discovered more then one solution and was starting to get excited. I signed up on the first website that was promoting an stable trading API. Unfortunately I live in Germany and I am not a US citizen so I am not able to create a account and trade equities in the US for now.

After days of searching for a possible trading platform I discovered a website named lemon.markets. The company is based in Germany and the lemon.markets API allows you to build your own trading strategies or application in a so called space. For now the lemon.markets API is in closed beta and you have to sign up for the waiting list to get early access. Once you are signed up for the closed beta the documentation leads the way to your first order that is placed on the Munich Stock Exchange (XMUN). I enjoy the design of the lemon.markets website and the sturcture of the documentation. The design is simple and effective. After the login you see the overview to watch all of your spaces.

Overview

We will quickly have a look at the structure of the API before we place an order and start with the portfolio management in python.

API Structure

The lemon.markets API consists of a variety of different endpoints that together enable you to place orders at the stock market, manage your previous orders and portfolio, and retrieve market data conveniently. The Graph below shows how the different API services are structured and related with each other.

Source: https://docs.lemon.markets/api-structure

Portfolio Management with lemon.markets API

First of all we are going to code a class that helps us with our portfolio management with the API. The goal is that we can call a class that helps us placing an order quickly and shows the portfolio data nicely.

Placing an Order

To place an order on lemon.markets API the order needs to be created and then activated. The lemon_markets class from lemon_markets.py allows us to quickly place and activate an order in one process.

When you run the code you see if the status of the order is activated.

Get Portfolio DataFrame

Since we want to have a nice overview of our portfolio we call the lemon_markets class and at get_portfolio_df.

The dataframe shows the data from the lemon.markets API and the international ticker. In case you want to get more information about a stock in your portfolio the international ticker can be useful. In the next article we are going to look at how we get more information about the stocks in the lemon.markets portfolio.

Stocks and Warrants DataFrame

If we want to get the stocks and the warrants in a separate dataframe we can call get_stocks_and_warrants_df().

To see the only stocks dataframe.

For the only warrants dataframe.

Get OHLC DataFrame

Now we want to get a quick overview of all stocks OHLC data.

Running the code will give you a single plot for each stock. Next we are going to a get the portfolio_close_df that will give us a more quick and clean overview with the stocks close and the ISIN.

Get Portfolio Return DataFrame

The portfolio return can be called as simple return and log return.

Get Weighted Portfolio Return DataFrame

The weighted portfolio return can be called with the same method as portfolio return. To see the overall performance of our portfolio we plot the cumulative return.

Sign up for lemon.markets

Sources:

Github:

--

--