GetPortfolioTrades
GET/portfolios/:portfolioId/trades
Load a list of completed trades in a portfolio. A completed trade corresponds to one closing of a position.
Technically each closing of a position corresponds to one execution of an order with intent=close (usually those
are sell orders, but in the case of short selling, opening a position is a sell order with intent=open).
The analysis follows the FIFO (First In, First Out) principle to accurately summarize trades. Each time a position is closed (note that partial executions are possible. In this case, each individual execution is regarded as a transaction), the system identifies the earliest corresponding "open position execution" that contributed to that closing. The result includes a single entry for each closing transaction, detailing key metrics such as profit/loss and holding period, based on the matched opening transactions.
This could be a real world example:
- 2020-01-01: buy 5 stock1 for 100 USD each
- 2021-06-01: buy 3 stock1 for 200 USD each
- 2021-06-06: sell 6 stock1 for 300 USD each
In this case, the result would be one completed trade (corresponding to the last sell) with a profit of (300*6)-(100*5+1*200)=1800-700=1100 USD.
There is an open position remaining (2 units of stock1, which correspond to the second buy transaction).
When we add this sell:
- 2021-06-07: sell 2 stock1 for 400 USD each
It would add a second complete trade with a profit of (400*2)-(200*2)=800-400=400 USD.
For some brokers, the order history may be incomplete (e.g. only reveals the latest 90 days), so that we do not know if there could be older transactions.
Thus, our implementation might detect (given the current set of open positions together with the list of order executions) that we cannot figure out
the corresponding opening transactions for a closing transaction. Affected trades will be ignored for this analysis and might appear as warning items in the
/warnings endpoint. Frontends should show those warnings so that users can understand why the analysis is incomplete.
Request
Responses
- 200
- 401
- 404
- 422
- 429
- 503
Ok
Not logged in
Portfolio not found
Validation error
Rate-limit exceeded
Maintenance active