new model and endpoints..
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user