Understanding the lemon.markets Market Data API

blog photo
Marius SprengerSeptember 2, 2021

Hey there. My name is Marius, and I’m the community developer at lemon.markets, an early-stage startup from the heart of Berlin, Germany. We are working on building an infrastructure that enables developers to build their own brokerage experience at the stock market. In this blog post, I want to take a closer look at one of our core products: the Market Data API. Together, we will explore how the API is structured, what kind of data you can retrieve with it and how that might be helpful for your very own trading product.

Title Card for the Article "Understanding the lemon.markets Market Data API"

What’s the point of getting Market Data?

If you ever were in the position of wanting to develop your own trading strategy (since you managed to click on this blog post and read until this sentence, we assume that the probability of this is rather high), you most certainly thought about using (historical) market data for it. While there are some examples where quantifiable market data plays a subordinate role (sentiment analysis of text data being the most prominent example), a large majority of (automated) trading strategies indeed work with historic or real-time stock prices to make a buy or sell decision. Check out one of our previous articles for an overview of popular, beginner-friendly trading strategies. You will notice that there are many ways to integrate market data into your trading strategy, which is why we do not want to dive too deep into what the best way to do so actually is.

However, we want to outline why we at lemon.markets think that Market Data is important. The answer lies (at least partly) in our name. The goal of lemon.markets was always to improve the experience of buying equities at the stock market. While we have a clear developer focus right now, the underlying principle goes much deeper. We want to avoid that people make uninformed investment decisions. How do you avoid that? We think by using data.

“Without data you’re just another person with an opinion”

W. Edwards Deming

This quote by the famous statistician W. Edwards Deming perfectly captures how we think about lemon.markets and making investment decisions in general. If you have access to extensive data, chances are high that you will make better decisions. Obviously, historical patterns do not necessarily imply future patterns, but they are definitely a good place to start. In the case of buying equities at the stock market, this data is market data. And that is how we can bridge the gap to the famous Market for Lemons Theory, which deals with information asymmetry between buyer and seller along the example of used cars (in American slang, used cars that turn out to be broken after purchasing them, are referred to as “lemons”). By giving the buyer (our customers who want to buy or sell equities) structured and extensive information and the freedom/flexibility to build their brokerage product based on this, we believe that we can close the information asymmetry gap at the stock market (at least to some extent). By looking at our users’ behaviour, we noticed that the market data endpoints are among the most frequently used ones, which pretty much proved our point that access to market data is an important use case and thus product for us at lemon.markets.

Market Data API Structure

Realising that market data is important is one thing. Translating that realisation into an API structure is another. Below, find the structure that we came up with.

Structure of API

The base URL of our Market Data API is:


Using that base URL, we implemented five different endpoints that fulfil different purposes. We will discuss those in a second. However, the principle behind each endpoint structure is the same. For example, if you want to retrieve instruments, you would use the/instruments/endpoint.To specify your request, you can use different query parameters (e.g. ?search to search for ISIN, WKN or Title, or ?type to search for stocks, bonds, ETFs, warrants or funds. Find out more about the respective endpoint query parameters and the Market Data API in general in our docs).

Using the Endpoints

Actually trying out the different endpoints is probably the best way to understand the API structure. Therefore, we set up a small example project that allows you to use all Market Data API endpoints conveniently. You can find the GitHub repository here.

To work with environment variables, we first want to create a file called .env.

Let us include the following variables in there:

  • API_KEY: Your API key
  • BASE_URL: “https://data.lemon.markets/v1/”
  • MIC: The Market Identifier Code of the Trading Venue you want to address.

Using the os and the python-dotenv packages, we can access those variables in our local setup (we’ll get to that in a second). But first, let us define a helper file, which we can use to perform requests. Let’s call it helper.py. Within that class,we can define a class RequestHandler that we can later use to conveniently make API requests through a predefined function. As the Market Data API only offers GET requests, we only need one function get_data().This allows us to conveniently use the function throughout our project ( → This way, we avoid duplicated code).

1import os
2import requests
3from dotenv import load_dotenv
4class RequestHandler:
5    load_dotenv()
6    url: str = os.environ.get("BASE_URL")
7    def get_data(self, endpoint: str):
8        response = requests.get(self.url + endpoint,
9                                headers={
10                                    "Authorization": "Bearer "+os.environ.get("API_KEY")
11                                })
12        return response.json()

Next, we want to create a model for our Market Data and create a class for it. Let’s call the file MarketData.py. Using the get_response function, we can pass a specific endpoint with the function to then get the data that we want.

1from dotenv import load_dotenv
2from helper import RequestHandler
3class MarketData(RequestHandler):
4    def get_response(self, endpoint):
5        load_dotenv()
6        endpoint = endpoint
7        response = self.get_data(endpoint)
8        return response

The class comes in handy for our main.py file, which we are going to work in next. In there, we can import the Market Data class using:

1from models.MarketData import MarketData

Subsequently, we can define a number of exemplary functions to show how our endpoints work.

Trading Venues

We can define a function get_venues() to retrieve all trading venues available on lemon.markets. By defining the variable endpoint, we can define what is added to our base URL. If we wanted to retrieve a specific venue, we could add ?mic={mic} to the endpoint and access our environment variable MIC through that.

Feel free to play around with it a little bit and see how the API reacts to your modified request URLs. Check out our documentation for specific information on the /venues/ endpoint.

1def get_venues():
2    endpoint = f'venues/'
3    response = MarketData().get_response(endpoint)
4    print(response)


Our Market Data also offers the possibility to search for/filter for different instruments. Following a similar concept as above, we define the endpoint that is added to the base URL.

1def get_instruments():
2    endpoint = f'instruments/'
3    response = MarketData().get_response(endpoint)
4    print(response)

There are a number of different query parameters that we could attach to the /instruments/ endpoint, such as

  • ?isin → retrieve a specific instrument, identified by its ISIN
  • ?search → using this query parameter, we can, e.g., search for ISIN, WKN or Title
  • ?tradable → we can filter for instruments that are currently tradable

Again, check out our docs to find a full list of query parameters for the /instruments/ endpoint.


Using the /quotes/ endpoint, you can access (well): Quotes. Using quotes can be helpful for your trading strategy, as you get information about the price and trading volume of a specific instrument (how it is “quoted” on the stock exchange). As quotes are always returned for a specific ISIN, that query parameter is mandatory, leading to the following “minimal” request URL with the ISIN for Coinbase:

1def get_quotes():
2    endpoint = f'quotes/?isin=US19260Q1076'
3    response = MarketData().get_response(endpoint)
4    print(response)

You could also add additional query parameters, such as ?decimals, which is a Boolean value with which you can decide between returning the numbers in the API response either as Decimal or Integer. In a similar fashion, you could also set the date in your preferred format (?epoch=true for UNIX Timestamp or ?epoch=false for the ISO Date). Again, check out our docs for a full list of query parameters for the /quotes/ endpoint.


Using the /ohlc/ endpoint, you can retrieve the typical candlestick data (Open High Low Close) for specific instruments. Here, you need to additionally add {x1} to the URL, which specifies what type of OHLC data you want to retrieve (m1 for data on a per-minute basis, h1 for data on a per-hour basis, d1 for data on a per-day basis). Similar as with the /quotes/ endpoint, the ?isin query parameter is also mandatory here. By the way, you can also request data for multiple instruments by adding a second ISIN to the query parameters, either divided by a comma or by adding a second isin={ISIN}.

1def get_ohlc():
2    endpoint = f'ohlc/d1/?isin=DE0008404005'
3    response = MarketData().get_response(endpoint)
4    print(response)

Additionally, you also have the option to set a time range for which you want to retrieve the OHLC data by using the query parameters from and toYou can either specify a date in epoch or in ISO date formatCheck out the docs for more information on the OHLC endpoint.


Finally, you also have the option to retrieve trades for a specific instrument using the /trades/ endpoint. Same as with the /quotes/ and /ohlc/ endpoint, setting an ISIN as query parameter is mandatory, as the API returns previous trades for a specific instrument. Take a look at this basic request example.

1def get_trades():
2    endpoint = f'trades/?isin=US19260Q1076'
3    response = MarketData().get_response(endpoint)
4    print(response)

To specify your request, e.g. to get the trades for multiple instruments in a numbers and date format of your choice, check out the docs for more information on the /trades/ endpoint query parameters.

Possible Extensions

We tried to give you a condensed overview of our Market Data API. However, when talking market data, you almost naturally think about real-time data. We did not simply forget this feature, but we need some time until we can offer it to you. Right now, a clear priority for us is to build stable and scalable services, which is why we are tackling different projects one by one to “do things right”. We will of course immediately inform you when we have a stable real-time market data service. To stay up to date: sign up for lemon.markets now and join our Slack Community.

While we provide you with “raw” market data through our API, there are a lot of possibilities to use the data to calculate different key performance indicators that might help you in making an investment decision. Check out one of our previous articles that discusses 10 resources to get you started in automated trading.

And if you are still missing something: let us know. We believe that lemon.markets will never be “finished” and we are trying to integrate user feedback/suggestions whenever possible.


We hope you got a good understanding of our Market Data API. Let us sum up our main takeaways:

  • The Market Data API is a separate product within the lemon.markets universe
  • It consists of 5 different main endpoints:
  1. /venues/
  2. /instruments/
  3. /quotes/
  4. /ohlc/{x1}
  5. /trades/
  • You can specify your request for each endpoint by using Query Parameters

We are really excited to see all of your trading projects in action soon. We hope that the Market Data API will help you make better investment decisions. If you are in desperate need of inspiration for a project: check out our other blog articles where we present different use cases and ideas. If you are interested in getting featured on our blog with your own project, just send us an email to support@lemon.markets and we will get back to you 🙂.

Looking forward to seeing you on lemon.markets soon.


You might also be interested in

blog photo

Blog 38 - The market maker explained

Market Makers are crucial to provide liquidity to stock exchanges. In this blog post, we talk about what Market Makers do and why they are useful.

blog photo

5 (+1) YouTube channels for FinTech enthusiasts 

YouTube is a great way to learn about new things, including financial education or coding. Therefore, in this article we’d like to introduce you to 5 YouTube channels to level up your trading literacy.

blog photo

A short introduction to derivatives

In this article, we'd like to introduce you derivatives - they come up in finance and leave a lot of people scratching their heads, though it's totally worth it! Curious about hearing what's the difference between investing and trading, the coherence between finance and weather & why the Greeks even appear here? We'll discuss who’s using them, what they are and how they can be valued in the following.

Dive Deeper

Find more resources to get started easily

Check out our documentation to find out more about our API structure, different endpoints and specific use cases.


Join lemon.markets community

Join our Slack channel to actively participate in our community, ask questions to other users and stay up to date at all times.


Interested in building lemon.markets with us?

We are always looking for great additions to our team that help us build a brokerage infrastructure for the 21st century.

Need any help?
Ask a question in our CommunityAsk a question in our CommunityGet started with our DocumentationGet started with our DocumentationGet inspired on our BlogGet inspired on our Blog
© lemon.markets 2021Privacy PolicyImprint
All systems normal

As a tied agent under § 3 Sec. 2 WplG on the account and under the liability of DonauCapital Wertpapier GmbH, Passauer Str. 5, 94161 Ruderting (short: DonauCapital), lemon.markets GmbH offers you the receipt and transmission of orders for clients (§ 2 Sec. 2 Nr. 3 WpIG) of financial instruments according to § 3 Sec. 5 WpIG as well as brokerage of accounts.