update of posotion by trade his

This commit is contained in:
samantha42
2026-03-26 11:42:38 +01:00
parent 3f878c1dc0
commit 2c24ee48b0
7 changed files with 156 additions and 30 deletions

View File

@@ -32,20 +32,8 @@ const (
Sell TradeType = false
)
type Trade struct {
CompanyID int
Symbol string
CurrencyID int
CurrencyCode string
Shares int
Product TradeProduct
Type TradeType
Price float64
Date time.Time
}
type AddTradeRequest struct {
TickerId int `json:"ticker_id"`
Symbol string `json:"symbol"`
Shares int `json:"shares"`
Product int `json:"product"`
Type bool `json:"type"`
@@ -54,9 +42,19 @@ type AddTradeRequest struct {
Date time.Time `json:"date"`
}
type Trade struct {
Symbol string
CurrencyCode string
Shares int
Product TradeProduct
Type TradeType
Price float64
Date time.Time
}
func (r *AddTradeRequest) Validate() error {
if r.TickerId <= 0 {
return errors.New("ticker id must be a positive integer")
if r.Symbol == "" {
return errors.New("empty SYmbol string")
}
if r.Shares <= 0 {
return errors.New("shares must be a positive integer")
@@ -67,7 +65,7 @@ func (r *AddTradeRequest) Validate() error {
if r.Price <= 0 {
return errors.New("price must be a positive number")
}
if r.CurrencyCode != "" {
if r.CurrencyCode == "" {
return errors.New("currency is required")
}
if r.Date.IsZero() {