diff --git a/internal/database/main.go b/internal/database/main.go index 06f51a3..c765eb9 100644 --- a/internal/database/main.go +++ b/internal/database/main.go @@ -69,6 +69,29 @@ func InitDB(db *sql.DB) { UNIQUE(company_id, name) ); + -- parent table + CREATE TABLE closed_positions ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + symbol TEXT NOT NULL, + currency_code TEXT NOT NULL, + product TEXT NOT NULL, + open_time DATETIME NOT NULL, + realized_gain REAL, + tax_amount REAL, + holding_days INTEGER + ); + + -- child table, one row per close lot + CREATE TABLE close_entries ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + closed_position_id INTEGER NOT NULL REFERENCES closed_positions(id), + shares INTEGER NOT NULL, + in_price REAL NOT NULL, + out_price REAL NOT NULL, + gain_price REAL NOT NULL, + close_time DATETIME NOT NULL + ); + CREATE TABLE IF NOT EXISTS revenue_entries ( id INTEGER PRIMARY KEY AUTOINCREMENT, company_id INTEGER NOT NULL, diff --git a/internal/model/portifolio.go b/internal/model/portifolio.go index 78be8a5..75532bb 100644 --- a/internal/model/portifolio.go +++ b/internal/model/portifolio.go @@ -5,6 +5,36 @@ import ( "time" ) +type Dividend struct { + Symbol string + CurrencyCode string + Product TradeProduct + Value float64 + PaymentDate time.Time + TaxAmount float64 + TaxRate float64 + NetValue float64 +} + +type CloseEntry struct { + Shares int + InPrice float64 + OutPrice float64 + GainPrice float64 + CloseTime time.Time +} + +type ClosedPosition struct { + Symbol string + CurrencyCode string + Product TradeProduct + Closes []CloseEntry // each close carries its own prices + share count + OpenTime time.Time + RealizedGain float64 + TaxAmount float64 + HoldingDays int +} + type Position struct { CompanyID int Symbol string @@ -81,4 +111,6 @@ func (r *AddTradeRequest) Validate() error { type Portifolio struct { Positions []Position Trades []Trade + closed []ClosedPosition + Dividends []Dividend } diff --git a/main.go b/main.go index cc1844f..18dbc2d 100644 --- a/main.go +++ b/main.go @@ -50,12 +50,17 @@ func main() { //Trades mux.HandleFunc("POST /trade/add", handlers.AddTradeHandler(db)) mux.HandleFunc("GET /trade/list", handlers.GetTradeListHandler(db)) + mux.HandleFunc("GET /trade/search", handlers.GetTradeListHandler(db)) // new + //Positions mux.HandleFunc("GET /positions/list", handlers.GetPositionListHandler(db)) - + mux.HandleFunc("GET /positions/closed/list", handlers.GetPositionListHandler(db)) // new + mux.HandleFunc("GET /positions/closed/search", handlers.GetTradeListHandler(db)) // new // Company mux.HandleFunc("POST /company/add", handlers.AddCompanyHandler(db)) mux.HandleFunc("GET /company/list", handlers.GetCompaniesHandler(db)) mux.HandleFunc("GET /company/revenue/categories", handlers.GetCompanyRevenueCategories(db)) + mux.HandleFunc("POST /company/S-O/add", handlers.GetCompaniesHandler(db)) // new + mux.HandleFunc("GET /company/S-O/list", handlers.GetCompaniesHandler(db)) // new // Currency mux.HandleFunc("GET /currency/list", handlers.GetCurrenciesHandler(db))