Understanding the lemon.markets Trading API

2. Dezember 2021

Offering our users the possibility to conveniently trade via an API is what we at lemon.markets have been working on on a daily basis over the past year. In this blog post, I want to introduce you to the structure and functionalities of our Trading API so you can easily get started building your own brokerage experience at the stock market. Let’s get going. 

Title Card for the Article "Understanding the lemon.markets Trading API"

Why trade via an API?

The starting point for lemon.markets was in early 2020 when we painfully realised that there’s no brokerage service in Europe that allows its users to build a trading product in a flexible way, just as they imagine it. What initially started as an interface to automate your trades, lemon.markets evolved into an infrastructure that gives you the freedom to build (basically) any kind of product. Some people may be unsatisfied with the current offering of trading apps and want to create their own application. Others may be interested in setting up an automated trading strategy that does all the work for them. Some people might even be interested in placing a trade in their favourite messaging app (what a coincidence, see an example for a Telegram Trading bot here). 

So, we set out on bringing this infrastructure to life and (tada 🎉) have now arrived at a point where we want to share what we created with all of you. 

You can see the structure of our Trading API below. 

This is the structure of our Trading API

Let’s dive into the endpoints

As you can see, there are two base URLs for our Trading API:




We have separate URLs for Paper and for Real Money Trading. The APIs follow a near-identical structure (with some real-money specifics). This means that before exposing your product to your hard earned money, you can safely deploy it to a simulated paper-money environment. All without making any changes to your implementation. And once you’re happy with it, you can simply exchange the base URL and your project will be running as before, only this time with real money.

For the rest of the article, we will use the Paper Money base URL for demonstration purposes. We will take a look at: 

  • how to retrieve your account information,
  • how to create a new order and see previous orders,
  • how to see all your transactions and
  • how to monitor your positions.

If you are interested in diving deeper into our API: check out our docs. There, you will also find information about how to get access to the API

Getting Started

The easiest way to communicate with the lemon.markets API is to make use of thelemon.markets Python SDK, which can easily be installed through:

1pip install lemon

The initial step for using the SDK (and subsequently making requests to the API) is to instantiate a client, like this:

1def __init__(self):
2        self.client = api.create(
3            market_data_api_token=os.getenv("DATA_API_KEY"),
4            trading_api_token=os.getenv("TRADING_API_KEY"),
5            env="paper"
6    )

Note that in line 3 and 4 we are accessing environment variables, which you need to create and define before that step, typically in a .env file. Here, we are using separate API Keys for market data and trading, as required by the lemon.markets API. You can create your Trading and Market Data API Keys in theDashboard.

Interacting with your account

To retrieve information about your account such as name, email address, the IBAN of your brokerage account or how much cash you have left to invest, make a request against the /account endpoint. See below how to address this endpoint. 

1def get_account():
2  response=client.trading.account.get()
3  print(response)


Placing orders is one of the core features of the Trading API. You can do that with one simple request. In there, you specify all things relevant for your order placement. Let’s look at an example:

1# create buy order
2response = client.trading.orders.create(
3    isin='US88160R1014',
4    side='buy',
5    quantity=1,
7order_id = response.results.id
8# activate buy order
9response = client.trading.orders.activate(order_id=order_id)

Afterwards, you way want to retrieve your previous orders:

1# get orders
2response = client.trading.orders.get()


Finally, using our Trading API you can also retrieve all of your positions by calling the /positions endpoint. To make the request more specific, you can query by ISIN:

1# get positions
2response = client.trading.positions.get(isin='US88160R1014')


Alright, that was our little deep dive into the lemon.markets Trading API. We hope you learned something and are now more than hyped to start building. We can’t wait to have you on board. Side note: the Trading API is only one of the two APIs that we offer, the other one is our Market Data API, which you can learn more about here.

We are looking forward to seeing what you are building with us. Make sure to sign up on lemon.markets and build your own brokerage experience at the stock market 🍋 ❤️


Das könnte Dich auch interessieren

blog photo

Using Time Series Forecasting to predict stock prices 🔮

In this article you will learn what time series forecasting is and how its application in finance looks like. Then you'll also dive into Facebook's Prophet Model for Time Series Forecasting and use it together with the lemon.markets Market Data API to forecast the development of the Tesla Stock.

blog photo

Dummies Guide to Trading with Machine Learning

Ever wonder how a trader with decades of experience on thousands of stocks and lightning fast reaction times might perform in the market? With some machine learning knowledge, you might be able to automate such a trader yourself! 💻 📈

blog photo

4 reasons why YOU should automate your trading strategy

In the current volatile market conditions, everyone is trying to find ways to minimise portfolio loss. In that context, have you ever thought about automating your trading strategy? In this article, we will dive into 4 reasons for doing so. Expect to learn how it can save you time, make your trading more efficient and lead to data-based decisions.

Tiefer eintauchen

Finde weitere Ressourcen für einen einfachen Einstieg

In unserer Dokumentation erfahrt Ihr mehr über unsere API-Struktur, die verschiedenen Endpunkte und spezifische Anwendungsfälle.


Tritt der lemon.markets Community bei

Tritt unserem Slack-Channel bei, um Dich aktiv an unserer Community zu beteiligen, Fragen an andere Nutzer:innen zu stellen und immer auf dem Laufenden zu bleiben.

Team unterstützen

Lust lemon.markets mit uns zu bauen?

Wir sind immer auf der Suche nach großartigen Ergänzungen für unser Team, die uns beim Aufbau einer Brokerage Infrastruktur für das 21. Jahrhundert helfen.

Brauchst Du Hilfe?
Stell Deine Fragen in unserer CommunityStell Deine Fragen in unserer CommunityLeg mit unserer API Dokumentation losLeg mit unserer API Dokumentation losLass Dich von unserem Blog inspirierenLass Dich von unserem Blog inspirieren
© lemon.markets 2022DatenschutzImpressum
Systems are down

Als vertraglich gebundener Vermittler gemäß § 3 Abs. 2 WpIG für Rechnung und unter der Haftung der DonauCapital Wertpapier GmbH, Passauer Str. 5, 94161 Ruderting (kurz: DonauCapital), bietet Dir die lemon.markets GmbH, die Anlagevermittlung (§ 2 Abs. 2 Nr. 3 WpIG) von Finanzinstrumenten im Sinne des § 3 Abs. 5 WpIG sowie die Vermittlung von Konten an.