transaction

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypePurchase       = "Purchase"
	TypeSale           = "Sale"
	TypeDividendPayout = "Dividends"
	TypeRoundUp        = "Round up"
	TypeSaveback       = "Saveback"

	InstrumentTypeStocks         = "Stocks"
	InstrumentTypeETF            = "ETF"
	InstrumentTypeCryptocurrency = "Cryptocurrency"
	InstrumentTypeLending        = "Lending"
	InstrumentTypeOther          = "Other"
)

Variables

View Source
var ErrNoMatch = errors.New("value did not match the pattern")
View Source
var ErrUnsupportedResponse = errors.New("unsupported response")

Functions

func ExtractInstrumentNameFromIcon

func ExtractInstrumentNameFromIcon(src string) (string, error)

func ParseFloatWithComma

func ParseFloatWithComma(src string, isNegative bool) (float64, error)

func ParseFloatWithPeriod

func ParseFloatWithPeriod(src string) (float64, error)

Types

type Builder added in v0.4.0

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

func NewBuilder added in v0.4.0

func NewBuilder(resolver TypeResolver, logger *log.Logger) Builder

func (Builder) Build added in v0.4.0

func (b Builder) Build(transactionType string, response details.Response) (Model, error)

func (Builder) BuildDocuments added in v0.4.0

func (b Builder) BuildDocuments(response details.Response) ([]Document, error)

func (Builder) FromResponse added in v0.4.0

func (b Builder) FromResponse(response details.Response) (Model, error)

func (Builder) GetHeaderData added in v0.4.0

func (b Builder) GetHeaderData(response details.Response) (string, string, time.Time, error)

Returns Status, ISIN, Timestamp and error.

func (Builder) GetOverviewData added in v0.4.0

func (b Builder) GetOverviewData(response details.Response) (string, error)

Returns Instrument name and error.

func (Builder) GetPerformanceData added in v0.4.0

func (b Builder) GetPerformanceData(response details.Response) (float64, float64, error)

Returns Yield, Profit and error.

func (Builder) GetTransactionData added in v0.4.0

func (b Builder) GetTransactionData(response details.Response) (float64, float64, float64, float64, error)

Returns Shares, Rate, Commission, Total and error.

type BuilderInterface added in v0.4.0

type BuilderInterface interface {
	FromResponse(response details.Response) (Model, error)
}

type CSVEntryFactory

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

func NewCSVEntryFactory

func NewCSVEntryFactory(logger *log.Logger) CSVEntryFactory

func (CSVEntryFactory) Make

func (f CSVEntryFactory) Make(transaction Model) (filesystem.CSVEntry, error)

type Document

type Document struct {
	ID    string
	URL   string
	Date  string
	Title string
}

func CreateDocumentsFromResponse

func CreateDocumentsFromResponse(resp details.Response) ([]Document, error)

func NewDocument

func NewDocument(id, url, date, title string) Document

type Instrument added in v0.4.0

type Instrument struct {
	ISIN string `gorm:"primaryKey"`
	Name string
}

func NewInstrument added in v0.4.0

func NewInstrument(isin, name string) Instrument

func (Instrument) Type added in v0.4.0

func (i Instrument) Type() string

type InstrumentRepositoryInterface added in v0.4.0

type InstrumentRepositoryInterface interface {
	database.RepositoryInterface[*Instrument]
}

type Model added in v0.4.0

type Model struct {
	UUID string `gorm:"primaryKey"`

	InstrumentISIN string
	Instrument     Instrument
	Documents      []Document `gorm:"-"`

	Type       string    `gorm:"index"`
	Timestamp  time.Time `gorm:"index"`
	Status     string
	Yield      float64
	Profit     float64
	Shares     float64
	Rate       float64
	Commission float64
	Total      float64
	CreatedAt  time.Time `gorm:"index"`
	UpdatedAt  time.Time `gorm:"index"`
}

func NewTransaction added in v0.4.0

func NewTransaction(
	uuid, transactionType, status string,
	yield, profit, shares, rate, commission, total float64,
	timestamp time.Time,
	instrument Instrument,
	documents []Document,
) Model

func (Model) TableName added in v0.4.0

func (Model) TableName() string

type Processor

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

func NewProcessor

func NewProcessor(
	builder BuilderInterface,
	transactionRepo RepositoryInterface,
	factory CSVEntryFactory,
	csvReader filesystem.CSVReader,
	csvWriter filesystem.CSVWriter,
	logger *log.Logger,
) Processor

func (Processor) Process

func (p Processor) Process(response details.Response) error

type RepositoryInterface added in v0.4.0

type RepositoryInterface interface {
	database.RepositoryInterface[*Model]
}

type Type

type Type int
const (
	TypeUnsupported Type = iota
	TypeSaleTransaction
	TypePurchaseTransaction
	TypeDividendPayoutTransaction
	TypeRoundUpTransaction
	TypeSavebackTransaction
	TypeCardPaymentTransaction
)

type TypeResolver

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

func NewTypeResolver

func NewTypeResolver(logger *log.Logger) TypeResolver

func (TypeResolver) Resolve

func (r TypeResolver) Resolve(response details.Response) (Type, error)

Jump to

Keyboard shortcuts

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