UNPKG

@accounter/server

Version:
70 lines (69 loc) 4.16 kB
import DataLoader from 'dataloader'; import { TenantAwareDBClient } from '../../app-providers/tenant-db-client.js'; import { FinancialAccountsProvider } from '../../financial-accounts/providers/financial-accounts.provider.js'; import { FinancialBankAccountsProvider } from '../../financial-accounts/providers/financial-bank-accounts.provider.js'; import { TransactionsProvider } from '../../transactions/providers/transactions.provider.js'; import { type MatchableTransaction } from '../helpers/match-security-executions.helper.js'; import type { ChargeSecurityProto, SecurityExecutionRow } from '../types.js'; import { SecurityBusinessesProvider } from './security-businesses.provider.js'; /** What the reverse match needs off a transaction, charge included so a row can link out. */ type MatchedTransaction = MatchableTransaction & { charge_id: string; }; export declare class ForeignSecuritiesProvider { private db; private transactionsProvider; private financialAccountsProvider; private financialBankAccountsProvider; private securityBusinessesProvider; constructor(db: TenantAwareDBClient, transactionsProvider: TransactionsProvider, financialAccountsProvider: FinancialAccountsProvider, financialBankAccountsProvider: FinancialBankAccountsProvider, securityBusinessesProvider: SecurityBusinessesProvider); private batchSecuritiesByKeys; securityByKeyLoader: DataLoader<string, import("../types.js").IGetSecuritiesByKeysResult | null, string>; /** * The Poalim identity (bank/branch/account) of each account the given transactions touch. * `financial_accounts.account_number` is text while the poalim_* tables store it as an * integer, so non-numeric account numbers (and non-bank accounts, which have no * financial_bank_accounts row) simply drop out — they can never match an execution. */ private getAccountTuples; /** * Ingested portfolio executions matched to the charge's transactions, grouped by security * key. Returns an empty map when the charge touches no resolvable Poalim account, so a * charge whose accounts predate the bank-account backfill degrades to "no activity" rather * than erroring. */ private getMatchedExecutions; /** * The whole ingested life of one security business: every execution of every Poalim key it * is known by, each carrying the cash movement (and so the charge) behind it. * * The candidate transactions are the security business's own — which is what the counterparty * now is for a resolved trade — so this reads the same pairing the charge view shows, from * the other end. */ getSecurityBusinessHistory(businessId: string, ownerId: string): Promise<{ executions: import("../types.js").IGetSecurityExecutionsByKeysResult[]; transactionByExecutionId: Map<string, MatchedTransaction>; }>; /** * Every ingested execution of every security business the tenant has, grouped by the business * it belongs to. Each business gets an entry, so "nothing ingested" is distinguishable from * "not a security". * * One query for the whole portfolio: `getSecurityExecutionsByKeys` already filters on * `security = ANY(...)` and returns the key on every row, so the union of every business's * Poalim keys can be asked for at once and split back up in memory. * * Unlike `getSecurityBusinessHistory` this never looks at transactions or accounts — those * exist only to pair an execution with the cash movement behind it, which a position does not * need, and they cost a transactions query plus an account lookup per security. */ getExecutionsBySecurityBusiness(): Promise<Map<string, SecurityExecutionRow[]>>; /** * The securities a charge's transactions reference, keyed off the security key each * description carries. Keys with no ingested row are still returned, with a null * `details`, so a stale or missing scrape is visible instead of silently dropping data. */ getChargeSecurities(chargeId: string): Promise<ChargeSecurityProto[]>; } export {};