models

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 14, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ERR_MESSAGES = map[Errno]string{
		MSG_STATUS_SUCCESS:   "operation successful",
		ERR_INSERT_WALLET:    "error saving the wallet",
		ERR_NEW_WALLET:       "invalid name",
		ERR_NOT_FOUND:        "element not found",
		ERR_DB_NOT_FOUND:     "database not avaliable in context",
		ERR_WALLET_NOT_FOUND: "wallet not found",
		ERR_NOT_A_WALLET:     "not a wallet",
		ERR_UPDATE_WALLET:    "unable to update the wallet",
		ERR_INSI_NOT_FOUND:   "inis not found",
	}
)

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	Type string          `json:"type"`
	Msg  json.RawMessage `json:"msg"`
}

type Errno

type Errno int
const (
	MSG_STATUS_SUCCESS Errno = 1

	ERR_INSERT_WALLET Errno = 101
	ERR_NEW_WALLET    Errno = 102

	ERR_NOT_FOUND        Errno = 404
	ERR_DB_NOT_FOUND     Errno = 405
	ERR_WALLET_NOT_FOUND Errno = 406
	ERR_NOT_A_WALLET     Errno = 407
	ERR_UPDATE_WALLET    Errno = 408
	ERR_INSI_NOT_FOUND   Errno = 409
)

type ErrorMessage

type ErrorMessage struct {
	Errno Errno
	Msg   string
}

func NewError

func NewError(code Errno, msg string) ErrorMessage

type FundData

type FundData struct {
	INSI        string     `json:"insi,omitempty"`
	Name        string     `json:"name,omitempty"`
	Nav         float32    `json:"nav,omitempty"`
	Date        time.Time  `json:"date,omitempty"`
	DayChange   [2]float32 `json:"day_change,omitempty"`
	TimeDelayed string     `json:"time_delayed,omitempty"`
	OneMonthS   string     `json:"one_month_s,omitempty"`
	ThreeMonthS string     `json:"three_month_s,omitempty"`
	SixMonthS   string     `json:"six_month_s,omitempty"`
	OneYearS    string     `json:"one_year_s,omitempty"`

	OneDay     float32 `json:"one_day,omitempty"`
	OneWeek    float32 `json:"one_week,omitempty"`
	OneMonth   float32 `json:"one_month,omitempty"`
	ThreeMonth float32 `json:"three_month,omitempty"`
	OneYear    float32 `json:"one_year,omitempty"`
	ThreeYears float32 `json:"three_years,omitempty"`
	FiveYears  float32 `json:"five_years,omitempty"`

	CreatedAt time.Time `json:"created_at,omitempty"`
}

FundData represents the dynamic data for the Fund

func NewFundData

func NewFundData(insi string) FundData

NewFundData returns a new empty FundData

func (FundData) GetDate

func (f FundData) GetDate() time.Time

GetDate returns the date which the operation was carried out

func (FundData) GetINSI

func (f FundData) GetINSI() string

GetINSI returns the INSI number for the Fund

func (FundData) GetName

func (f FundData) GetName() string

GetName returns the Fund name

func (FundData) GetNav

func (f FundData) GetNav() float32

GetNav returns the net asset value

func (FundData) Predictions

func (f FundData) Predictions() []float32

Predictions returns the profit predictions

type Funds

type Funds map[string]FundData

Funds contains the dymanic data for each Fund

func CopyFundsMap

func CopyFundsMap(m Funds) Funds

CopyFundsMap creates a deep copy for Funds type

type Operation

type Operation struct {
	ID       string
	FundInsi string
	Date     time.Time
	Amount   float32
	NAV      float32
	Shares   float32
}

Operation represents one operation

func NewOperation

func NewOperation(date time.Time, fund string, amount, nav, shares float32) (Operation, error)

NewOperation returns a new operation

func (Operation) GetAmount

func (op Operation) GetAmount() float32

GetAmount returns the input amount for the operation was carried out

func (Operation) GetCopy

func (op Operation) GetCopy() Operation

GetCopy creates a copy of the wallet

func (Operation) GetDate

func (op Operation) GetDate() time.Time

GetDate returns the date where the operation as made

func (Operation) GetID

func (op Operation) GetID() string

GetID returns the operation ID

func (Operation) GetInsi

func (op Operation) GetInsi() string

GetInsi returns the INSI associated to the Fund where the operation was made

func (Operation) GetNav

func (op Operation) GetNav() float32

GetNav returns the Net Asset Value of the fund to which the operation was carried out

func (Operation) GetShares

func (op Operation) GetShares() float32

GetShares returns the number of shares for the operation was carried out

func (*Operation) SetAmount

func (op *Operation) SetAmount(amount float32)

SetAmount sets the input for this operation

func (*Operation) SetDate

func (op *Operation) SetDate(t time.Time)

SetDate sets the operation's date

func (*Operation) SetInsi

func (op *Operation) SetInsi(insi string)

func (*Operation) SetNav

func (op *Operation) SetNav(nav float32)

SetNav sets the Net Asset Value

func (*Operation) SetShares

func (op *Operation) SetShares(shares float32)

SetShares sets the shares field

type Operations

type Operations map[string][]Operation

Operations represents the operations that were taken by a Fund

func CopyOperationsMap

func CopyOperationsMap(ops Operations) Operations

CopyOperationsMap creates a deep copy for Operations type

type Wallet

type Wallet struct {
	ID        string
	Name      string
	Funds     Funds
	Ops       Operations
	CreatedAt time.Time
	UpdatedAt time.Time
}

Wallet represents a wallet

func NewWallet

func NewWallet(name string) (Wallet, error)

NewWallet creates a new wallet with a defined name

func (*Wallet) AddFund

func (w *Wallet) AddFund(fund FundData) error

AddFund adds the fund and its dynamic data to the wallet

func (*Wallet) AddOperation

func (w *Wallet) AddOperation(op Operation) error

AddOperation adds an operation to the wallet

func (Wallet) Allocations

func (w Wallet) Allocations() map[string][]float32

Allocations returns the percentage of assets allocation in the wallet. The result is a map where the key is the Fund INSI and the value is a slice for the initial allocation and the actual allocation.

func (Wallet) Capitalization

func (w Wallet) Capitalization() map[string][]float32

Capitalization returns the wallet capitalization. The return object is a map which each key is a Fund INSI and the value is slice if 3 elements. The first one represents the shares, the second the inputs, and the third one is the wallet's worth.

func (Wallet) GetAssetsAllocationPOJO

func (w Wallet) GetAssetsAllocationPOJO() map[string]interface{}

GetAssetsAllocationPOJO retuns an object which can be consumed by Charts.js. The object is usefull for plotting the allocations

func (Wallet) GetCopy

func (w Wallet) GetCopy() Wallet

GetCopy creates a copy of the wallet

func (Wallet) GetFundData

func (w Wallet) GetFundData(insi string) FundData

GetFundData returns the dynamic data associated to each Fund

func (Wallet) GetFundInsiByName

func (w Wallet) GetFundInsiByName(name string) string

GetFundInsiByName returns the Fund INSI for a given name

func (Wallet) GetFundNameByInsi

func (w Wallet) GetFundNameByInsi(insi string) string

GetFundNameByInsi retruns the Fund name for a given INSI

func (Wallet) GetFunds

func (w Wallet) GetFunds() Funds

GetFunds returns the Funds associated to the wallet

func (Wallet) GetHistoricWalletPOJO

func (w Wallet) GetHistoricWalletPOJO() map[string]interface{}

GetHistoricWalletPOJO retuns an object which can be consumed by Charts.js. The object is usefull for plotting the inputs history

func (Wallet) GetID

func (w Wallet) GetID() string

GetID returns the wallet ID

func (Wallet) GetName

func (w Wallet) GetName() string

GetName returns the wallet name

func (Wallet) GetOperations

func (w Wallet) GetOperations() Operations

GetOperations returns the operations

func (Wallet) GetOperationsFor

func (w Wallet) GetOperationsFor(insi string) ([]Operation, error)

GetOperationsFor returns all the operations associated to a Fund

func (Wallet) HasFund

func (w Wallet) HasFund(insi string) bool

HasFund returns true if the Fund is associated to the wallet, otherwise it returns false

func (Wallet) HasOperation

func (w Wallet) HasOperation(op Operation) bool

HasOperation returns true is the wallet has the operation, otherwise it returns false

func (Wallet) Profitability

func (w Wallet) Profitability() map[string][]float32

Profitability returns the wallet profitability. The return object is a map which each key is a Fund INSI and the value is slice if 4 elements. The first one is the profitability which is the difference between input and wotrh, the second one is the percentage for the profitability, the third one is the TWR (Time-Weighted Return). Finally, the fourth one is MWR Money-Weighted Return.

func (*Wallet) RemoveFundByInsi

func (w *Wallet) RemoveFundByInsi(insi string)

RemoveFundByInsi removes a Fund from the wallet

func (Wallet) RemoveOperation

func (w Wallet) RemoveOperation(opID string) error

RemoveOperation removed an operation from the wallet

func (*Wallet) SetName

func (w *Wallet) SetName(name string) error

SetName sets the wallet name

func (*Wallet) UpdateFundData

func (w *Wallet) UpdateFundData(fund FundData) error

UpdateFundData updates the Fund dynamic data

func (*Wallet) UpdateFundDataAndOps

func (w *Wallet) UpdateFundDataAndOps(oldInsi string, fund FundData) error

UpdateFundDataAndOps updates the Fund dynamic data and its operations

func (*Wallet) UpdateOperation

func (w *Wallet) UpdateOperation(opID string, newOp Operation) error

Jump to

Keyboard shortcuts

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