stock

package
v0.0.0-...-381b1be Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package stock :: buying.go

Package stock :: byExchange.go

Package stock :: byStock.go

Package stock :: exchange.go

Package stock :: market.go

Package stock :: stock.go

Index

Constants

View Source
const (
	// MAXSTACK is the maximum stacks allowed for a stack
	MAXSTACK = 10

	// STACKSIZE is the number of stocks in one stack
	STACKSIZE = 100

	// STOCKAMOUNT is the default number of stocks
	STOCKAMOUNT = 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Buyer

type Buyer interface {
	GetBuyingStocks(id, amount int) []BuyingStock
}

Buyer interface

type Buying

type Buying []BuyingStock

Buying struct

func (Buying) String

func (bu Buying) String() string

String func for Buying

type BuyingStock

type BuyingStock struct {
	StockID    int
	ExchangeID int
	Amount     int
	UnitPrice  float64
	StackDiff  float64
	Pay        float64
}

BuyingStock struct

func (*BuyingStock) String

func (bs *BuyingStock) String() string

String func for BuyingStock

func (*BuyingStock) StringHeader

func (bs *BuyingStock) StringHeader() string

StringHeader func for BuyingStock

type ByStock

type ByStock func(s1, s2 *Stock) bool

ByStock is type of func as Less of sort.Interface

func ByStockID

func ByStockID() ByStock

ByStockID returns a ByStock / Less function of sort.Interface

func ByStockPrice

func ByStockPrice() ByStock

ByStockPrice returns a ByStock / Less function of sort.Interface

func (ByStock) Sort

func (by ByStock) Sort(stocks []*Stock)

Sort func

type Exchange

type Exchange struct {
	ID     int
	Stocks map[int]*Stock
}

Exchange struct

func (*Exchange) GetStocks

func (e *Exchange) GetStocks() []*Stock

GetStocks returns sorted stocks list

func (*Exchange) StockHeader

func (e *Exchange) StockHeader() string

StockHeader func for stocks list header

func (*Exchange) String

func (e *Exchange) String() string

String func for Exchange

type Market

type Market struct {
	Exchanges map[int]*Exchange
}

Market struct

func (*Market) GetBuyingStocks

func (m *Market) GetBuyingStocks(id, amount int) []BuyingStock

GetBuyingStocks returns a set of stock to buy at the lowest price

func (*Market) GetExchanges

func (m *Market) GetExchanges() []*Exchange

GetExchanges returns sorted exchanges list

func (*Market) GetPriceByAmount

func (m *Market) GetPriceByAmount(exchangeID, stockID, amount int) float64

GetPriceByAmount returns the total per exchange, stock, and number of stocks

func (*Market) GetUnitPriceByStack

func (m *Market) GetUnitPriceByStack(exchangeID, stockID, stack int) float64

GetUnitPriceByStack returns the price for spcified exchange, stock, and stack

func (*Market) String

func (m *Market) String() string

String func for Market

type Stock

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

Stock struct represents exchangeable stock - assuming same price for buying and selling - assuming stack is always the same (for simplicity) - note: for varied stack, see GetUnitPriceByBoughtAmount

func NewStock

func NewStock(id, amount int, price, stackDiff float64) *Stock

NewStock builds a stock

func (*Stock) GetPriceByAmount

func (s *Stock) GetPriceByAmount(amount int) float64

GetPriceByAmount returns the total price by number of stocks

func (*Stock) GetUnitPriceByBoughtAmount

func (s *Stock) GetUnitPriceByBoughtAmount(boughtAmount int) float64

GetUnitPriceByBoughtAmount returns the unit price per bought amount

func (*Stock) GetUnitPriceByStack

func (s *Stock) GetUnitPriceByStack(stack int) float64

GetUnitPriceByStack returns the unit price for specified stack

func (*Stock) String

func (s *Stock) String() string

String func for Stock

func (*Stock) StringHeader

func (s *Stock) StringHeader() string

StringHeader func for stocks list header

Jump to

Keyboard shortcuts

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