client

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapError

func WrapError(err error) error

Types

type AssetClass

type AssetClass string
const (
	AssetClassEquity AssetClass = "equity"
	AssetClassCrypto AssetClass = "crypto"
)

type AssetType

type AssetType string
const (
	AssetTypeStock     AssetType = "stock"
	AssetTypeForex     AssetType = "forex"
	AssetTypeIndex     AssetType = "index"
	AssetTypeEtf       AssetType = "etf"
	AssetTypeCommodity AssetType = "commodity"
)

type BISTStockLiveData

type BISTStockLiveData struct {
	Symbol             string  `json:"s"`
	DailyPercentChange float64 `json:"ch"`
	ClosePrice         float64 `json:"p"`
	StockLiveData
}

type Client

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

func NewClient

func NewClient(
	cfg utilities.LaplaceConfiguration,
	logger *logrus.Logger,
) *Client

func (*Client) CreateCustomTheme

func (c *Client) CreateCustomTheme(ctx context.Context, params CreateCustomThemeParams) (*primitive.ObjectID, error)

func (*Client) DeleteCustomTheme

func (c *Client) DeleteCustomTheme(ctx context.Context, id primitive.ObjectID) error

func (*Client) GetAllCollections

func (c *Client) GetAllCollections(ctx context.Context, region Region, locale Locale) ([]Collection, error)

func (*Client) GetAllCustomThemes

func (c *Client) GetAllCustomThemes(ctx context.Context, locale Locale) ([]Collection, error)

func (*Client) GetAllIndustries

func (c *Client) GetAllIndustries(ctx context.Context, region Region, locale Locale) ([]Collection, error)

func (*Client) GetAllSectors

func (c *Client) GetAllSectors(ctx context.Context, region Region, locale Locale) ([]Collection, error)

func (*Client) GetAllStocks

func (c *Client) GetAllStocks(ctx context.Context, region Region) ([]Stock, error)

func (*Client) GetAllThemes

func (c *Client) GetAllThemes(ctx context.Context, region Region, locale Locale) ([]Collection, error)

func (*Client) GetCollectionDetail

func (c *Client) GetCollectionDetail(ctx context.Context, id string, region Region, locale Locale) (CollectionDetail, error)

func (*Client) GetCustomThemeDetail

func (c *Client) GetCustomThemeDetail(ctx context.Context, id string, region Region, locale Locale, sortBy SortBy) (CollectionDetail, error)

func (*Client) GetFinancialRatioComparison

func (c *Client) GetFinancialRatioComparison(ctx context.Context, symbol string, region Region) ([]StockSectorFinancialRatioComparison, error)

func (*Client) GetHistoricalFinancialSheets

func (c *Client) GetHistoricalFinancialSheets(ctx context.Context, symbol string, from FinancialSheetDate, to FinancialSheetDate, sheetType FinancialSheetType, period FinancialSheetPeriod, currency Currency, region Region) (HistoricalFinancialSheets, error)

func (*Client) GetHistoricalPrices

func (c *Client) GetHistoricalPrices(ctx context.Context, symbols []string, region Region, keys []HistoricalPricePeriod) ([]StockPriceGraph, error)

func (*Client) GetHistoricalRatios

func (c *Client) GetHistoricalRatios(ctx context.Context, symbol string, keys []HistoricalRatiosKey, region Region) (StockHistoricalRatios, error)

func (*Client) GetHistoricalRatiosDescriptions

func (c *Client) GetHistoricalRatiosDescriptions(ctx context.Context, locale Locale, region Region) ([]StockHistoricalRatiosDescription, error)

func (*Client) GetIndustryDetail

func (c *Client) GetIndustryDetail(ctx context.Context, id string, region Region, locale Locale) (CollectionDetail, error)

func (*Client) GetLivePriceForBIST

func (c *Client) GetLivePriceForBIST(ctx context.Context, symbols []string) (data <-chan BISTStockLiveData, errors <-chan error, close func(), err error)

func (*Client) GetLivePriceForUS

func (c *Client) GetLivePriceForUS(ctx context.Context, symbols []string) (data <-chan USStockLiveData, errors <-chan error, close func(), err error)

func (*Client) GetSectorDetail

func (c *Client) GetSectorDetail(ctx context.Context, id string, region Region, locale Locale) (CollectionDetail, error)

func (*Client) GetStockDetailByID

func (c *Client) GetStockDetailByID(ctx context.Context, id string, locale Locale) (StockDetail, error)

func (*Client) GetStockDetailBySymbol

func (c *Client) GetStockDetailBySymbol(ctx context.Context, symbol string, assetClass AssetClass, region Region, locale Locale) (StockDetail, error)

func (*Client) GetStockDividends

func (c *Client) GetStockDividends(ctx context.Context, symbol string, region Region) ([]StockDividend, error)

func (*Client) GetStockStats

func (c *Client) GetStockStats(ctx context.Context, symbols []string, keys []StockStatsKey, region Region) ([]StockStats, error)

func (*Client) GetThemeDetail

func (c *Client) GetThemeDetail(ctx context.Context, id string, region Region, locale Locale) (CollectionDetail, error)

func (*Client) GetTopMovers

func (c *Client) GetTopMovers(ctx context.Context, region Region) ([]TopMover, error)

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, types []SearchType, region Region, locale Locale, page int, pageSize PaginationPageSize) (*SearchResponse, error)

func (*Client) UpdateCustomTheme

func (c *Client) UpdateCustomTheme(ctx context.Context, id primitive.ObjectID, params UpdateCustomThemeParams) error

type Collection

type Collection struct {
	ID          primitive.ObjectID `json:"id"`
	Title       string             `json:"title"`
	Description string             `json:"description"`
	Region      []Region           `json:"region"`
	AssetClass  string             `json:"assetClass"`
	ImageUrl    string             `json:"imageUrl"`
	AvatarUrl   string             `json:"avatarUrl"`
	NumStocks   int                `json:"numStocks"`

	Image    string           `json:"image"`
	Order    int              `json:"order"`
	Status   CollectionStatus `json:"status,omitempty"`
	MetaData map[string]any   `json:"metaData,omitempty"`
}

type CollectionDetail

type CollectionDetail struct {
	*Collection `json:",inline"`
	Stocks      []Stock `json:"stocks"`
}

type CollectionStatus

type CollectionStatus string
const (
	CollectionStatusActive   CollectionStatus = "active"
	CollectionStatusInactive CollectionStatus = "inactive"
)

type CollectionType

type CollectionType string
const (
	CollectionTypeSector      CollectionType = "sector"
	CollectionTypeIndustry    CollectionType = "industry"
	CollectionTypeTheme       CollectionType = "theme"
	CollectionTypeCustomTheme CollectionType = "custom-theme"
	CollectionTypeCollection  CollectionType = "collection"
)

type CreateCustomThemeParams

type CreateCustomThemeParams struct {
	Title          LocaleString         `json:"title,omitempty" bson:"title,omitempty" validate:"required"`
	Description    LocaleString         `json:"description,omitempty" bson:"description,omitempty"`
	Region         []Region             `json:"region,omitempty" bson:"region,omitempty"`
	ImageURL       string               `json:"image_url" bson:"image_url"`
	Image          string               `json:"image" bson:"image"`
	AvatarImageURL string               `json:"avatar_url" bson:"avatar_image_url"`
	Stocks         []primitive.ObjectID `json:"stocks" bson:"stocks" validate:"required"`
	Order          int                  `json:"order" bson:"order"`
	Status         CollectionStatus     `json:"status" bson:"status" validate:"required,oneof=active inactive"`
	MetaData       map[string]any       `json:"meta_data,omitempty" bson:"meta_data,omitempty"`
}

type Currency

type Currency string
const (
	CurrencyUSD Currency = "USD"
	CurrencyTRY Currency = "TRY"
	CurrencyEUR Currency = "EUR"
)

type FinancialSheetDate

type FinancialSheetDate struct {
	Day   int `json:"day"`
	Month int `json:"month"`
	Year  int `json:"year"`
}

type FinancialSheetPeriod

type FinancialSheetPeriod string
const (
	FinancialSheetPeriodAnnual     FinancialSheetPeriod = "annual"
	FinancialSheetPeriodQuarterly  FinancialSheetPeriod = "quarterly"
	FinancialSheetPeriodCumulative FinancialSheetPeriod = "cumulative"
)

type FinancialSheetType

type FinancialSheetType string
const (
	FinancialSheetIncomeStatement FinancialSheetType = "incomeStatement"
	FinancialSheetBalanceSheet    FinancialSheetType = "balanceSheet"
	FinancialSheetCashFlow        FinancialSheetType = "cashFlowStatement"
)

type HistoricalFinancialSheet

type HistoricalFinancialSheet struct {
	Period string                        `json:"period"`
	Rows   []HistoricalFinancialSheetRow `json:"rows"`
}

type HistoricalFinancialSheetRow

type HistoricalFinancialSheetRow struct {
	Description             string  `json:"description"`
	Value                   float64 `json:"value"`
	LineCodeId              int     `json:"lineCodeId"`
	IndentLevel             int     `json:"indentLevel"`
	FirstAncestorLineCodeId int     `json:"firstAncestorLineCodeId"`
	SectionLineCodeId       int     `json:"sectionLineCodeId"`
}

type HistoricalFinancialSheets

type HistoricalFinancialSheets struct {
	Sheets []HistoricalFinancialSheet `json:"sheets"`
}

type HistoricalPricePeriod

type HistoricalPricePeriod string
const (
	HistoricalPricePeriodOneDay     HistoricalPricePeriod = "1D"
	HistoricalPricePeriodOneWeek    HistoricalPricePeriod = "1W"
	HistoricalPricePeriodOneMonth   HistoricalPricePeriod = "1M"
	HistoricalPricePeriodThreeMonth HistoricalPricePeriod = "3M"
	HistoricalPricePeriodOneYear    HistoricalPricePeriod = "1Y"
	HistoricalPricePeriodTwoYear    HistoricalPricePeriod = "2Y"
	HistoricalPricePeriodThreeYear  HistoricalPricePeriod = "3Y"
	HistoricalPricePeriodFiveYear   HistoricalPricePeriod = "5Y"
)

type HistoricalRatiosKey

type HistoricalRatiosKey string
const (
	HistoricalRatiosKeyPriceToEarningsRatio HistoricalRatiosKey = "pe-ratio"
	HistoricalRatiosKeyReturnOnEquity       HistoricalRatiosKey = "roe"
	HistoricalRatiosKeyReturnOnAssets       HistoricalRatiosKey = "roa"
	HistoricalRatiosKeyReturnOnCapital      HistoricalRatiosKey = "roic"
)

type LaplaceError

type LaplaceError error
var (
	ErrYouDoNotHaveAccessToEndpoint LaplaceError = errors.New("you do not have access to this endpoint")
	ErrLimitExceeded                LaplaceError = errors.New("limit exceeded")
	ErrEndpointIsNotActive          LaplaceError = errors.New("endpoint is not active")
	ErrInvalidToken                 LaplaceError = errors.New("invalid token")
	ErrInvalidID                    LaplaceError = errors.New("invalid object id")
)

type LaplaceHTTPError

type LaplaceHTTPError struct {
	HTTPStatus    int    `json:"code"`
	Message       string `json:"msg"`
	InternalError error  `json:"-"`
}

func HttpError

func HttpError(httpStatus int, fmtString string, args ...interface{}) *LaplaceHTTPError

func (*LaplaceHTTPError) Cause

func (e *LaplaceHTTPError) Cause() error

Cause returns the root cause error

func (*LaplaceHTTPError) Error

func (e *LaplaceHTTPError) Error() string

func (*LaplaceHTTPError) Is

func (e *LaplaceHTTPError) Is(target error) bool

func (*LaplaceHTTPError) Unwrap

func (e *LaplaceHTTPError) Unwrap() error

func (*LaplaceHTTPError) WithInternalError

func (e *LaplaceHTTPError) WithInternalError(err error) *LaplaceHTTPError

WithInternalError adds internal error information to the error

type Locale

type Locale string
const (
	LocaleTr Locale = "tr"
	LocaleEn Locale = "en"
)

type LocaleString

type LocaleString map[Locale]string

type PaginationPageSize

type PaginationPageSize int
const (
	PageSize10 PaginationPageSize = 10
	PageSize20 PaginationPageSize = 20
	PageSize50 PaginationPageSize = 50
)

type PriceDataPoint

type PriceDataPoint struct {
	Date  int64   `json:"d"`
	Close float64 `json:"c"`
	High  float64 `json:"h"`
	Low   float64 `json:"l"`
	Open  float64 `json:"o"`
}

type Region

type Region string
const (
	RegionTr Region = "tr"
	RegionUs Region = "us"
)

type SearchResponse

type SearchResponse struct {
	Stocks      []SearchResponseStock      `json:"stocks"`
	Collections []SearchResponseCollection `json:"collections"`
	Sectors     []SearchResponseCollection `json:"sectors"`
	Industries  []SearchResponseCollection `json:"industries"`
}

type SearchResponseCollection

type SearchResponseCollection struct {
	ID         primitive.ObjectID `json:"id"`
	Title      string             `json:"title"`
	Region     []string           `json:"region"`
	AssetClass string             `json:"assetClass"`
	ImageUrl   string             `json:"imageUrl"`
	AvatarUrl  string             `json:"avatarUrl"`
}

type SearchResponseStock

type SearchResponseStock struct {
	ID         primitive.ObjectID `json:"id"`
	Name       string             `json:"name"`
	Symbol     string             `json:"title"`
	Region     string             `json:"region"`
	AssetClass string             `json:"assetType"`
	AssetType  string             `json:"type"`
}

type SearchType

type SearchType string
const (
	SearchTypeStock      SearchType = "stock"
	SearchTypeCollection SearchType = "collection"
	SearchTypeSector     SearchType = "sector"
	SearchTypeIndustry   SearchType = "industry"
)

type SortBy

type SortBy string
const (
	SortByPriceChange SortBy = "price_change"
)

type Stock

type Stock struct {
	ID          primitive.ObjectID `json:"id"`
	AssetType   AssetType          `json:"assetType"`
	Name        string             `json:"name"`
	Symbol      string             `json:"symbol"`
	SectorId    primitive.ObjectID `json:"sectorId"`
	IndustryId  primitive.ObjectID `json:"industryId"`
	UpdatedDate time.Time          `json:"updatedDate"`
	DailyChange float64            `json:"dailyChange,omitempty"`
}

type StockDetail

type StockDetail struct {
	ID                        primitive.ObjectID `json:"id"`
	AssetType                 AssetType          `json:"assetType"`
	AssetClass                AssetClass         `json:"assetClass"`
	Name                      string             `json:"name"`
	Symbol                    string             `json:"symbol"`
	Description               string             `json:"description"`
	LocalizedDescription      LocaleString       `json:"localized_description"`
	ShortDescription          string             `json:"shortDescription"`
	LocalizedShortDescription LocaleString       `json:"localizedShortDescription"`
	Region                    string             `json:"region"`
	SectorId                  primitive.ObjectID `json:"sectorId"`
	IndustryId                primitive.ObjectID `json:"industryId"`
	UpdatedDate               time.Time          `json:"updatedDate"`
}

type StockDividend

type StockDividend struct {
	Date              time.Time `json:"date"`
	DividendAmount    float32   `json:"dividendAmount"`
	DividendRatio     float32   `json:"dividendRatio"`
	NetDividendAmount float32   `json:"netDividendAmount"`
	NetDividendRatio  float32   `json:"netDividendRatio"`
	PriceThen         float32   `json:"priceThen"`
}

type StockHistoricalRatios

type StockHistoricalRatios struct {
	Symbol     string                                     `json:"symbol"`
	Data       []StockHistoricalRatiosData                `json:"data"`
	Formatting map[string]StockHistoricalRatiosFormatting `json:"formatting"`
}

type StockHistoricalRatiosData

type StockHistoricalRatiosData struct {
	FiscalYear    int                                   `json:"fiscalYear"`
	FiscalQuarter int                                   `json:"fiscalQuarter"`
	Values        map[string]StockHistoricalRatiosValue `json:"values"`
}

type StockHistoricalRatiosDescription

type StockHistoricalRatiosDescription struct {
	Slug        string  `json:"slug"`
	Name        string  `json:"name"`
	Suffix      string  `json:"suffix"`
	Prefix      string  `json:"prefix"`
	Display     bool    `json:"display"`
	Precision   int     `json:"precision"`
	Multiplier  float64 `json:"multiplier"`
	Description string  `json:"description"`
	Interval    string  `json:"interval"`
}

type StockHistoricalRatiosFormatting

type StockHistoricalRatiosFormatting struct {
	Name        string  `json:"name"`
	Slug        string  `json:"slug"`
	Precision   int     `json:"precision"`
	Multiplier  float64 `json:"multiplier"`
	Suffix      string  `json:"suffix"`
	Prefix      string  `json:"prefix"`
	Interval    string  `json:"interval"`
	Description string  `json:"description"`
}

type StockHistoricalRatiosValue

type StockHistoricalRatiosValue struct {
	Value         float64 `json:"value"`
	SectorAverage float64 `json:"sectorAverage"`
}

type StockLiveData

type StockLiveData interface{}

type StockPriceGraph

type StockPriceGraph struct {
	Symbol     string           `json:"symbol"`
	OneDay     []PriceDataPoint `json:"1D"`
	OneWeek    []PriceDataPoint `json:"1W"`
	OneMonth   []PriceDataPoint `json:"1M"`
	ThreeMonth []PriceDataPoint `json:"3M"`
	OneYear    []PriceDataPoint `json:"1Y"`
	TwoYear    []PriceDataPoint `json:"2Y"`
	ThreeYear  []PriceDataPoint `json:"3Y"`
	FiveYear   []PriceDataPoint `json:"5Y"`
}

type StockSectorFinancialRatioComparison

type StockSectorFinancialRatioComparison struct {
	MetricName      string                                      `json:"metric_name"`
	NormalizedValue float64                                     `json:"normalizedValue"`
	Details         []StockSectorFinancialRatioComparisonDetail `json:"details"`
}

type StockSectorFinancialRatioComparisonDetail

type StockSectorFinancialRatioComparisonDetail struct {
	Slug          string  `json:"slug"`
	Value         float64 `json:"value"`
	SectorAverage float64 `json:"sectorAverage"`
}

type StockStats

type StockStats struct {
	PreviousClose    float64 `json:"previousClose"`
	MarketCap        float64 `json:"marketCap"`
	PeRatio          float64 `json:"peRatio"`
	PbRatio          float64 `json:"pbRatio"`
	YearLow          float64 `json:"yearLow"`
	YearHigh         float64 `json:"yearHigh"`
	WeeklyReturn     float64 `json:"weeklyReturn"`
	MonthlyReturn    float64 `json:"monthlyReturn"`
	ThreeMonthReturn float64 `json:"3MonthReturn"`
	YtdReturn        float64 `json:"ytdReturn"`
	YearlyReturn     float64 `json:"yearlyReturn"`
	ThreeYear        float64 `json:"3YearReturn"`
	FiveYear         float64 `json:"5YearReturn"`
	Symbol           string  `json:"symbol"`
}

type StockStatsKey

type StockStatsKey string
const (
	StockStatsPreviousClose StockStatsKey = "previous_close"
	StockStatsMarketCap     StockStatsKey = "market_cap"
	StockStatsFK            StockStatsKey = "fk"
	StockStatsPDDD          StockStatsKey = "pddd"
	StockStatsYearLow       StockStatsKey = "year_low"
	StockStatsYearHigh      StockStatsKey = "year_high"
	StockStatsWeeklyReturn  StockStatsKey = "weekly_return"
	StockStatsMonthlyReturn StockStatsKey = "monthly_return"
	StockStats3MonthReturn  StockStatsKey = "3_month_return"
	StockStatsYtdReturn     StockStatsKey = "ytd_return"
	StockStatsYearlyReturn  StockStatsKey = "yearly_return"
	StockStats3YearReturn   StockStatsKey = "3_year_return"
	StockStats5YearReturn   StockStatsKey = "5_year_return"
	StockStatsLatestPrice   StockStatsKey = "latest_price"
)

type TopMover

type TopMover struct {
	Symbol        string  `json:"symbol"`
	PercentChange float64 `json:"percent_change"`
}

type USStockLiveData

type USStockLiveData struct {
	Symbol   string  `json:"s"`
	BidPrice float64 `json:"bp"`
	AskPrice float64 `json:"ap"`
	StockLiveData
}

type UpdateCustomThemeParams

type UpdateCustomThemeParams struct {
	Title          LocaleString         `json:"title,omitempty" bson:"title,omitempty"`
	Description    LocaleString         `json:"description,omitempty" bson:"description,omitempty"`
	ImageURL       string               `json:"image_url" bson:"image_url"`
	Image          string               `json:"image" bson:"image"`
	AvatarImageURL string               `json:"avatar_url" bson:"avatar_image_url"`
	Stocks         []primitive.ObjectID `json:"stockIds" bson:"stockIds"`
	Status         CollectionStatus     `json:"status" bson:"status"`
	MetaData       map[string]any       `json:"meta_data,omitempty" bson:"meta_data,omitempty"`
}

Jump to

Keyboard shortcuts

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