Understanding the lemon.markets Trading API
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.
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:
1https://paper-trading.lemon.markets/v1/
and
1https://trading.lemon.markets/v1/
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.
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.
1import requests
2request = requests.get("https://paper-trading.lemon.markets/v1/account/",
3 headers={"Authorization": "Bearer YOUR-API-KEY-HERE"})
4print(request.json())
Orders
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. Using the “isin” request parameter, we buy one share of Coinbase in the example below. Additionally, you can specify when you want the order to expire (“expires_at”).
1import requests
2import json
3request = requests.post("https://paper-trading.lemon.markets/v1/orders/",
4 data=json.dumps({
5 "isin": "US19260Q1076",
6 "expires_at": "2021-11-10T22:59:00.000+00:00",
7 "side": "buy",
8 "quantity": 1,
9 "venue": "XMUN",
10 "notes": "This is an informative note attached to my order"
11 }), headers={"Authorization": "Bearer YOUR-API-KEY-HERE"})
12print(request.json())
Afterwards, you may want to check the orders you already placed. You can filter the orders returned by the API by different query parameters. For example, you could be interested in only seeing buy orders for a specific ISIN. To retrieve these orders, use:
1import requests
2request = requests.get("https://paper-trading.lemon.markets/v1/orders/?side=buy&&isin=US88160R1014",
3 headers={"Authorization": "Bearer YOUR-API-KEY-HERE"})
4print(request.json())
Positions
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:
1import requests
2request = requests.get("https://paper-trading.lemon.markets/v1/positions/?isin=US88160R1014/",
3 headers={"Authorization": "Bearer YOUR-API-KEY-HERE"})
4print(request.json())
Conclusion
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 🍋 ❤️
Marius
You might also be interested in
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.
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.
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.
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.