api

package
v0.0.0-...-d6aaa2e Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound represents a not found error in the API.

Functions

This section is empty.

Types

type AnnualReport

type AnnualReport struct {
	FiscalDateEnding       string `json:"fiscalDateEnding"`
	TotalLiabilities       string `json:"totalLiabilities"`
	TotalShareholderEquity string `json:"totalShareholderEquity"`
}

AnnualReport represents key financial data from a stock's annual balance sheet report.

type Authenticator

type Authenticator interface {
	middleware.Authenticator

	GenerateState() (string, error)
	GetBaseURL() (string, error)
	VerifyState(s string) error
	VerifyToken(ctx context.Context, token *oauth2.Token) (*oidc.IDToken, error)
	RevokeToken(ctx context.Context, token string) error
	Exchange(ctx context.Context, code string) (*oauth2.Token, error)
	GetClientID() string
	GetClientOrigin() string
}

Authenticator defines the interface for handling authentication flows within the application.

type BalanceSheetMetadata

type BalanceSheetMetadata struct {
	Symbol        string `json:"symbol"`
	AnnualReports []AnnualReport
}

BalanceSheetMetadata represents a summary of the financial balances of a stock.

type Config

type Config struct {
	Rules map[string]Rule `json:"rules"`
}

Config represents the scoring rules config.

type OverviewMetadata

type OverviewMetadata struct {
	Symbol                    string `json:"symbol"`
	MarketCapitalization      string `json:"MarketCapitalization"`
	PERatio                   string `json:"PERatio"`
	EPS                       string `json:"EPS"`
	DividendYield             string `json:"DividendYield"`
	QuarterlyRevenueGrowthYOY string `json:"QuarterlyRevenueGrowthYOY"`
}

OverviewMetadata represents the overall financial information of a stock.

type Profile

type Profile struct {
	Email   string `json:"email"`
	Name    string `json:"name"`
	Picture string `json:"picture"`
	ID      string `json:"id"`
}

Profile represents the structure of the user data sent to the client.

type Rule

type Rule struct {
	ScoringRanges []ScoringRange `json:"ranges"`
	Weight        float64        `json:"weight"`
}

Rule represents the threshold range and weight of each metric. The threshold ranges of a metric is a set of predefined value intervals used to evaluate the metric performance by assigning it a score.

type ScoringRange

type ScoringRange struct {
	Min   *float64 `json:"min"`
	Max   *float64 `json:"max"`
	Score float64  `json:"score"`
}

ScoringRange represents the lowest and highest values for a range, as well as its computed score.

type Server

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

Server is the API server.

func New

func New(
	apiKey, filePath string,
	cookieCfg ServerCookieConfig,
	store Store,
	auth Authenticator,
	obsrv *observe.Observer,
) *Server

New creates a new API server.

func (*Server) CallbackHandler

func (s *Server) CallbackHandler(w http.ResponseWriter, r *http.Request)

CallbackHandler handles the authenticator provider login callback.

func (*Server) CreateUserHandler

func (s *Server) CreateUserHandler(w http.ResponseWriter, r *http.Request)

CreateUserHandler creates a new user.

func (*Server) GetCurrentUserHandler

func (s *Server) GetCurrentUserHandler(w http.ResponseWriter, r *http.Request)

func (*Server) GetStockAnalysisBySymbolHandler

func (s *Server) GetStockAnalysisBySymbolHandler(w http.ResponseWriter, r *http.Request)

GetStockAnalysisBySymbolHandler performs a basic stock evaluation.

func (*Server) GetStockBySymbolHandler

func (s *Server) GetStockBySymbolHandler(w http.ResponseWriter, r *http.Request)

GetStockBySymbolHandler fetches stock data for the given symbol.

func (*Server) GetUserHandler

func (s *Server) GetUserHandler(w http.ResponseWriter, r *http.Request)

GetUserHandler gets an existing user.

func (*Server) HelloServerHandler

func (s *Server) HelloServerHandler(w http.ResponseWriter, _ *http.Request)

HelloServerHandler is a handler that returns a welcome message.

func (*Server) LoginHandler

func (s *Server) LoginHandler(w http.ResponseWriter, _ *http.Request)

LoginHandler handles the authenticator login process.

func (*Server) LogoutHandler

func (s *Server) LogoutHandler(w http.ResponseWriter, r *http.Request)

LogoutHandler handles the Auth0 logout process. This should be called when the user wants to log out.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the API server.

func (*Server) UpdateUserHandler

func (s *Server) UpdateUserHandler(w http.ResponseWriter, r *http.Request)

UpdateUserHandler updates the existing user.

type ServerCookieConfig

type ServerCookieConfig struct {
	Name     string `json:"name"`
	Path     string `json:"path"`
	HttpOnly bool   `json:"httpOnly"`
	Secure   bool   `json:"secure"`
}

ServerCookieConfig holds server cookie specific configurations.

type StockMetadata

type StockMetadata struct {
	Information   string `json:"1. Information"`
	Symbol        string `json:"2. Symbol"`
	LastRefreshed string `json:"3. Last Refreshed"`
	OutputSize    string `json:"4. Output Size"`
	TimeZone      string `json:"5. Time Zone"`
}

StockMetadata represents the metadata of a stock.

type Store

type Store interface {
	CreateUser(ctx context.Context, user *store.CreateUser) (*store.User, error)
	ListUsers(ctx context.Context, limit, offset int) ([]store.User, error)
	FindUser(ctx context.Context, id uuid.UUID) (*store.User, error)
	UpdateUser(ctx context.Context, user *store.UpdateUser) (*store.User, error)
	FindStockBySymbol(ctx context.Context, symbol string) (*store.Stock, error)
	ListMetrics(ctx context.Context, limit, offset int) ([]store.Metric, error)
	CreateStockMetric(ctx context.Context, stockID, metricID uuid.UUID, value float64) (*store.StockMetric, error)
	FindLatestStockMetrics(ctx context.Context, stockID uuid.UUID) ([]store.LatestStockMetric, error)
	CreateAnalysis(ctx context.Context, userID, stockID uuid.UUID, score float64) (*store.Analysis, error)
	CreateRecommendation(
		ctx context.Context,
		analysisID uuid.UUID,
		action store.Action,
		confidenceLevel float64,
		reason string,
	) (*store.Recommendation, error)
}

Store defines the interface for interacting with the application's persistent storage.

type TimeSeriesDaily

type TimeSeriesDaily struct {
	StockMetadata `json:"Meta Data"`

	TimeSeries map[string]map[string]string `json:"Time Series (Daily)"`
}

TimeSeriesDaily represents the daily time series of a stock.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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