DEV Community

Cover image for How to access your lemon.markets Trading API Account with one API call
Joanne for lemon.markets

Posted on

How to access your lemon.markets Trading API Account with one API call

We at lemon.markets provide the infrastructure so everyone can build their own brokerage experience at the stock market. In this blog post, we show you how to easily access your trading account information with one simple API call. Additionally, we dive a little deeper into our /account endpoint. Let us begin!

Signing up

The first step to accessing your account is to make sure that you actually have one. So, sign up on our dashboard and verify your account through the email that we send you after registration. You can then sign into the dashboard, where we already provide you with your first API Key.

Finding your way around our API

Using that API Key, you can go ahead and start testing our API. You can find everything you need to know in our documentation. We created several endpoints concerned with everything related to your account. Using these endpoints, you can find information about your name (in case you forgot), your current balance, how much cash you have left to invest, the IBAN of your brokerage account and many many more things.

To retrieve information about your account, place a GET request against the following request URL:

https://paper-trading.lemon.markets/v1/account/
Enter fullscreen mode Exit fullscreen mode

You can do so by grabbing the API Key from your dashboard and placing it into the following Python code snippet (find a JavaScript example in our documentation).

import requests

request = requests.get("https://paper-trading.lemon.markets/v1/account/", 
                       headers={"Authorization": "Bearer YOUR-API-KEY"})
print(request.json())
Enter fullscreen mode Exit fullscreen mode

Placing this request will result in a response similar to this one:

{
  "time": "2021-11-22T15:37:56.520+00:00",
  "status": "ok",
  "results": {
    "created_at": "2021-10-12T10:29:49.769+00:00",
    "account_id": "acc_pyNQNll99hQbXMCS0dRzHyKQCRKYHpy3zg",
    "firstname": "Michael",
    "lastname": "Burry",
    "email": "m_burry@tradingapi.com",
    "phone": "+491637876521",
    "address": "Ritterstraße 2A 10969 Berlin",
    "billing_address": "Ritterstraße 2A 10969 Berlin",
    "billing_email": "m_burry@tradingapi.com",
    "billing_name": "Michael Burry",
    "billing_vat": "DE999999999",
    "mode": "money",
    "deposit_id": "K2057263187",
    "client_id": "2057263",
    "account_number": "2057263187",
    "iban_brokerage": "DE12345678902057263",
    "iban_origin": "DE123456789012345",
    "bank_name_origin": "Test Bank",
    "balance": 100000000,
    "cash_to_invest": 80000000,
    "cash_to_withdraw": 20000000,
    "trading_plan": "basic",
    "data_plan": "basic",
    "tax_allowance": 8010000,
    "tax_allowance_start": "2021-01-01",
    "tax_allowance_end": "2021-01-01"
  }
}
Enter fullscreen mode Exit fullscreen mode

As you can see, you get a lot of information on everything related to your account, like when it was created, what your current balance is, on which trading & data plan you are on and the IBAN of your brokerage account. Make sure to check out our documentation for in-depth information on all endpoint response parameters.

Withdrawing money

As you can see in the endpoint response above, you also have a response element called cash_to_withdraw. This is your current balance minus the current sum of your buy orders. Based on that number, you can very easily withdraw money into your reference account via:

https://paper-trading.lemon.markets/v1/account/withdrawals/
Enter fullscreen mode Exit fullscreen mode

(Note that we are currently still working on releasing the real money feature, so it might take some more time until you can use this endpoint 🙂)
Use the following code snippet (with your own API Key, of course) to withdraw money into your reference account.

import requests
import json

request = requests.post("https://paper-trading.lemon.markets/v1/account/withdrawals/",
          data=json.dumps({
               amount: 5000000,
               pin: 1234
            }), headers={"Authorization": "Bearer YOUR-API-KEY"})
print(request.json())
Enter fullscreen mode Exit fullscreen mode

Define the amount you want to withdraw in your request body, along with your individual 4-digit PIN that you set during your onboarding process. After a successful API request, the specified amount is automatically withdrawn.

Retrieving your Bank statements

Obviously, as a user you are interested in staying up to date regarding all activity that is happening on your account. That is what the /bankstatements endpoint is there for. The endpoint returns a list of objects containing all activities from your last “active day” (in the paper money environment) and all activities from the last working day (in the real money environment), where, by default, an end of day balance is created for you. You can access your bank statements using the following request URL:

import requests

request = requests.get("https://paper-trading.lemon.markets/v1/account/bankstatements/?type=order_buy", 
                       headers={"Authorization": "Bearer YOUR-API-KEY"})
print(request.json())
Enter fullscreen mode Exit fullscreen mode

This will return a response similar to the following one:

"time": "2021-12-20T12:48:06.199+00:00",
"status": "ok",
"mode": "paper",
"results": [
        {
            "id": "bst_pyHLSwwFFd6r9fJsNbFhxrB3sl43xCP1GK",
            "account_id": "acc_pyNQNll11hQbXMCS0dRzHyNKLZTYHpy3zg",
            "type": "eod_balance",
            "date": "2021-12-16",
            "amount": 987033450,
            "isin": null,
            "isin_title": null
        },
        {
            "id": "bst_pyQWCwwFFrBm9NhMYJ1yYDnhnMtMs64DNT",
            "account_id": "acc_pyNQNll11nQbXMCS0dRzHyKQCRKYHpy3zg",
            "type": "order_buy",
            "date": "2021-12-16",
            "amount": 8829000,
            "isin": "US88160R1014",
            "isin_title": "TESLA INC."
        }
    ],
"previous": null,
"next": null,
"total": 2,
"page": 1,
"pages": 1
}
Enter fullscreen mode Exit fullscreen mode

As you can see, the last thing I did was I placed a buy order in the paper environment and an end of day balance was created for me.

Seeing some documents

Lastly, you have the chance to very easily access all important documents related to your account via the following URL:

https://paper-trading.lemon.markets/v1/account/documents/
Enter fullscreen mode Exit fullscreen mode

Use the following code snippet, extended by your own API Key, to retrieve a list of documents:

import requests

request = requests.get("https://paper-trading.lemon.markets/v1/account/documents/", 
                       headers={"Authorization": "Bearer YOUR-API-KEY"})
print(request.json())
Enter fullscreen mode Exit fullscreen mode

This will provide you with a list similar to this one:

{
  "time": "2021-11-22T15:41:04.028+00:00"
  "status": "ok",
  "results": [
    {
      "id": "doc_pyNjNcc77ht3T3lH8dJa5fD8jhj2JHJ1xX",
      "name": "account_opening.pdf",
      "created_at": "2021-10-19T14:58:52.813Z",
      "category": "kyc",
      "public_url": "http://testpublicurl.de/",
      "link": "'https://trading.lemon.markets/v1/account/documents/doc_pyNjNcc77ht3T3lH8dJa5fD8jhj2JHJ1xX",
      "viewed_first_at": "2021-10-19T14:58:52.813Z",
      "viewed_last_at": "2021-10-19T14:58:52.813Z"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

In there, you find all documents, along with a download link. By clicking the link, you are redirected to a .pdf version of the file.


Alright, that was all there is to say about the lemon.markets account endpoints and what you can do with them. Make sure to sign up to our trading API to build your own brokerage experience at the stock market. Also, join our Slack community, where we discuss all things trading and lemon.markets with more than 400 developers.

Looking forward to seeing you there 🍋 🚀

Discussion (0)