Manage your positions with the lemon.markets trading API


blog photo
Marius SprengerJanuary 6, 2022
Trading


An important part of a functional brokerage service is the possibility to conveniently monitor everything related to your positions. Therefore, in this blog post, I want to dive deeper into how to keep an overview of your positions with the lemon.markets brokerage API. 

lemon.markets was born out of the wish/need to have more flexibility in the way you manage your trading activities. The result of months of iteration with our beta users is an API that allows you to build your own brokerage experience at the stock market, customised to your individual use case. Check out our documentation to learn more about the structure of our API and what you can build with it. 

We offer different endpoints to, for instance, buy or sell stocks, retrieve historical market data or manage your account. However, in this blog post we we want to specifically deal with the /positions endpoint which allows you to conveniently monitor your (who would’ve guessed?) positions. 

In general, your positions are all the different instruments that are the result of executed orders. This means that if you have no positions and you place an order for 10 Tesla shares, once that order is executed (i.e. placed and filled at the stock market) your positions are comprised of 10 shares of Tesla. 

Let’s take a look at how you get that information through the lemon.markets API.

Using the /positions endpoint

To access your positions, use the following URL:

1https://paper-trading.lemon.markets/v1/positions/

Below, find an example code snippet in Python. Check out our documentation for additional code snippets in JavaScript. 

1import requests request = requests.get("https://paper-trading.lemon.markets/v1/positions/",                        headers={"Authorization": "Bearer YOUR-API-KEY"})print(request.json())

Making the request stated above will result in a response similar to this one:

1{
2  "time":"2021-11-21T19:34:45.071+00:00",
3  "status": "ok",
4  "mode": "paper",
5  "results": [
6    {
7     "isin": "US19260Q1076",
8     "isin_title": "COINBASE GLOBAL INC.",
9     "quantity": 5,
10"buy_price_avg": 2260400,
11"estimated_price_total": 7350000,
12"estimated_price": 1470000
13    },
14    {
15      ...
16    }
17  ]
18}
19

The results part of the response is an array of objects. Each object represents a different position item and you can retrieve a lot of interesting information from it. For instance, the isin is the International Security Identification Number through which an instrument can uniquely be identified. Additionally, you receive information on the current quantity of the instrument in your positions, the average buy-in price and the estimated price.

Working with query parameters

While a general overview of all position items is nice, you might want to narrow your search. That’s what query parameters are for. In the /positions endpoint, you can query for the isin, which allows you to see only position items for a specific instrument.

Using the query parameters is really easy, you simply add them to your request URL. 

1import requests
2request = requests.get("https://paper-trading.lemon.markets/v1/positions/?isin=US88160R1014", 
3                       headers={"Authorization": "Bearer YOUR-API-KEY"})
4print(request.json())

This will result in only Tesla position items being displayed.

And now: what to do with it?

The possibilities from here on are (almost) endless. You could build your own dashboard to display your positions using some cool charts, you could integrate the information in your own custom trading app or build an analysis tool that automatically buys or sells stock to rebalance your positions. Get creative!

We are really excited for you to try out our API and help shape a product that developers enjoy using. Make sure to sign up on our website and join our growing Slack community where we discuss all things lemon.markets with more than 400 developers.

See you there,

Marius & the 🍋.markets team

You might also be interested in

blog photo

Profiting in Bear Markets with 5 Useful Algorithmic Trading Strategies

You may have heard the term “bear market” being thrown around a lot recently on the news and online. Perhaps you have looked at your favourite stock picks and only see red. In this article, we explain what bear markets are and algorithmic strategies that can be advantageous during a bear market.

blog photo

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.

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.

Engage

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.

Contribute

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 2022Privacy PolicyImprint
Systems are down

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.