@accounter/server
Version:
Accounter GraphQL server
34 lines (33 loc) • 1.54 kB
TypeScript
import type { TimelessDateString } from '../../../shared/types/index.js';
export type PositionExecution = {
trade_date: Date;
trade_type: string;
nv: string | null;
net_value_trade_currency: string | null;
trade_currency: string | null;
};
export type SecurityPositionProto = {
/** Units held, derived from the ingested executions alone. */
quantity: number;
/** Weighted average price paid per unit bought, in the trade currency. Null with no buys. */
averageCost: number | null;
totalBought: number;
totalSold: number;
/** The currency the amounts above are in — the trade currency the executions report. */
currency: string | null;
/**
* The earliest ingested execution. The position is only as complete as history from this
* day on, which is what the UI has to say out loud: holdings are not ingested, so anything
* bought before the first scraped execution is invisible here.
*/
historyStartDate: TimelessDateString | null;
lastExecutionDate: TimelessDateString | null;
};
/**
* The holding a security's ingested executions add up to, plus what was paid for it.
*
* Derived, not reported: the bank's own balances are not ingested. Corporate actions that
* change the unit count without an execution row (a split, say) are therefore invisible, and a
* history that starts mid-life starts from zero — hence `historyStartDate`.
*/
export declare function calculateSecurityPosition(executions: readonly PositionExecution[]): SecurityPositionProto;