new endpoints

This commit is contained in:
zipfriis
2026-03-25 16:54:46 +01:00
parent 4e5b830e75
commit 52d99c7012
8 changed files with 305 additions and 99 deletions

View File

@@ -0,0 +1,81 @@
package model
import (
"errors"
"time"
)
type Position struct {
Company Company
weight float64
CostBasis float64
Shares int
}
type TradeProduct int
const (
StockTrade TradeProduct = iota // 0
OptionCallTrade // 1
OptionPutTrade // 2
CurrencyTrade // 3
BondTrade
)
type TradeType bool
const (
Buy TradeType = true
Sell TradeType = false
)
type Trade struct {
Ticker Company
Shares int
Product TradeProduct
Type TradeType
Price float64
Currency Currency
Date time.Time
}
type AddTradeRequest struct {
TickerId int
Shares int
Product int
Type bool
Price float64
Currency string
Date time.Time
}
func (r *AddTradeRequest) Validate() error {
if r.TickerId <= 0 {
return errors.New("ticker id must be a positive integer")
}
if r.Shares <= 0 {
return errors.New("shares must be a positive integer")
}
if r.Product < 0 || r.Product > 3 {
return errors.New("product must be between 0 and 3")
}
if r.Price <= 0 {
return errors.New("price must be a positive number")
}
if r.Currency == "" {
return errors.New("currency is required")
}
if r.Date.IsZero() {
return errors.New("date is required")
}
if r.Date.After(time.Now()) {
return errors.New("date cannot be in the future")
}
return nil
}
// for now trades and none stock position will not be supported.
type Portifolio struct {
Positions []Position
Trades []Trade
}