internal

package
v0.0.0-...-4626f08 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInsufficientBoughtVolume = fmt.Errorf("insufficient bought volume")

Functions

func BuildReport

func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter) error

Types

type AggregatorWriter

type AggregatorWriter struct {
	// contains filtered or unexported fields
}

AggregatorWriter tracks ReportItem totals.

func NewAggregatorWriter

func NewAggregatorWriter() *AggregatorWriter

func (*AggregatorWriter) Iter

func (aw *AggregatorWriter) Iter() iter.Seq[ReportItem]

func (*AggregatorWriter) TotalEarned

func (aw *AggregatorWriter) TotalEarned() decimal.Decimal

func (*AggregatorWriter) TotalFees

func (aw *AggregatorWriter) TotalFees() decimal.Decimal

func (*AggregatorWriter) TotalSpent

func (aw *AggregatorWriter) TotalSpent() decimal.Decimal

func (*AggregatorWriter) TotalTaxes

func (aw *AggregatorWriter) TotalTaxes() decimal.Decimal

func (*AggregatorWriter) Write

func (aw *AggregatorWriter) Write(_ context.Context, ri ReportItem) error

type Filler

type Filler struct {
	Record
	// contains filtered or unexported fields
}

func NewFiller

func NewFiller(r Record) *Filler

func (*Filler) Fill

func (f *Filler) Fill(quantity decimal.Decimal) (decimal.Decimal, bool)

Fill accrues some quantity. Returns how mutch was accrued in the 1st return value and whether it was filled or not on the 2nd return value.

func (*Filler) IsFilled

func (f *Filler) IsFilled() bool

IsFilled returns true if the fill is equal to the record quantity.

type FillerQueue

type FillerQueue struct {
	// contains filtered or unexported fields
}

func (*FillerQueue) Len

func (fq *FillerQueue) Len() int

Len returns how many elements are currently on the queue

func (*FillerQueue) Peek

func (fq *FillerQueue) Peek() (*Filler, bool)

Peek returns the front Filler of the queue in the 1st return value. If the list is empty returns false on the 2nd return value, true otherwise.

func (*FillerQueue) Pop

func (fq *FillerQueue) Pop() (*Filler, bool)

Pop removes and returns the first Filler of the queue in the 1st return value. If the list is empty returns false on the 2nd return value, true otherwise.

func (*FillerQueue) Push

func (fq *FillerQueue) Push(f *Filler)

Push inserts the Filler at the back of the queue.

type Nature

type Nature string
const (
	// NatureUnknown is the zero value of Nature type
	NatureUnknown Nature = ""

	// NatureG01 describes selling of stocks per table VII: Alienação onerosa de ações/partes sociais
	NatureG01 Nature = "G01"

	// NatureG20 describes selling units in investment funds (including ETFs) as per table VII:
	// Resgates ou alienação de unidades de participação ou liquidação de fundos de investimento
	NatureG20 Nature = "G20"
)

func (Nature) String

func (n Nature) String() string

type OpenFIGI

type OpenFIGI struct {
	// contains filtered or unexported fields
}

OpenFIGI is a small adapter for the openfigi.com api

func NewOpenFIGI

func NewOpenFIGI(c *http.Client) *OpenFIGI

func (*OpenFIGI) SecurityTypeByISIN

func (of *OpenFIGI) SecurityTypeByISIN(ctx context.Context, isin string) (string, error)

type Record

type Record interface {
	Symbol() string
	Nature() Nature
	BrokerCountry() int64
	AssetCountry() int64
	Side() Side
	Price() decimal.Decimal
	Quantity() decimal.Decimal
	Timestamp() time.Time
	Fees() decimal.Decimal
	Taxes() decimal.Decimal
}

type RecordReader

type RecordReader interface {
	// ReadRecord should return Records until an error is found.
	ReadRecord(context.Context) (Record, error)
}

type ReportItem

type ReportItem struct {
	Symbol        string
	Nature        Nature
	BrokerCountry int64
	AssetCountry  int64
	BuyValue      decimal.Decimal
	BuyTimestamp  time.Time
	SellValue     decimal.Decimal
	SellTimestamp time.Time
	Fees          decimal.Decimal
	Taxes         decimal.Decimal
}

func (ReportItem) RealisedPnL

func (ri ReportItem) RealisedPnL() decimal.Decimal

type ReportWriter

type ReportWriter interface {
	// ReportWriter writes report items
	Write(context.Context, ReportItem) error
}

type Side

type Side uint
const (
	SideUnknown Side = iota
	SideBuy
	SideSell
)

func (Side) IsBuy

func (d Side) IsBuy() bool

IsBuy returns true if the s == SideBuy

func (Side) IsSell

func (d Side) IsSell() bool

IsSell returns true if the s == SideSell

func (Side) String

func (d Side) String() string

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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