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
- type BalanceChanged
- type BalanceCreated
- type BalanceView
- func (bv *BalanceView) Apply(event eventsourcing.Event) error
- func (bv *BalanceView) CreditPending(transaction *Transaction) error
- func (bv *BalanceView) DebitPending(transaction *Transaction) error
- func (bv *BalanceView) EventTable() string
- func (bv *BalanceView) GetTransitions() []eventsourcing.Transition
- func (bv *BalanceView) MoveAvailableToPending(transaction *Transaction) error
- func (bv *BalanceView) MovePendingToAvailable(transaction *Transaction) error
- func (BalanceView) TableName() string
- type Base
- type CalculationBase
- type DailyClose
- type ID
- type Order
- func (order *Order) Apply(event eventsourcing.Event) error
- func (order *Order) CalculateProfitLoss()
- func (order *Order) CalculateUnrealizedProfitLoss(currentPrice float32)
- func (order *Order) Change(orderType string, stockID string, exchangeDate string, tradePrice float32, ...) error
- func (order *Order) Close() error
- func (order *Order) EventTable() string
- func (order *Order) GetCurrentState() eventsourcing.State
- func (order *Order) GetTransitions() []eventsourcing.Transition
- func (order *Order) QuantityMatched() bool
- func (Order) TableName() string
- type OrderChanged
- type OrderClosed
- type OrderCreated
- type PickedStock
- type Selection
- type StakeConcentration
- type Stock
- type StockPrice
- type ThreePrimary
- type Transaction
- func (tran *Transaction) Apply(event eventsourcing.Event) error
- func (tran *Transaction) Complete() error
- func (tran *Transaction) EventTable() string
- func (tran *Transaction) Fail() error
- func (tran *Transaction) GetCurrentState() eventsourcing.State
- func (tran *Transaction) GetTransitions() []eventsourcing.Transition
- func (Transaction) TableName() string
- type TransactionCompleted
- type TransactionCreated
- type TransactionFailed
- type UnsupportedEventError
- type User
Constants ¶
const ( ZeroID = ID(0) MyIP = "MY_IP" )
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 CalculationBase ¶
type DailyClose ¶
type DailyClose struct { Base StockID string `gorm:"column:stock_id" json:"stockId"` Date string `gorm:"column:exchange_date" json:"date"` 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 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 (*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) EventTable ¶
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 ¶
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"` 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 StockPrice ¶
type ThreePrimary ¶
type ThreePrimary struct { Base StockID string `gorm:"column:stock_id" json:"stockId"` Date string `gorm:"column:exchange_date" json:"exchangeDate"` }
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 (*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 ¶
func (*TransactionCompleted) EventType() eventsourcing.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 ¶
func (*TransactionCreated) EventType() eventsourcing.EventType
EventType returns the name of event
type TransactionFailed ¶
type TransactionFailed struct {
eventsourcing.BaseEvent
}
func (*TransactionFailed) EventType ¶
func (*TransactionFailed) EventType() eventsourcing.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"` }