Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Book ¶
type Book struct { Order []*Order // List of all orders in the book Transactions []*Transaction // List of completed transactions OrdersChan chan *Order // Input channel for receiving new orders OrdersChanOut chan *Order // Output channel for sending processed ordes Wg *sync.WaitGroup // WaitGroup for managing concurrent processing }
Book represents a trading book that manages buy and sell orders and executes transactions
func (*Book) AddTransaction ¶
func (b *Book) AddTransaction(transaction *Transaction, wg *sync.WaitGroup)
AddTransaction adds a completed transactio to the book, updating investor asset position and order status
type Investor ¶
type Investor struct { ID string Name string AssetPosition []*InvestorAssetPosition }
Structure - composite data type that groups together variables Investor represents an investor on the market.
func NewInvestor ¶
Constructor Function NewInvestor creates a new instance of the Investor entity.
func (*Investor) AddAssetPosition ¶
func (i *Investor) AddAssetPosition(assetPosition *InvestorAssetPosition)
Methods associated with Investor struct AddAssetPosition adds a new asset position to the investor's portfolio.
func (*Investor) GetAssetPosition ¶
func (i *Investor) GetAssetPosition(assetID string) *InvestorAssetPosition
GetAssetPosition retrieves the asset position based on the assetID.
func (*Investor) UpdateAssetPosition ¶
UpdateAssetPosition updates an existing asset position or adds a new one.
type InvestorAssetPosition ¶
type InvestorAssetPosition struct { AssetID string }
InvestorAssetPosition represents an asset position on the market.
func NewInvestorAssetPosition ¶
func NewInvestorAssetPosition(assetID string, shares int) *InvestorAssetPosition
Constructor Function NewInvestorAssetPosition creates a new instance of the InvestorAssetPosition entity.
type Order ¶
type Order struct { ID string Investor *Investor Asset *Asset Price float64 OrderType string Status string Transactions []*Transaction }
Order represents a buy or sell order in the market.
type OrderQueue ¶
type OrderQueue struct {
Orders []*Order
}
OrderQueue represents a priority queue (heap) for orders.
func NewOrderQueue ¶
func NewOrderQueue() *OrderQueue
NewOrderQueue creates a new instance of the OrderQueue.
func (*OrderQueue) Len ¶
func (oq *OrderQueue) Len() int
Len returns the number of orders in the priority queue. It is used during heap operations to determine the size of the priority queue.
func (*OrderQueue) Less ¶
func (oq *OrderQueue) Less(i, j int) bool
Less returns true if the order at position i has a lower price than the order at position j. It implements the heap.Interface and is used for sorting orders based on their prices.
func (*OrderQueue) Pop ¶
func (oq *OrderQueue) Pop() interface{}
Pop removes and returns the order with the highest priority (lowest price). It is used during heap operations to extract the top order from the priority queue.
func (*OrderQueue) Push ¶
func (oq *OrderQueue) Push(x interface{})
Push adds a new order to the priority queue. It is used during heap operations to insert new orders.
func (*OrderQueue) Swap ¶
func (oq *OrderQueue) Swap(i, j int)
Swap swaps the positions of orders at indices i and j in the queue. It is used during heap operations to maintain the order of the priority queue.
type Transaction ¶
type Transaction struct { ID string SellingOrder *Order BuyingOrder *Order Price float64 Total float64 DateTime time.Time }
Transaction represents a transaction in the market.
func NewTransaction ¶
func NewTransaction(sellingOrder *Order, buyingOrder *Order, shares int, price float64) *Transaction
NewTransaction creates a new instance of the Transaction entity.
func (*Transaction) AddBuyOrderPendingShares ¶
func (t *Transaction) AddBuyOrderPendingShares(shares int)
func (*Transaction) AddSellOrderPendingShares ¶
func (t *Transaction) AddSellOrderPendingShares(shares int)
func (*Transaction) CalculateTotal ¶
func (t *Transaction) CalculateTotal(shares int, price float64)
func (*Transaction) CloseBuyOrder ¶
func (t *Transaction) CloseBuyOrder()
func (*Transaction) CloseSellOrder ¶
func (t *Transaction) CloseSellOrder()