Manage your trading portfolio with the brokerage API

blog photo
Published by Marius Sprenger on January 6, 2022

An important part of a functional brokerage service is the possibility to conveniently monitor everything related to your portfolio. Therefore, in this blog post, I want to dive deeper into how to keep an overview of your portfolio items 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 /portfolio endpoint which allows you to conveniently monitor your (who would’ve guessed?) portfolio. 

In general, your portfolio consists of different portfolio items that are the result of executed orders. This means that if your portfolio is empty and you place an order for 10 Tesla shares, once that order is executed (i.e. placed and filled at the stock market) your portfolio consists of 10 shares of Tesla stock. 

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

Using the /portfolio endpoint

To access your portfolio, use the following URL:


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

1import requests request = requests.get("",                        headers={"Authorization": "Bearer YOUR-API-KEY"})print(request.json())

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  "results": [
5    {
6     "space_id": "sp_pyPFYssNNJyV4m8rxtK7LnfGwKLMk2njSv",
7     "isin": "US19260Q1076",
8     "isin_title": "COINBASE GLOBAL INC.",
9     "quantity": 1,
10     "buy_quantity": 1,
11     "sell_quantity": 0,
12     "buy_price_avg": 2965000,
13     "buy_price_min": 2965000,
14     "buy_price_max": 2965000,
15     "buy_price_avg_historical": 2965000,
16     "sell_price_min": null,
17     "sell_price_max": null,
18     "sell_price_avg_historical": null,
19     "orders_total": 1,
20     "sell_orders_total": 0,
21     "buy_orders_total": 1
22    },
23    {
24      "space_id": "sp_pyPFYssNNJyV4m8rxtK7LnfGwKLMk2njSv",
25      ...
26    }
27  ]

The results part of the response is an array of objects. Each object represents a different portfolio item and you can retrieve a lot of interesting information from it. For instance, the space_id tells you which Space the portfolio item belongs to, 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 portfolio, how many shares you bought, how many you sold and at what price.

Working with query parameters

While a general overview of all portfolio items is nice, you might want to narrow your search. That’s what query parameters are for. In the /portfolio endpoint, you can query for the space_id and the isin, which allows you to either only see portfolio items from a specific Space or only portfolio items for a specific instrument. Or both. 

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

1import requests
2request = requests.get("", 
3                       headers={"Authorization": "Bearer YOUR-API-KEY"})

This will result in only Tesla portfolio items being displayed. If you have multiple Spaces with which you traded Tesla stock, you will still retrieve multiple objects, e.g. Space 1 with 17 Tesla shares, Space 2 with 9 Tesla shares, and Space 3 with 2 Tesla shares. However, if you only hold the respective portfolio item in one of your Spaces, the API will only return a results array of length one. 

Additionally, you can also enforce to only get one result by also specifying a space_id next to the isin. Simply add &space_id={YOUR_SPACE_ID} to the request URL displayed above. With that request, you will get the portfolio information of a specific instrument in a specific Space. 

And now: what to do with it?

The possibilities from here on are (almost) endless. You could build your own dashboard to display your portfolio 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 portfolio. 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

Exploring the instruments endpoint

blog photo

The /instruments endpoint can be used to search the 8250+ stocks and ETFs we currently offer on You can customise your search with as much detail as you’d like by specifying the exchange, currency, type and other characteristics. Continue reading if you’d like to learn more.

Manage your trading portfolio with the brokerage API

blog photo

Placing your first order with the Trading API

blog photo

With the API, placing an order is only one API call. But kind of information do you need to include in your request? In this blog post we walk you through how to successfully place an order and how to activate it with the trading API, such that it is placed and filled on the exchange of your choice. Keep reading to learn more.

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
For Developers
© 2021Privacy PolicyImprint
All systems normal