entity

package
v0.0.0-...-e083ea5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright 2021 Wei (Sam) Wang <sam.wang.0723@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Wei (Sam) Wang <sam.wang.0723@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Wei (Sam) Wang <sam.wang.0723@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Wei (Sam) Wang <sam.wang.0723@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Wei (Sam) Wang <sam.wang.0723@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Wei (Sam) Wang <sam.wang.0723@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Wei (Sam) Wang <sam.wang.0723@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Wei (Sam) Wang <sam.wang.0723@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	ZeroID = ID(0)
	MyIP   = "MY_IP"
)
View Source
const (
	OrderTypeBuy      = "Buy"
	OrderTypeSell     = "Sell"
	OrderTypeFee      = "Fee"
	OrderTypeTax      = "Tax"
	OrderTypeDeposit  = "Deposit"
	OrderTypeWithdraw = "Withdraw"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BalanceChanged

type BalanceChanged struct {
	AvailableDelta float32
	PendingDelta   float32
	Amount         float32
	Currency       string
	TransactionID  uint64
	OrderType      string

	eventsourcing.BaseEvent
}

func (*BalanceChanged) EventType

func (*BalanceChanged) EventType() eventsourcing.EventType

type BalanceCreated

type BalanceCreated struct {
	InitialBalance float32

	eventsourcing.BaseEvent
}

func (*BalanceCreated) EventType

func (*BalanceCreated) EventType() eventsourcing.EventType

EventType returns the name of event

type BalanceView

type BalanceView struct {
	Balance   float32   `gorm:"column:balance" json:"balance"`
	Pending   float32   `gorm:"column:pending" json:"pending"`
	Available float32   `gorm:"column:available" json:"available"`
	CreatedAt time.Time `gorm:"column:created_at" mapstructure:"created_at"`
	UpdatedAt time.Time `gorm:"column:updated_at" mapstructure:"updated_at"`

	eventsourcing.BaseAggregate
}

func NewBalanceView

func NewBalanceView(userID uint64, initBalance float32) (*BalanceView, error)

func (*BalanceView) Apply

func (bv *BalanceView) Apply(event eventsourcing.Event) error

Apply updates the aggregate according to a event.

func (*BalanceView) CreditPending

func (bv *BalanceView) CreditPending(transaction *Transaction) error

func (*BalanceView) DebitPending

func (bv *BalanceView) DebitPending(transaction *Transaction) error

func (*BalanceView) EventTable

func (bv *BalanceView) EventTable() string

func (*BalanceView) GetTransitions

func (bv *BalanceView) GetTransitions() []eventsourcing.Transition

GetStates returns all possible state transitions

func (*BalanceView) MoveAvailableToPending

func (bv *BalanceView) MoveAvailableToPending(transaction *Transaction) error

MoveAvailableToPending moves balance from available state to pending state. It doesn't change total balance.

func (*BalanceView) MovePendingToAvailable

func (bv *BalanceView) MovePendingToAvailable(transaction *Transaction) error

func (BalanceView) TableName

func (BalanceView) TableName() string

type Base

type Base struct {
	ID        ID         `gorm:"primaryKey" mapstructure:"id"`
	CreatedAt *time.Time `gorm:"column:created_at" mapstructure:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" mapstructure:"updated_at"`
	DeletedAt gorm.DeletedAt
}

func (*Base) BeforeCreate

func (m *Base) BeforeCreate(tx *gorm.DB) (err error)

type CalculationBase

type CalculationBase struct {
	Date        string `gorm:"column:exchange_date"`
	TradeShares uint64 `gorm:"column:trade_shares"`
	Diff        int    `gorm:"column:diff"`
}

type DailyClose

type DailyClose struct {
	Base

	StockID string `gorm:"column:stock_id"      json:"stockId"`
	Date    string `gorm:"column:exchange_date" json:"date"`
	// Total volumes of shares being traded.
	TradedShares uint64 `gorm:"column:trade_shares"  json:"tradeShares"`
	// Total numbers of transaction.
	Transactions uint64 `gorm:"column:transactions"  json:"transactions"`
	// Total traded dollar volume
	Turnover  uint64  `gorm:"column:turnover"      json:"turnover"`
	Open      float32 `gorm:"column:open"          json:"open"`
	Close     float32 `gorm:"column:close"         json:"close"`
	High      float32 `gorm:"column:high"          json:"high"`
	Low       float32 `gorm:"column:low"           json:"low"`
	PriceDiff float32 `gorm:"column:price_diff"    json:"priceDiff"`
}

func (DailyClose) TableName

func (DailyClose) TableName() string

type ID

type ID uint64

func GenID

func GenID() (ID, error)

func (ID) Uint64

func (id ID) Uint64() uint64

type Order

type Order struct {
	StockID          string  `gorm:"column:stock_id" json:"stockId"`
	UserID           uint64  `gorm:"column:user_id" json:"userId"`
	BuyPrice         float32 `gorm:"column:buy_price" json:"buyPrice"`
	BuyQuantity      uint64  `gorm:"column:buy_quantity" json:"buyQuantity"`
	BuyExchangeDate  string  `gorm:"column:buy_exchange_date" json:"buyExchangeDate"`
	SellPrice        float32 `gorm:"column:sell_price" json:"sellPrice"`
	SellQuantity     uint64  `gorm:"column:sell_quantity" json:"sellQuantity"`
	SellExchangeDate string  `gorm:"column:sell_exchange_date" json:"sellExchangeDate"`
	ProfitablePrice  float32 `gorm:"column:profitable_price" json:"profitablePrice"`
	Status           string  `gorm:"column:status" json:"status,omitempty"`

	ProfitLoss        float32
	ProfitLossPercent float32
	StockName         string
	CurrentPrice      float32

	CreatedAt time.Time `gorm:"column:created_at" mapstructure:"created_at"`
	UpdatedAt time.Time `gorm:"column:updated_at" mapstructure:"updated_at"`

	eventsourcing.BaseAggregate
}

func NewOrder

func NewOrder(
	userID uint64,
	orderType string,
	stockID string,
	exchangeDate string,
	tradePrice float32,
	quantity uint64,
) (*Order, error)

func (*Order) Apply

func (order *Order) Apply(event eventsourcing.Event) error

Apply updates the aggregate according to a event.

func (*Order) CalculateProfitLoss

func (order *Order) CalculateProfitLoss()

func (*Order) CalculateUnrealizedProfitLoss

func (order *Order) CalculateUnrealizedProfitLoss(currentPrice float32)

func (*Order) Change

func (order *Order) Change(
	orderType string,
	stockID string,
	exchangeDate string,
	tradePrice float32,
	quantity uint64,
) error

func (*Order) Close

func (order *Order) Close() error

func (*Order) EventTable

func (order *Order) EventTable() string

func (*Order) GetCurrentState

func (order *Order) GetCurrentState() eventsourcing.State

func (*Order) GetTransitions

func (order *Order) GetTransitions() []eventsourcing.Transition

GetStates returns all possible state transitions

func (*Order) QuantityMatched

func (order *Order) QuantityMatched() bool

func (Order) TableName

func (Order) TableName() string

type OrderChanged

type OrderChanged struct {
	OrderType    string
	StockID      string
	ExchangeDate string
	TradePrice   float32
	Quantity     uint64
	Description  string
	ProfitLoss   float32

	eventsourcing.BaseEvent
}

func (*OrderChanged) EventType

func (*OrderChanged) EventType() eventsourcing.EventType

EventType returns the name of event

type OrderClosed

type OrderClosed struct {
	eventsourcing.BaseEvent
}

func (*OrderClosed) EventType

func (*OrderClosed) EventType() eventsourcing.EventType

EventType returns the name of event

type OrderCreated

type OrderCreated struct {
	OrderType       string
	StockID         string
	ExchangeDate    string
	TradePrice      float32
	Quantity        uint64
	Description     string
	ProfitablePrice float32
	ProfitLoss      float32

	eventsourcing.BaseEvent
}

func (*OrderCreated) EventType

func (*OrderCreated) EventType() eventsourcing.EventType

EventType returns the name of event

type PickedStock

type PickedStock struct {
	Base

	StockID string `gorm:"column:stock_id" json:"stockId"`
	UserID  uint64 `gorm:"column:user_id" json:"userId"`
}

func (PickedStock) TableName

func (PickedStock) TableName() string

type Selection

type Selection struct {
	StockID         string  `gorm:"column:stock_id" json:"stockId"`
	Name            string  `gorm:"column:name" json:"name"`
	Category        string  `gorm:"column:category" json:"category"`
	Date            string  `gorm:"column:exchange_date" json:"-"`
	Open            float32 `gorm:"column:open" json:"open"`
	High            float32 `gorm:"column:high" json:"high"`
	Low             float32 `gorm:"column:low" json:"low"`
	Close           float32 `gorm:"column:close" json:"close"`
	PriceDiff       float32 `gorm:"column:price_diff" json:"priceDiff"`
	Concentration1  float32 `gorm:"column:concentration_1" json:"concentration1"`
	Concentration5  float32 `gorm:"column:concentration_5" json:"concentration5"`
	Concentration10 float32 `gorm:"column:concentration_10" json:"concentration10"`
	Concentration20 float32 `gorm:"column:concentration_20" json:"concentration20"`
	Concentration60 float32 `gorm:"column:concentration_60" json:"concentration60"`
	Volume          int     `gorm:"column:volume" json:"volume"`
	Trust           int     `gorm:"column:trust" json:"trust"`
	Foreign         int     `gorm:"column:foreignc" json:"foreign"`
	Hedging         int     `gorm:"column:hedging" json:"hedging"`
	Dealer          int     `gorm:"column:dealer" json:"dealer"`
	Trust10         int     `json:"trust10"`
	Foreign10       int     `json:"foreign10"`
	QuoteChange     float32 `json:"quoteChange"`
}

type StakeConcentration

type StakeConcentration struct {
	Base

	StockID         string  `gorm:"column:stock_id" json:"stockId"`
	Date            string  `gorm:"column:exchange_date" json:"exchangeDate"`
	SumBuyShares    uint64  `gorm:"column:sum_buy_shares" json:"sumBuyShares"`
	SumSellShares   uint64  `gorm:"column:sum_sell_shares" json:"sumSellShares"`
	AvgBuyPrice     float32 `gorm:"column:avg_buy_price" json:"avgBuyPrice"`
	AvgSellPrice    float32 `gorm:"column:avg_sell_price" json:"avgSellPrice"`
	Concentration1  float32 `gorm:"column:concentration_1"`
	Concentration5  float32 `gorm:"column:concentration_5"`
	Concentration10 float32 `gorm:"column:concentration_10"`
	Concentration20 float32 `gorm:"column:concentration_20"`
	Concentration60 float32 `gorm:"column:concentration_60"`
	Diff            []int32 `gorm:"-" json:"diff"`
}

func (StakeConcentration) TableName

func (StakeConcentration) TableName() string

type Stock

type Stock struct {
	Base

	StockID  string `gorm:"column:stock_id" json:"stockId"`
	Name     string `gorm:"column:name" json:"name"`
	Country  string `gorm:"column:country" json:"country"`
	Category string `gorm:"column:category" json:"category"`
	Market   string `gorm:"column:market" json:"market"`
}

func (Stock) TableName

func (Stock) TableName() string

type StockPrice

type StockPrice struct {
	ExchangeDate string  `gorm:"column:exchange_date" json:"exchangeDate"`
	StockID      string  `gorm:"column:stock_id"      json:"stockId"`
	Price        float32 `gorm:"column:close"         json:"price"`
}

type ThreePrimary

type ThreePrimary struct {
	Base

	StockID            string `gorm:"column:stock_id" json:"stockId"`
	Date               string `gorm:"column:exchange_date" json:"exchangeDate"`
	ForeignTradeShares int64  `gorm:"column:foreign_trade_shares" json:"foreignTradeShares"`
	TrustTradeShares   int64  `gorm:"column:trust_trade_shares" json:"trustTradeShares"`
	DealerTradeShares  int64  `gorm:"column:dealer_trade_shares" json:"dealerTradeShares"`
	HedgingTradeShares int64  `gorm:"column:hedging_trade_shares" json:"hedgingTradeShares"`
}

func (ThreePrimary) TableName

func (ThreePrimary) TableName() string

type Transaction

type Transaction struct {
	UserID       uint64    `gorm:"column:user_id" json:"userId"`
	OrderType    string    `gorm:"column:order_type" json:"orderType"`
	CreditAmount float32   `gorm:"column:credit_amount" json:"creditAmount"`
	DebitAmount  float32   `gorm:"column:debit_amount" json:"debitAmount"`
	OrderID      uint64    `gorm:"column:order_id" json:"orderId"`
	Status       string    `gorm:"column:status" json:"status,omitempty"`
	CreatedAt    time.Time `gorm:"column:created_at" mapstructure:"created_at"`
	UpdatedAt    time.Time `gorm:"column:updated_at" mapstructure:"updated_at"`

	eventsourcing.BaseAggregate
}

func NewTransaction

func NewTransaction(
	userID uint64,
	orderType string,
	creditAmount float32,
	debitAmount float32,
	orderID ...uint64,
) (*Transaction, error)

func (*Transaction) Apply

func (tran *Transaction) Apply(event eventsourcing.Event) error

Apply updates the aggregate according to a event.

func (*Transaction) Complete

func (tran *Transaction) Complete() error

func (*Transaction) EventTable

func (tran *Transaction) EventTable() string

func (*Transaction) Fail

func (tran *Transaction) Fail() error

func (*Transaction) GetCurrentState

func (tran *Transaction) GetCurrentState() eventsourcing.State

func (*Transaction) GetTransitions

func (tran *Transaction) GetTransitions() []eventsourcing.Transition

GetStates returns all possible state transitions

func (Transaction) TableName

func (Transaction) TableName() string

type TransactionCompleted

type TransactionCompleted struct {
	eventsourcing.BaseEvent
}

func (*TransactionCompleted) EventType

EventType returns the name of event

type TransactionCreated

type TransactionCreated struct {
	DebitAmount  float32
	CreditAmount float32
	OrderType    string
	OrderID      uint64

	eventsourcing.BaseEvent
}

func (*TransactionCreated) EventType

EventType returns the name of event

type TransactionFailed

type TransactionFailed struct {
	eventsourcing.BaseEvent
}

func (*TransactionFailed) EventType

EventType returns the name of event

type UnsupportedEventError

type UnsupportedEventError struct {
	// contains filtered or unexported fields
}

func (*UnsupportedEventError) Error

func (e *UnsupportedEventError) Error() string

type User

type User struct {
	Base

	FirstName        string     `gorm:"column:first_name" json:"firstName"`
	LastName         string     `gorm:"column:last_name" json:"lastName"`
	Email            string     `gorm:"column:email" json:"email"`
	Phone            string     `gorm:"column:phone" json:"phone"`
	Password         string     `gorm:"column:password" json:"password"`
	SessionID        string     `gorm:"column:session_id" json:"sessionID"`
	EmailConfirmedAt *time.Time `gorm:"column:email_confirmed_at" mapstructure:"email_confirmed_at"`
	PhoneConfirmedAt *time.Time `gorm:"column:phone_confirmed_at" mapstructure:"phone_confirmed_at"`
	SessionExpiredAt *time.Time `gorm:"column:session_expired_at" mapstructure:"session_expired_at"`
}

func (User) TableName

func (User) TableName() string

Jump to

Keyboard shortcuts

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