postgresql

package module
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 13 Imported by: 7

README

Functions that use PostgreSQL and are mostly used in my portfolio programs.

Documentation

Overview

Package postgresql Some PostgreSQL using functions

Package postgresql Some PostgreSQL using functions

Package postgresql Some PostgreSQL using functions

Package postgresql Some PostgreSQL using functions

Package postgresql Some PostgreSQL using functions

Package postgresql Some PostgreSQL using functions

Package postgresql Some PostgreSQL using functions

Package postgresql Some PostgreSQL using functions

Package postgresql - Some PostgreSQL using functions

Package postgresql - Some PostgreSQL using functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddEmptyPortfolio added in v0.0.3

func AddEmptyPortfolio(name string)

AddEmptyPortfolio will add a new, empty portfolio

func AddPortfolio

func AddPortfolio(name string, tr, pr float64)

AddPortfolio will add a new portfolio with given values

func AddSymbol added in v0.0.9

func AddSymbol(symbol, name, wkn, isin, sector, lookType, quoteCurrency string)

AddSymbol will add a new symbol. If it already exists, nothing is done.

func AddSymbolWithWarrant added in v0.0.9

func AddSymbolWithWarrant(symbol, name, wkn, isin, lookType, quoteCurrency, basesym, optionend string)

AddSymbolWithWarrant will add a new symbol for a warrant. If it already exists, nothing is done. The warrant information is also added to its table.

func AddWatchlist added in v0.0.9

func AddWatchlist(name string)

AddWatchlist will add a new watchlist. If it already exists, nothing is done.

func CloseConnection

func CloseConnection()

CloseConnection closes the current connection

func FindAllLookupRows

func FindAllLookupRows(whereClause string) pgx.Rows

FindAllLookupRows finds all lookup values.

func FindAllTradeRows

func FindAllTradeRows(whereClause string) pgx.Rows

FindAllTradeRows finds all trade values.

func FindAllTransRows added in v0.0.9

func FindAllTransRows(whereClause string) pgx.Rows

FindAllTransRows finds all transaction values.

func FindLookup

func FindLookup(symbol string) pgx.Rows

FindLookup finds the row in the lookup table for a given symbol.

func FindTrade

func FindTrade(portID int64) pgx.Rows

FindTrade finds the row in the trades table for a given portfolio id.

func GetAllCountries added in v0.0.13

func GetAllCountries() (countries []string)

GetAllCountries returns all known countries with risk values.

func GetAllIsoCodes added in v0.0.13

func GetAllIsoCodes() (fields []string)

GetAllIsoCodes returns all iso codes.

func GetClose

func GetClose(quotes []Quote) (closeVal []float64)

GetClose extracts closing values from given quotes as slice of float64

func GetCurrencyXSymbol added in v0.0.13

func GetCurrencyXSymbol(src, dest string) (symbol string)

GetCurrencyXSymbol returns symbol for given currency pair.

func GetLastQuoteDate

func GetLastQuoteDate(symbol string) (tmpDate string)

GetLastQuoteDate returns the last quote date for given symbol

func GetRiskValuesForCountry added in v0.0.13

func GetRiskValuesForCountry(country string) (MRP, RFR float64)

GetRiskValuesForCountry returns risk values for given country.

func NewDBConnection

func NewDBConnection(user, host, password, port, dbname, appName, sslMode string) (err error)

NewDBConnection Creates the database handler and checks the connection. allowed sslmode values are: disable, allow, prefer, require, verify-ca and verify-full

func UpdateQuoteLoop added in v0.0.4

func UpdateQuoteLoop(allLookup []Lookup)

func UpsertQuotes

func UpsertQuotes(secu string, quotes []Quote)

UpsertQuotes inserts given quotes values into the database or updates open, high, low, close and volume if we already have a row

Types

type CurrSymbCross added in v0.0.13

type CurrSymbCross struct {
	IsoCodeSrc  string
	IsoCodeDest string
	Symbol      string
}

CurrSymbCross contains the structure of a curr_symb_cross row

func NewCurrSymbCross added in v0.0.13

func NewCurrSymbCross() CurrSymbCross

NewCurrSymbCross returns an empty curr_symb_cross row

type Currencies added in v0.0.9

type Currencies struct {
	Currency        string
	Currencycountry string
	IsoCode         string
	Symbol          string
}

Currencies contains the structure of a currencies sentence

func GetAllCurrencies added in v0.0.9

func GetAllCurrencies() (curArr []Currencies)

GetAllCurrencies gets all existing currencies

func GetCurrencySymbol added in v0.0.9

func GetCurrencySymbol(iso string) (currencies Currencies)

GetCurrencySymbol gets the symbol for given ISO code If ISO code is not found an empty currency value is returned

func GetNextCurrencyRow added in v0.0.9

func GetNextCurrencyRow(rows pgx.Rows) (currencies Currencies)

GetNextCurrencyRow returns the next currency row.

func NewCurrency added in v0.0.9

func NewCurrency() Currencies

NewCurrency returns an empty currency row

type Lookup

type Lookup struct {
	Symbol        string
	Name          string
	WKN           string
	ISIN          string
	LookType      string
	QuoteCurrency string
	IsHistory     bool
}

Lookup contains the structure of a lookup sentence

func FindAllCurrentLookup

func FindAllCurrentLookup() []Lookup

FindAllCurrentLookup finds all lookup values which are not test indices and not historic.

func FindAllCurrentLookupOrdered added in v0.0.9

func FindAllCurrentLookupOrdered(column, direction string) []Lookup

FindAllCurrentLookupOrdered finds all lookup values which are not test indices and not historic ordered by column and direction.

func FindAllHistoricLookup added in v0.0.9

func FindAllHistoricLookup() []Lookup

FindAllHistoricLookup finds all lookup values which are not test indices and not historic.

func FindAllHistoricLookupOrdered added in v0.0.9

func FindAllHistoricLookupOrdered(column, direction string) []Lookup

FindAllHistoricLookupOrdered finds all lookup values which are not test indices and is historic ordered by column and direction.

func FindAllLookup

func FindAllLookup() []Lookup

FindAllLookup finds all lookup values.

func FindAllLookupOrdered added in v0.0.9

func FindAllLookupOrdered(column, direction string) []Lookup

FindAllLookupOrdered finds all lookup values ordered by column and direction.

func GetNextLookupRow

func GetNextLookupRow(rows pgx.Rows) Lookup

GetNextLookupRow returns the next lookup row.

func GetSingleIsinLookup

func GetSingleIsinLookup(isin string) Lookup

GetSingleIsinLookup gets one row in the lookup table for a given ISIN. If ISIN is not found an empty lookup value is returned

func GetSingleLookup

func GetSingleLookup(symbol string) Lookup

GetSingleLookup gets one row in the lookup table for a given symbol.

func NewLookup

func NewLookup() Lookup

NewLookup returns an empty lookup

type Portfolio

type Portfolio struct {
	PortfolioID uint64  // portfolio_id
	Name        string  // name
	TradeRisk   float64 // trade_risk
	PortRisk    float64 // port_risk
}

Portfolio is the structure of a portfolio.

func FindAllPortfolios added in v0.0.4

func FindAllPortfolios() (pFolios []Portfolio, err error)

FindAllPortfolios returns all portfolios in the portfolio table.

func FindSpecificPortfolio

func FindSpecificPortfolio(name string) (Portfolio, error)

FindSpecificPortfolio returns portofilo with given name and error status

func GetNextPortfolioRow

func GetNextPortfolioRow(rows pgx.Rows) (Portfolio, error)

GetNextPortfolioRow returns the next portfolio row.

type Quote

type Quote struct {
	Symbol    string    // symbol
	QuoteDate time.Time // quote_date
	Open      float64   // open
	High      float64   // high
	Low       float64   // low
	Close     float64   // close
	Volume    int64     // volume
}

Quote is the structure of a quote.

func FindQuotes

func FindQuotes(symbol, order string) (tmpQuote []Quote)

FindQuotes selects all rows in the quotes table for a given symbol, sorted by quote_date and given sort order.

func GetLastQuote

func GetLastQuote(symbol string) (quote Quote)

GetLastQuote returns the last quote for given symbol

func GetPeriodQuotes added in v0.0.11

func GetPeriodQuotes(security, period string) (quotes []Quote)

func MonthlyQuotes

func MonthlyQuotes(values []Quote) []Quote

MonthlyQuotes analyzes all the given daily values and returns the monthly values accordingly The highest and lowest prices in the monthly trading sessions become the high and low for the monthly marker The open of the first day becomes the open of the month The close of the last day becomes the close of the month

func NewQuote

func NewQuote() Quote

NewQuote returns an empty quote

func UpdateAriva

func UpdateAriva(symbol string) (outLookup []Quote)

UpdateAriva reads values from ariva.de and returns a slice of quotes symbol should be in the format "ariva::<secu>.<boerse_id>"

func UpdateStooq added in v0.0.13

func UpdateStooq(symbol string) (outArr []Quote)

UpdateStooq reads values from stooq.com and returns a slice of quotes symbol should be in the format "stooq::<symbol>"

func UpdateSwisscanto

func UpdateSwisscanto(symbol string) (outArr []Quote)

UpdateSwisscanto reads values from cash.ch or www.swissfunddata.ch and returns a slice of quotes symbol should be in the format "swisscanto::<fundid>"

func UpdateYahoo added in v0.0.13

func UpdateYahoo(symbol string) (outArr []Quote)

UpdateYahoo reads values from query1.finance.yahoo.com and returns a slice of quotes symbol should be in the format "yahoo::<symbol>"

func WeeklyQuotes

func WeeklyQuotes(values []Quote) []Quote

WeeklyQuotes analyzes all the given daily values and returns the weekly values accordingly The highest and lowest prices in the five weekly trading sessions become the high and low for the weekly marker The open of the first day becomes the open of the week The close of the last day becomes the close of the week

func YearlyQuotes

func YearlyQuotes(values []Quote) []Quote

YearlyQuotes analyzes all the given daily values and returns the yearly values accordingly The highest and lowest prices in the yearly trading sessions become the high and low for the yearly marker The open of the first day becomes the open of the year The close of the last day becomes the close of the year

type Risk added in v0.0.13

type Risk struct {
	Country           string
	MarketRiskPremium float64
	RiskFreeRate      float64
}

Risk contains the structure of a risk row

func GetAllRisks added in v0.0.13

func GetAllRisks() (riskArr []Risk)

GetAllRisk gets all existing risk values

func GetNextRiskRow added in v0.0.13

func GetNextRiskRow(rows pgx.Rows) (risk Risk)

GetNextRiskRow returns the next risk row.

func NewRisk added in v0.0.13

func NewRisk() Risk

NewRisk returns an empty risk row

type Trade

type Trade struct {
	TradeID         uint64
	PortfolioID     uint64
	Symbol          string
	Comment         string
	CheckLevelValue float64
	StopLossType    string
	StopLossValue   float64
}

Trade contains the structure of a trades sentence

func FindAllTrades

func FindAllTrades() (tmpTrade []Trade, err error)

FindAllTrades finds all trade values.

func FindPortfolioTrades

func FindPortfolioTrades(portID uint64) (tmpTrade []Trade, err error)

FindPortfolioTrades finds all trades for given portfolio_id.

func GetNextTradeRow

func GetNextTradeRow(rows pgx.Rows) (trade Trade, err error)

GetNextTradeRow returns the next trade row.

func NewTrade

func NewTrade() Trade

NewTrade returns an empty trade

type Transaction added in v0.0.9

type Transaction struct {
	TransactionID uint64
	TradeID       uint64
	PortfolioID   uint64
	Symbol        string
	TransDate     time.Time
	Action        string
	Price         float64
	Quantity      float64
	Brokerage     float64
	Slippage      float64
}

Transaction contains the structure of a transaction row

func FindPortTradeTransactions added in v0.0.9

func FindPortTradeTransactions(portID, tradeID uint64) (tmpTrans []Transaction, err error)

FindPortTradeTransactions finds all Transactions for given portfolio_id and trade_id

func GetNextTransRow added in v0.0.9

func GetNextTransRow(rows pgx.Rows) (trans Transaction, err error)

GetNextTransRow returns the next transaction row.

func NewTransaction added in v0.0.9

func NewTransaction() Transaction

NewTransaction returns an empty transaction

type Warrant added in v0.0.9

type Warrant struct {
	Symbol         string
	BaseSymbol     string
	WarrantEndDate time.Time
}

Warrant is the structure of a warrant.

func FindSpecificWarrant added in v0.0.9

func FindSpecificWarrant(symbol string) (Warrant, error)

FindSpecificWarrant returns warrant with given symbol

func GetNextWarrantRow added in v0.0.9

func GetNextWarrantRow(rows pgx.Rows) (Warrant, error)

GetNextWarrantRow returns the next warrant row.

type Watchlist added in v0.0.9

type Watchlist struct {
	WatchlistID   int64
	WatchlistName string
}

Watchlist is the structure of a watchlist.

func FindAllWatchlists added in v0.0.9

func FindAllWatchlists() (watchs []Watchlist, err error)

FindAllWatchlists returns all watchlists.

func GetNextWatchlistRow added in v0.0.9

func GetNextWatchlistRow(rows pgx.Rows) (Watchlist, error)

GetNextWatchlistRow returns the next watchlist row.

Jump to

Keyboard shortcuts

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