model

package
v0.0.0-...-17a13fa Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusOpen   = "OPEN"
	StatusClosed = "CLOSED"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Investor

type Investor struct {
	ID             int64
	Name           int64
	StocksPosition []*InvestorStocksPosition
}

func NewInvestor

func NewInvestor(id int64) *Investor

func (*Investor) AddStockPosition

func (i *Investor) AddStockPosition(StockPosition *InvestorStocksPosition)

func (*Investor) GetStockPosition

func (i *Investor) GetStockPosition(stockID string) *InvestorStocksPosition

func (*Investor) UpdateStockPosition

func (i *Investor) UpdateStockPosition(stockID string, shares int64)

type InvestorStocksPosition

type InvestorStocksPosition struct {
	StockID string
	Shares  int64
}

func NewInvestorStocksPosition

func NewInvestorStocksPosition(stockID string, shares int64) *InvestorStocksPosition

type OfferBook

type OfferBook struct {
	Order         []*Order
	Transactions  []*Transaction
	OrdersChanIn  chan *Order
	OrdersChanOut chan *Order
	// contains filtered or unexported fields
}

func NewOfferBook

func NewOfferBook(orderChanIn, orderChanOut chan *Order, wg *sync.WaitGroup) *OfferBook

func (*OfferBook) AddTransaction

func (ob *OfferBook) AddTransaction(transaction *Transaction, wg *sync.WaitGroup)

func (*OfferBook) Trade

func (ob *OfferBook) Trade()

type Order

type Order struct {
	ID            int64
	Investor      *Investor
	Stock         *Stock
	Shares        int64
	PendingShares int64
	Price         float64
	OrderType     string
	Status        string
	Transactions  []*Transaction
}

func NewOrder

func NewOrder(orderID int64, investor *Investor, stock *Stock, shares int64, price float64, orderType string) *Order

type OrderQueue

type OrderQueue struct {
	Orders []*Order
}

func NewOrderQueue

func NewOrderQueue() *OrderQueue

func (*OrderQueue) Len

func (oq *OrderQueue) Len() int

func (*OrderQueue) Less

func (oq *OrderQueue) Less(i, j int) bool

func (*OrderQueue) Pop

func (oq *OrderQueue) Pop() any

func (*OrderQueue) Push

func (oq *OrderQueue) Push(x any)

func (*OrderQueue) Swap

func (oq *OrderQueue) Swap(i, j int)

type Stock

type Stock struct {
	ID           string
	Name         string
	MarketVolume int64
}

func NewStock

func NewStock(id string, name string, marketVolume int64) *Stock

type Transaction

type Transaction struct {
	ID           string
	SellingOrder *Order
	BuyingOrder  *Order
	Shares       int64
	Price        float64
	Total        float64
	CreatedAt    time.Time
}

func NewTransaction

func NewTransaction(sellingOrder, buyingOrder *Order, shares int64, price float64) *Transaction

func (*Transaction) AddBuyOrderPendingShares

func (t *Transaction) AddBuyOrderPendingShares(shares int64)

func (*Transaction) AddSellOrderPendingShares

func (t *Transaction) AddSellOrderPendingShares(shares int64)

func (*Transaction) CalculateTotal

func (t *Transaction) CalculateTotal(shares int64)

func (*Transaction) CloseBuyOrder

func (t *Transaction) CloseBuyOrder()

func (*Transaction) CloseSellOrder

func (t *Transaction) CloseSellOrder()

Jump to

Keyboard shortcuts

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