entity

package
v0.0.0-...-b74f185 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	ID           string
	Name         string
	MarketVolume int
}

Asset represents an asset in the market.

func NewAsset

func NewAsset(id string, name string, marketVolume int) *Asset

Constructor Function NewAsset creates a new instance of the Asset entity.

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 NewBook

func NewBook(orderChan chan *Order, orderChanOut chan *Order, wg *sync.WaitGroup) *Book

NewBook creates a new Book instance with the given order channels and WaitGroup

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

func (*Book) Trade

func (b *Book) Trade()

Trade procesess incoming orders and executes trades based on matching logic

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

func NewInvestor(id string) *Investor

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

func (i *Investor) UpdateAssetPosition(assetID string, qtdShares int)

UpdateAssetPosition updates an existing asset position or adds a new one.

type InvestorAssetPosition

type InvestorAssetPosition struct {
	AssetID string
	Shares  int
}

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
	Shares        int
	PendingShares int
	Price         float64
	OrderType     string
	Status        string
	Transactions  []*Transaction
}

Order represents a buy or sell order in the market.

func NewOrder

func NewOrder(orderID string, investor *Investor, asset *Asset, shares int, price float64, orderType string) *Order

Constructor Function NewOrder creates a new instance of the Order entity.

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
	Shares       int
	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()

Jump to

Keyboard shortcuts

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