entity

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SatoshiInBitcoin = 100_000_000

	BTCSuffix = "BTC"
)
View Source
const (
	CentInUSD = 100

	USDPrefix = "$"
)
View Source
const MinimalPrecision = 10

Variables

View Source
var (
	DepositUSDAction  = USDAction{"deposit"}
	WithdrawUSDAction = USDAction{"withdraw"}

	BuyBTCAction  = BTCAction{"buy"}
	SellBTCAction = BTCAction{"sell"}
)
View Source
var ErrInvalidAction = errors.New("invalid action")
View Source
var ErrPrecisionInvalidFormat = errors.New("invalid format to get precision")
View Source
var ErrSubtractMoreBTCThanHave = errors.New("can't subtract more btc than available")
View Source
var ErrSubtractMoreUSDThanHave = errors.New("can't subtract more usd than available")

Functions

func CountPrecision

func CountPrecision(value int) (int, error)

CountPrecision counts float numbers precision From integer in format like 1 (one) with some amount of zeroes It uses math.Log10 to count the number of digits It is used for formatting (satoshi -> btc, cent -> dollar) See BTC.String and USD.String for example of usage

func MustCountPrecision

func MustCountPrecision(value int) int

Types

type BTC

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

func MustNewBTC

func MustNewBTC(amount float64) BTC

func NewBTC

func NewBTC(amount float64) (BTC, error)

func (BTC) Add

func (btc BTC) Add(toAdd BTC) BTC

func (BTC) Equal

func (btc BTC) Equal(other BTC) bool

func (BTC) IsZero

func (btc BTC) IsZero() bool

func (BTC) LessThan

func (btc BTC) LessThan(other BTC) bool

func (BTC) String

func (btc BTC) String() string

func (BTC) Sub

func (btc BTC) Sub(toSubtract BTC) (BTC, error)

func (BTC) ToFloat

func (btc BTC) ToFloat() *big.Float

func (BTC) ToFloat64

func (btc BTC) ToFloat64() float64

func (BTC) ToUSD

func (btc BTC) ToUSD(price BTCPrice) USD

type BTCAction

type BTCAction action

func NewBTCAction

func NewBTCAction(action string) (BTCAction, error)

type BTCPrice

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

func NewBTCPrice

func NewBTCPrice(price USD, updatedAt time.Time) BTCPrice

func (BTCPrice) GetPrice

func (btcPrice BTCPrice) GetPrice() USD

func (BTCPrice) GetUpdatedAt

func (btcPrice BTCPrice) GetUpdatedAt() time.Time

type BTCRepository

type BTCRepository interface {
	Get() BTCPrice
	SetPrice(price USD) error
}

type USD

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

func MustNewUSD

func MustNewUSD(amount float64) USD

func NewUSD

func NewUSD(amount float64) (USD, error)

func (USD) Add

func (usd USD) Add(toAdd USD) USD

func (USD) Equal

func (usd USD) Equal(toCompare USD) bool

func (USD) IsZero

func (usd USD) IsZero() bool

func (USD) LessThan

func (usd USD) LessThan(toCompare USD) bool

func (USD) String

func (usd USD) String() string

func (USD) Sub

func (usd USD) Sub(toSubtract USD) (USD, error)

func (USD) ToFloat

func (usd USD) ToFloat() *big.Float

func (USD) ToFloat64

func (usd USD) ToFloat64() float64

type USDAction

type USDAction action

func NewUSDAction

func NewUSDAction(action string) (USDAction, error)

Jump to

Keyboard shortcuts

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