models

package
v0.0.0-...-d88c766 Latest Latest
Warning

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

Go to latest
Published: May 3, 2025 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimingFWD Timing = "fwd"
	TimingTTM Timing = "ttm"

	FrequencyUnknown   Frequency = "unknown"
	FrequencyWeekly    Frequency = "weekly"
	FrequencyBiweekly  Frequency = "biweekly"
	FrequencyMonthly   Frequency = "monthly"
	FrequencyQuarterly Frequency = "quarterly"
	FrequencySemi      Frequency = "semi-annual"
	FrequencyYearly    Frequency = "annual"
)

Variables

View Source
var (
	ValidOrderColumns = map[string]bool{
		"price":       true,
		"consensus":   true,
		"score":       true,
		"coverage":    true,
		"marketcap":   true,
		"volume":      true,
		"avgvolume":   true,
		"outstanding": true,
		"beta":        true,
		"eps":         true,
		"pe":          true,
		"yield":       true,
		"payout":      true,
		"holdings":    true,
		"aum":         true,
		"expense":     true,
		"nav":         true,
		"inception":   true,
		"pc":          true,
		"ppc":         true,
		"updated":     true,
	}
	ValidAscValues = map[string]bool{
		"asc":  true,
		"desc": true,
	}
)

Possible valid values for Order and Asc fields

Functions

func CreateETF

func CreateETF(db *sqlx.DB, etf *ETF) error

func CreateExchange

func CreateExchange(db *sqlx.DB, exchange *Exchange) error

func CreateReit

func CreateReit(db *sqlx.DB, reit *REIT) error

func CreateStock

func CreateStock(db *sqlx.DB, stock *Security) (err error)

func GetSecurityTargetGapPercentage

func GetSecurityTargetGapPercentage(db *sqlx.DB, input string) (float64, error)

func InsertDividend

func InsertDividend(tx *sqlx.Tx, dividend *Dividend) error

func InsertSecurity

func InsertSecurity(tx *sqlx.Tx, security *Security) error

func IsSecuritiesTableEmpty

func IsSecuritiesTableEmpty(db *sqlx.DB) (bool, error)

func SecurityExists

func SecurityExists(db *sqlx.DB, ticker string, exchange string) bool

func UpdateDividend

func UpdateDividend(tx *sqlx.Tx, dividend *Dividend) error

func UpdateETF

func UpdateETF(db *sqlx.DB, etf *ETF) error

func UpdateREIT

func UpdateREIT(db *sqlx.DB, reit *REIT) error

func UpdateSecurity

func UpdateSecurity(tx *sqlx.Tx, security *Security) error

func UpdateStock

func UpdateStock(db *sqlx.DB, stock *Security) (err error)

func ValidateBigIntRange

func ValidateBigIntRange(min, max *string, minout, maxout *int64) error

func ValidateIntRange

func ValidateIntRange(min, max *float64, minout, maxout *int) error

Types

type BrowserManager

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

func NewBrowserManager

func NewBrowserManager(maxRequests int) *BrowserManager

func (*BrowserManager) Close

func (bm *BrowserManager) Close()

func (*BrowserManager) GetBrowser

func (bm *BrowserManager) GetBrowser() *rod.Browser

📌 Get a browser instance for scraping

func (*BrowserManager) MonitorBrowserHealth

func (bm *BrowserManager) MonitorBrowserHealth()

func (*BrowserManager) MonitorMemory

func (bm *BrowserManager) MonitorMemory()

🚀 Restart Chrome if memory usage exceeds 70%

func (*BrowserManager) ReleaseBrowser

func (bm *BrowserManager) ReleaseBrowser()

📌 Called when a scraper finishes using the browser

func (*BrowserManager) RestartBrowserSafely

func (bm *BrowserManager) RestartBrowserSafely()

🚀 Safe Restart with Backup Browser

type CalcInput

type CalcInput struct {
	SID                 string  `form:"sid"`
	Rate                float64 `form:"rate"`
	CompundingFrequency string  `form:"compoundingfrequency"`
	Principal           float64 `form:"principal"`
	Currency            string  `form:"currency"`
	ContribFrequency    string  `form:"contribfrequency"`
	Contribution        float64 `form:"contribution"`
	PriceMod            float64 `form:"pricemod"`
	YieldMod            float64 `form:"yieldmod"`
	Years               int     `form:"years"`
}

type Dividend

type Dividend struct {
	Ticker        string         `db:"ticker" json:"ticker,omitempty"`
	Exchange      string         `db:"exchange" json:"exchange,omitempty"`
	Yield         int            `db:"yield" json:"yield"`
	AnnualPayout  NullableInt    `db:"ap" json:"annualPayout,omitempty"`
	Timing        NullableString `db:"tm" json:"timing,omitempty"` // Enum: fwd, ttm
	PayoutRatio   NullableInt    `db:"pr" json:"payoutRatio,omitempty"`
	GrowthRate    NullableInt    `db:"lgr" json:"growthRate,omitempty"`
	YearsGrowth   NullableInt    `db:"yog" json:"yearsGrowth,omitempty"`
	LastAnnounced NullableInt    `db:"lad" json:"lastAnnounced,omitempty"`
	Frequency     NullableString `db:"frequency" json:"frequency,omitempty"` // Enum: Frequency
	ExDivDate     NullableTime   `db:"edd" json:"exDivDate,omitempty"`
	PayoutDate    NullableTime   `db:"pd" json:"payoutDate,omitempty"`
}

Dividend represents a row from the dividends table.

func (*Dividend) PrettyPrintString

func (d *Dividend) PrettyPrintString() string

type DividendHistoryScrap

type DividendHistoryScrap struct {
	Pr         *int       `json:"pr"`
	Lad        *int       `json:"lad"`
	Frequency  *string    `json:"frequency"`
	ExDivDate  *time.Time `json:"exDivDate"`
	PayoutDate *time.Time `json:"payoutDate"`
}

type ETF

type ETF struct {
	Security          `json:"security"` // Embedded security properties
	Holdings          int               `db:"holdings" json:"holdings"`
	Family            string            `db:"family" json:"family"`
	AUM               NullableInt       `db:"aum" json:"aum,omitempty"`
	ExpenseRatio      NullableInt       `db:"er" json:"expenseRatio,omitempty"`
	NAV               NullableInt       `db:"nav" json:"nav,omitempty"`
	InceptionDate     NullableTime      `db:"inception" json:"inception,omitempty"`
	RelatedSecurities []string          `json:"relatedSecurities"` // Related securities as "TICKER:EXCHANGE:ALLOCATION"
}

ETF represents a row from the etfs table.

func GetETF

func GetETF(db *sqlx.DB, input string) (*ETF, error)

func GetETFs

func GetETFs(
	db *sqlx.DB,
	exchange, country []string,
	minPrice, maxPrice int,
	orderBy []string, orderDirection string,
	limit int,
	dividend bool,
) ([]ETF, error)

func (*ETF) PrettyPrintString

func (etf *ETF) PrettyPrintString() string

func (*ETF) Scan

func (etf *ETF) Scan(rows *sqlx.Rows) error

type Exchange

type Exchange struct {
	Title     string         `db:"title" json:"title"`
	Fullname  string         `db:"fullname" json:"fullname"`
	Prefix    NullableString `db:"prefix" json:"prefix,omitempty"`
	Suffix    NullableString `db:"suffix" json:"suffix,omitempty"`
	CC        string         `db:"cc" json:"countryCode"`
	OpenTime  NullableTime   `db:"opentime" json:"openTime,omitempty"`
	CloseTime NullableTime   `db:"closetime" json:"closeTime,omitempty"`
}

func GetExchangeBySuffixorPrefix

func GetExchangeBySuffixorPrefix(db *sqlx.DB, suffix, prefix string) (*Exchange, error)

func GetExchangeByTitle

func GetExchangeByTitle(db *sqlx.DB, title string) (*Exchange, error)

func InitExchanges

func InitExchanges(db *sqlx.DB) ([]Exchange, error)

type Frequency

type Frequency string

func ParseFrequency

func ParseFrequency(frequency string) (Frequency, error)

type JSONErrorResponse

type JSONErrorResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Error   string `json:"error"`
}

func PlaceholderGet

func PlaceholderGet() (JSONErrorResponse, error)

type NullableInt

type NullableInt sql.NullInt64

func (NullableInt) MarshalJSON

func (ni NullableInt) MarshalJSON() ([]byte, error)

Implement json.Marshaler for NullableInt

func (*NullableInt) Scan

func (ni *NullableInt) Scan(value any) error

Implement sql.Scanner for NullableInt

func (NullableInt) Value

func (ni NullableInt) Value() (driver.Value, error)

Implement driver.Valuer for NullableInt

type NullableString

type NullableString sql.NullString

func (NullableString) MarshalJSON

func (ns NullableString) MarshalJSON() ([]byte, error)

Implement json.Marshaler for NullableString

func (*NullableString) Scan

func (ns *NullableString) Scan(value any) error

Implement sql.Scanner for NullableString

func (NullableString) Value

func (ns NullableString) Value() (driver.Value, error)

Implement driver.Valuer for NullableString

type NullableTime

type NullableTime sql.NullTime

func (NullableTime) MarshalJSON

func (nt NullableTime) MarshalJSON() ([]byte, error)

func (*NullableTime) Scan

func (nt *NullableTime) Scan(value any) error

Implement sql.Scanner for NullableTime

func (NullableTime) Value

func (nt NullableTime) Value() (driver.Value, error)

Implement driver.Valuer for NullableTime

type REIT

type REIT struct {
	Security   `json:"security"` // Embedded security properties
	Occupation NullableInt       `db:"occupation" json:"occupation,omitempty"`
	Focus      NullableString    `db:"focus" json:"focus,omitempty"`
	FFO        NullableInt       `db:"ffo" json:"ffo,omitempty"`
	PFFO       NullableInt       `db:"pffo" json:"pffo,omitempty"`
	Timing     NullableString    `db:"tm" json:"timing,omitempty"` // Enum: fwd, ttm
}

REIT represents a row from the reits table.

func GetREIT

func GetREIT(db *sqlx.DB, input string) (*REIT, error)

func GetREITs

func GetREITs(
	db *sqlx.DB,
	exchange, country []string,
	minPrice, maxPrice int,
	orderBy []string, orderDirection string,
	limit int,
	dividend bool,
) ([]REIT, error)

func (*REIT) Scan

func (r *REIT) Scan(rows *sqlx.Rows) error

type SEO

type SEO struct {
	Description string
	Keywords    string
}

type SecParams

type SecParams struct {
	Exchange        []string  `query:"exchange"`
	Country         []string  `query:"country"`
	Currency        []string  `query:"currency"` // New field
	MinPrice        int       `query:"minPrice"`
	MaxPrice        int       `query:"maxPrice"`
	Consensus       string    `query:"consensus"`      // New field
	MinScore        int       `query:"minScore"`       // New field
	MaxScore        int       `query:"maxScore"`       // New field
	MinCov          int       `query:"minCov"`         // New field
	MaxCov          int       `query:"maxCov"`         // New field
	MinCap          int64     `query:"minCap"`         // New field
	MaxCap          int64     `query:"maxCap"`         // New field
	MinVol          int64     `query:"minVol"`         // New field
	MaxVol          int64     `query:"maxVol"`         // New field
	MinOutstanding  int64     `query:"minOutstanding"` // New field
	MaxOutstanding  int64     `query:"maxOutstanding"` // New field
	MinBeta         int       `query:"minBeta"`        // New field
	MaxBeta         int       `query:"maxBeta"`        // New field
	MinEps          int       `query:"minEps"`         // New field
	MaxEps          int       `query:"maxEps"`         // New field
	MinPe           int       `query:"minPe"`          // New field
	MaxPe           int       `query:"maxPe"`          // New field
	Dividend        bool      `query:"dividend"`
	MinYield        int       `query:"minYield"`        // New field
	MaxYield        int       `query:"maxYield"`        // New field
	MinPayoutRatio  int       `query:"minPayoutRatio"`  // New field
	MaxPayoutRatio  int       `query:"maxPayoutRatio"`  // New field
	Frequency       []string  `query:"frequency"`       // New field
	MinHoldings     int       `query:"minHoldings"`     // New field
	MaxHoldings     int       `query:"maxHoldings"`     // New field
	Family          []string  `query:"family"`          // New field
	MinAum          int64     `query:"minAum"`          // New field
	MaxAum          int64     `query:"maxAum"`          // New field
	MinExpenseRatio int       `query:"minExpenseRatio"` // New field
	MaxExpenseRatio int       `query:"maxExpenseRatio"` // New field
	MinNav          int       `query:"minNav"`          // New field
	MaxNav          int       `query:"maxNav"`          // New field
	MinInception    time.Time `query:"minInception"`    // New field
	MaxInception    time.Time `query:"maxInception"`    // New field
	Order           []string  `query:"order"`
	Asc             string    `query:"asc"`
	Limit           int       `query:"limit"`
}

type SecParamsPointers

type SecParamsPointers struct {
	Exchange        *string  `query:"exchange"`
	Country         *string  `query:"country"`
	Currency        *string  `query:"currency"` // New field
	MinPrice        *float64 `query:"minPrice"`
	MaxPrice        *float64 `query:"maxPrice"`
	Consensus       *string  `query:"consensus"`      // New field
	MinScore        *float64 `query:"minScore"`       // New field
	MaxScore        *float64 `query:"maxScore"`       // New field
	MinCov          *int     `query:"minCov"`         // New field
	MaxCov          *int     `query:"maxCov"`         // New field
	MinCap          *string  `query:"minCap"`         // New field
	MaxCap          *string  `query:"maxCap"`         // New field
	MinVol          *string  `query:"minVol"`         // New field
	MaxVol          *string  `query:"maxVol"`         // New field
	MinOutstanding  *string  `query:"minOutstanding"` // New field
	MaxOutstanding  *string  `query:"maxOutstanding"` // New field
	MinBeta         *float64 `query:"minBeta"`        // New field
	MaxBeta         *float64 `query:"maxBeta"`        // New field
	MinEps          *float64 `query:"minEps"`         // New field
	MaxEps          *float64 `query:"maxEps"`         // New field
	MinPe           *float64 `query:"minPe"`          // New field
	MaxPe           *float64 `query:"maxPe"`          // New field
	Dividend        *bool    `query:"dividend"`
	MinYield        *float64 `query:"minYield"`        // New field
	MaxYield        *float64 `query:"maxYield"`        // New field - depends on dividend
	MinPayoutRatio  *float64 `query:"minPayoutRatio"`  // New field - depends on dividend
	MaxPayoutRatio  *float64 `query:"maxPayoutRatio"`  // New field - depends on dividend
	Frequency       *string  `query:"frequency"`       // New field - depends on dividend
	MinHoldings     *float64 `query:"minHoldings"`     // New field
	MaxHoldings     *float64 `query:"maxHoldings"`     // New field
	Family          *string  `query:"family"`          // New field
	MinAum          *string  `query:"minAum"`          // New field
	MaxAum          *string  `query:"maxAum"`          // New field
	MinExpenseRatio *float64 `query:"minExpenseRatio"` // New field
	MaxExpenseRatio *float64 `query:"maxExpenseRatio"` // New field
	MinNav          *float64 `query:"minNav"`          // New field
	MaxNav          *float64 `query:"maxNav"`          // New field
	MinInception    *string  `query:"minInception"`    // New field
	MaxInception    *string  `query:"maxInception"`    // New field
	Order           *string  `query:"order"`
	Asc             *string  `query:"asc"`
	Limit           *int     `query:"limit"`
}

func (*SecParamsPointers) Validate

func (p *SecParamsPointers) Validate() (*SecParams, error)

Validate method ensures that all fields are valid and normalizes them

type Security

type Security struct {
	Ticker      string         `db:"ticker" json:"ticker"`
	Exchange    string         `db:"exchange" json:"exchange"`
	Typology    string         `db:"typology" json:"typology"` // STOCK, ETF, REIT
	Currency    string         `db:"currency" json:"currency"`
	FullName    string         `db:"fullname" json:"fullName"`
	Sector      NullableString `db:"sector" json:"sector,omitempty"`
	Industry    NullableString `db:"industry" json:"industry,omitempty"`
	SubIndustry NullableString `db:"subindustry" json:"subIndustry,omitempty"`
	Price       int            `db:"price" json:"price"`
	PC          int            `db:"pc" json:"pc"`
	PCP         int            `db:"pcp" json:"pcp"`
	YearLow     int            `db:"yrl" json:"yearLow"`
	YearHigh    int            `db:"yrh" json:"yearHigh"`
	DayLow      int            `db:"drl" json:"dayLow"`
	DayHigh     int            `db:"drh" json:"dayHigh"`
	Consensus   NullableString `db:"consensus" json:"consensus,omitempty"`
	Score       NullableInt    `db:"score" json:"score,omitempty"`
	Coverage    NullableInt    `db:"coverage" json:"coverage,omitempty"`
	MarketCap   NullableInt    `db:"cap" json:"marketCap,omitempty"`
	Volume      NullableInt    `db:"volume" json:"volume,omitempty"`
	AvgVolume   NullableInt    `db:"avgvolume" json:"avgVolume,omitempty"`
	Outstanding NullableInt    `db:"outstanding" json:"outstanding,omitempty"`
	Beta        NullableInt    `db:"beta" json:"beta,omitempty"`
	PClose      int            `db:"pclose" json:"previousClose"`
	COpen       int            `db:"copen" json:"currentOpen"`
	Bid         int            `db:"bid" json:"bid"`
	BidSize     NullableInt    `db:"bidsz" json:"bidSize,omitempty"`
	Ask         int            `db:"ask" json:"ask"`
	AskSize     NullableInt    `db:"asksz" json:"askSize,omitempty"`
	EPS         NullableInt    `db:"eps" json:"eps,omitempty"`
	PE          NullableInt    `db:"pe" json:"pe,omitempty"`
	Target      NullableInt    `db:"target" json:"target,omitempty"`
	STM         NullableString `db:"stm" json:"stm,omitempty"` // Enum: fwd, ttm/
	Created     time.Time      `db:"created" json:"created"`
	Updated     time.Time      `db:"updated" json:"updated"`

	Dividend *Dividend `db:"-" json:"dividend,omitempty"` // Associated dividend data (if exists)
}

func GetStock

func GetStock(db *sqlx.DB, input string) (*Security, error)

func GetStocks

func GetStocks(
	db *sqlx.DB,
	exchange, country []string,
	minPrice, maxPrice int,
	orderBy []string, orderDirection string,
	limit int,
	dividend bool,
) ([]Security, error)

func (*Security) CreatePrettyPrintString

func (s *Security) CreatePrettyPrintString() string

func (*Security) Scan

func (s *Security) Scan(rows *sqlx.Rows) error

Scan implements the sql.Scanner interface for Security.

type SecuritySearchView

type SecuritySearchView struct {
	Ticker   string `json:"ticker"`
	Exchange string `json:"exchange"`
	Title    string `json:"title"` // derived from fullname
	Price    string `json:"price"`
	Typology string `json:"typology"`
	Currency string `json:"currency"`
}

func (*SecuritySearchView) Scan

func (s *SecuritySearchView) Scan(rows *sqlx.Rows) error

type SecurityVars

type SecurityVars struct {
	Price        float64
	Currency     string
	Yield        float64
	Frequency    string
	ExpenseRatio float64
	PayoutMonth  int
}

func GetSecurityVars

func GetSecurityVars(db *sqlx.DB, input string) (*SecurityVars, error)

func (*SecurityVars) Scan

func (s *SecurityVars) Scan(rows *sqlx.Rows) error

type SeekingAlphaScrap

type SeekingAlphaScrap struct {
	Holdings   *int       `json:"holdings"`
	FFO        *int       `json:"ffo"`
	PFFO       *int       `json:"pffo"`
	REITiming  *string    `json:"timing"`
	Pr         *int       `json:"pr"`
	Lgr        *int       `json:"lgr"`
	Yog        *int       `json:"yog"`
	Lad        *int       `json:"lad"`
	Frequency  *string    `json:"frequency"`
	ExDivDate  *time.Time `json:"exDivDate"`
	PayoutDate *time.Time `json:"payoutDate"`
}

type SelectedSecurityView

type SelectedSecurityView struct {
	Ticker                 string `json:"ticker"`
	Exchange               string `json:"exchange"`
	Fullname               string `json:"fullname"`
	Price                  string `json:"price"`
	Typology               string `json:"typology"`
	Currency               string `json:"currency"`
	Target                 string `json:"target"`
	Yield                  string `json:"yield"`
	AnnualPayout           string `json:"annualPayout"`
	PayoutRatio            string `json:"payoutRatio"`
	Frequency              string `json:"frequency"`
	Family                 string `json:"family"`
	ExpenseRatio           string `json:"expenseRatio"`
	ProjectedPriceIncrease string `json:"projectedPriceIncrease"`
	ProjectedYieldIncrease string `json:"projectedYieldIncrease"`
}

func GetSecurityView

func GetSecurityView(db *sqlx.DB, tp, input string) (*SelectedSecurityView, error)

func (*SelectedSecurityView) Scan

func (s *SelectedSecurityView) Scan(rows *sqlx.Rows) error

type Site

type Site struct {
	AppName  string
	Title    string
	Metatags SEO
	Year     int
}

func GetDefaultSite

func GetDefaultSite(title string) Site

type Timing

type Timing string

Jump to

Keyboard shortcuts

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