flexstmt

package
v2.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package flexstmt parses IBKR Flex query statements into typed records for the post-trade reconciliation engine (internal-docs/design/post-trade-truth.md). Pure parsing: no I/O, no policy, no matching. Statement content is untrusted broker data — everything is extracted through typed attributes, an unknown cash-transaction type lands in Uncategorized rather than being dropped, and nothing in a statement can carry an instruction anywhere.

Index

Constants

View Source
const (
	// CategoryFlow is an external capital flow (deposit/withdrawal) —
	// the lines the declared ledger must account for.
	CategoryFlow = "flow"
	// CategoryClassified is a known non-flow line (dividend, interest,
	// fee, tax, …): legitimate P&L, excluded from flow matching by type.
	CategoryClassified = "classified"
	// CategoryUncategorized is a line type this parser does not know.
	// Always surfaced as an exception downstream, never silently dropped.
	CategoryUncategorized = "uncategorized"
)

Cash-transaction categories after classification.

Variables

This section is empty.

Functions

This section is empty.

Types

type CashLine

type CashLine struct {
	// ID is the broker transactionID when present, else a stable hash of
	// the line's identifying attributes. Restatements supersede by ID.
	ID       string
	Category string // flow | classified | uncategorized
	Type     string // raw Flex type attribute
	Currency string
	// Amount is nil when the statement omitted the amount attribute. An
	// explicit zero remains a present value.
	Amount *float64
	// AmountBase is Amount converted at the statement's fxRateToBase;
	// nil when the statement carried no amount or no usable rate (never
	// fabricated).
	AmountBase  *float64
	ValueDate   time.Time // settleDate when present, else dateTime's day
	Description string
}

CashLine is one classified cash-transaction line.

type EquityRow

type EquityRow struct {
	ReportDate time.Time
	TotalBase  float64
}

EquityRow is one day of the base-currency equity series.

type Statement

type Statement struct {
	AccountID     string
	FromDate      time.Time
	ToDate        time.Time
	WhenGenerated time.Time
	Cash          []CashLine
	Transfers     []Transfer
	Equity        []EquityRow
}

Statement is one parsed Flex statement.

func Parse

func Parse(data []byte) ([]Statement, error)

Parse decodes one Flex query response document. It returns an error for anything that is not a well-formed statement — including the Flex service's own error/status envelope — so a failed fetch can never be mistaken for an empty week.

type Transfer

type Transfer struct {
	ID        string
	Direction string // IN | OUT
	Date      time.Time
	// CashTransfer is nil when the statement omitted the cashTransfer
	// attribute. An explicit zero remains a present value.
	CashTransfer *float64
	AmountBase   *float64
	Description  string
}

Transfer is one position/cash transfer (ACATS, internal). Treated as a flow candidate downstream; a transfer with no computable base amount is an uncategorized exception, not a guess.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL