Skip to main content

Quick Start

This guide gets you started with Gorila CORE API with a simple working example.

Basic setup

import requests

# Gorila CORE's URL
base_url = "https://core.gorila.com.br"

# Prepare a header to authenticate using your API key
authorization = {"Authorization": "c1deeef8-4812-4bd3-903e-8adeaff3903d"}

Create a Portfolio

response = requests.post(
f"{base_url}/portfolios",
json={"name": "ALVARO DIAS PEREIRA", "autoRnC": False},
headers=authorization,
)

response.json()
'''
{
'id': 'e3021f03-0af7-4571-be92-ba97b537c89d',
'name': 'ALVARO DIAS PEREIRA',
'autoRnC': False
}
'''

Input some Transactions

portfolio_id = "e3021f03-0af7-4571-be92-ba97b537c89d"

transactions = [
{
"type": "REGULAR",
"transactDate": "2022-10-03",
"quantity": 200,
"brokerId": "18945670000146",
"security": {
"isin": "BRPETRACNPR6", # PETR4
},
"side": "BUY",
"price": 24.28,
"fees": {
"brokerageFee": 8.00,
}
},
{
"type": "REGULAR",
"transactDate": "2022-10-18",
"brokerId": "27652684000162",
"security": {
"isin": "BRSTNCNTB4O9", # NTN-B
},
"side": "BUY",
"price": 4027.058131,
"quantity": 30.0,
},
{
"type": "REGULAR",
"transactDate": "2022-10-27",
"quantity": 105,
"brokerId": "18945670000146",
"security": {
"isin": "BRPETRACNPR6", # PETR4
},
"side": "SELL",
"price": 27.15,
"fees": {
"brokerageFee": 0.15,
}
},
]

for txn in transactions:
requests.post(
f"{base_url}/portfolios/{portfolio_id}/transactions",
json=txn,
headers=authorization,
)

Now that we have some transactions added to a portfolio, we can start to fetch useful data about it.

For the next API calls, we are going to look at certain period of one month: from 2022-10-01 to 2022-10-31.

Get portfolio's Net Asset Value (NAV)

portfolio_id = "e3021f03-0af7-4571-be92-ba97b537c89d"

params = {
"startDate": "2022-10-01",
"endDate": "2022-10-31",
"frequency": "DAILY",
}

response = requests.get(
f"{base_url}/portfolios/{portfolio_id}/nav",
params=params,
headers=authorization,
)

response.json()
"""
{
'timeseries': [
{ 'referenceDate': '2022-10-01', 'nav': 0, 'currency': 'BRL' },
{ 'referenceDate': '2022-10-02', 'nav': 0, 'currency': 'BRL' },
{ 'referenceDate': '2022-10-03', 'nav': 1572, 'currency': 'BRL' },
{ 'referenceDate': '2022-10-04', 'nav': 1410, 'currency': 'BRL' },
...
]
}
"""

Get portfolio's Profit & Losses (P&L)

portfolio_id = "e3021f03-0af7-4571-be92-ba97b537c89d"

params = {
"startDate": "2022-10-01",
"endDate": "2022-10-31",
"frequency": "DAILY",
"seriesType": "ACCUMULATED",
}

response = requests.get(
f"{base_url}/portfolios/{portfolio_id}/pnl",
params=params,
headers=authorization,
)

response.json()
"""
{
'timeseries': [
{ 'referenceDate': '2022-10-03', 'pnl': 1580, 'currency': 'BRL' },
{ 'referenceDate': '2022-10-04', 'pnl': 1418, 'currency': 'BRL' },
{ 'referenceDate': '2022-10-05', 'pnl': 1654, 'currency': 'BRL' },
{ 'referenceDate': '2022-10-06', 'pnl': 1876, 'currency': 'BRL' },
...
]
}
"""

Get portfolio's Time-Weighted Rate of Return (TWR)

portfolio_id = "e3021f03-0af7-4571-be92-ba97b537c89d"

params = {
"startDate": "2022-10-01",
"endDate": "2022-10-31",
"frequency": "DAILY",
"seriesType": "PER_PERIOD",
}

response = requests.get(
f"{base_url}/portfolios/{portfolio_id}/twr",
params=params,
headers=authorization,
)

response.json()
"""
{
'timeseries': [
{ 'referenceDate': '2022-10-03', 'twr': 0 },
{ 'referenceDate': '2022-10-04', 'twr': -0.10305343509999998 },
{ 'referenceDate': '2022-10-05', 'twr': 0.1673758864999999 },
{ 'referenceDate': '2022-10-06', 'twr': 0.13487241800000005 },
...
]
}
"""

Get portfolio's Internal Rate of Return (IRR)

portfolio_id = "e3021f03-0af7-4571-be92-ba97b537c89d"

params = {
"startDate": "2022-10-01",
"endDate": "2022-10-31",
}

response = requests.get(
f"{base_url}/portfolios/{portfolio_id}/positions/irr",
params=params,
headers=authorization,
)

response.json()
"""
{
"next": None,
"records": [
{
"broker": {
"id": "18945670000146",
"name": "INTER DTVM"
},
"irr": 0.12034529944391072,
"referenceDate": "2022-10-31",
"security": {
"assetClass": "STOCKS",
"id": 122720,
"isin": "BRPETRACNPR6",
"name": "PETR4",
"type": "STOCK_LOCAL",
"validityDate": "2023-09-01T00:00:00Z"
}
},
{
"broker": {
"id": "18945670000146",
"name": "INTER DTVM"
},
"irr": 0,
"referenceDate": "2022-10-31",
"security": {
"assetClass": "CASH",
"id": 177223,
"name": "BRL",
"type": "CASH",
"validityDate": "1994-07-01T00:00:00Z"
}
},
{
"broker": {
"id": "27652684000162",
"name": "GENIAL INVESTIMENTOS"
},
"irr": 0,
"referenceDate": "2022-10-31",
"security": {
"assetClass": "CASH",
"id": 177223,
"name": "BRL",
"type": "CASH",
"validityDate": "1994-07-01T00:00:00Z"
}
},
{
"broker": {
"id": "27652684000162",
"name": "GENIAL INVESTIMENTOS"
},
"irr": 0.005959030443407324,
"referenceDate": "2022-10-31",
"security": {
"assetClass": "FIXED_INCOME",
"dealType": "spread",
"id": 118697,
"index": "ipca",
"isin": "BRSTNCNTB4O9",
"maturityDate": "2023-05-15T00:00:00Z",
"name": "NTNB - 15/05/2023",
"type": "TREASURY_LOCAL_NTNB",
"validityDate": "2000-07-15T00:00:00Z",
"yield": 0.06
}
}
]
}
"""