Portfolio Trades

Retrieves trade instructions for a portfolio on latest rebalance date.


Endpoint

GET/data/v1/portfolio_trades/:id

Parameters

api_key string required
Your authentication key needed to make requests.


value int required
Portfolio value in USD. E.g. 1000000 for USD 1 million.


allow_fractional boolean default: false
Whether to allow for fractional shares (typically by sepcifying exact amount to be invested if broker allows).


rebalance_period string default: last_rebalance_date
The date on which holdings are based. Default is last_rebalance_date which return trades for the actual rebalance date of the portfolio. Optionally if today is inputted it will show trades if the portfolios were rebalanced on the most recent trading date.


format string default: json
Defines return format of response. Options are json or csv. Default is json.

Example Request

cURL
curl -X GET "https://sensaai.com/data/v1/portfolio_trades/337?value=1000000&api_key=API_KEY"
Python
import requests

url = "https://sensaai.com/data/v1/portfolio_trades/337/"
params = {
 "api_key": "API_KEY",  # Replace 'API_KEY' with your actual API key
 "value": 1000000
}

response = requests.get(url, params=params)

if response.status_code == 200:
 data = response.json()
 print(data)
else:
 print(f"Request failed with status code {response.status_code}")
JavaScript
const https = require('https');

const url = "https://sensaai.com/data/v1/portfolio_trades/337/";
const params = {
api_key: "API_KEY", // Replace 'API_KEY' with your actual API key
"value": 1000000
};

const requestUrl = new URL(url);
requestUrl.search = new URLSearchParams(params);

https.get(requestUrl, (response) => {
let data = '';

response.on('data', (chunk) => {
  data += chunk;
});

response.on('end', () => {
  if (response.statusCode === 200) {
    console.log(data);
  } else {
    console.error(`Request failed with status code ${response.statusCode}`);
  }
});
});

Response

Returns a list of portfolio trades if a valid portfolio ID and value were provided. Returns an error otherwise.

[
  {
    "date": "2023-10-02",
    "id": 176,
    "ticker": "AME",
    "name": "AMETEK INC/",
    "price": 147.42,
    "quantity": 136.0,
    "value": 20049.12,
    "pct": 0.02004912,
    "order_type": "Buy"
  },
  {
    "date": "2023-10-02",
    "id": 67,
    "ticker": "ADM",
    "name": "ARCHER DANIELS MIDLAND CO",
    "price": 74.2,
    "quantity": 270.0,
    "value": 20034.0,
    "pct": 0.020034,
    "order_type": "Buy"
  },
  {
    "date": "2023-10-02",
    "id": 71,
    "ticker": "ADP",
    "name": "AUTOMATIC DATA PROCESSING INC",
    "price": 239.37,
    "quantity": 84.0,
    "value": 20107.08,
    "pct": 0.020107080000000003,
    "order_type": "Buy"
  },
    ...more trades
]