Manage your positions with the trading API

blog photo
Marius SprengerJanuary 6, 2022

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 brokerage API. 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 API.

The easiest way to communicate with the API is to make use of the 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 API. You can create your Trading and Market Data API Keys in the Dashboard.

Using the /positions endpoint

To access your positions, use the following URL:


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

1# get positions
2response =

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

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  ]

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. 

1# get positions
2response ='US88160R1014')

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 with more than 400 developers.

See you there,

Marius & the 🍋.markets team

You might also be interested in

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 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.

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 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 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
© 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), GmbH offers you the receipt and transmission of orders for clients (§ 2 Sec. 2 Nr. 3 WpIG) of financial instruments according to § 2 Sec. 5 WpIG as well as brokerage of accounts.