wad

package
v0.87.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MSatsPerSat is a constant amount of satoshis.
	MSatsPerSat = 1000
	// SatsPerBtc is the number of satoshi's in a bitcoin.
	SatsPerBtc = btcutil.SatoshiPerBitcoin
	// MSatsPerBtc is the number of satoshis in a bitcoin.
	MSatsPerBtc = MSatsPerSat * SatsPerBtc
	// AllCountries is the constant for all nations (international currency).
	AllCountries = "All"
)

Variables

View Source
var CryptoCurrency = CurrencyMap{
	"LTC": {
		Code: "LTC",
		Name: "Litecoin",
	},
	"ETH": {
		Code: "ETH",
		Name: "Ethereum",
	},
}

CryptoCurrency is a list of supported currencies.

View Source
var Fiat = CurrencyMap{}/* 169 elements not displayed */

Fiat is a list of fiat currencies.

Functions

This section is empty.

Types

type Currency

type Currency struct {
	// Code is the currency code (e.g. usd)
	Code string `json:"code"`
	// Countries  is csv list of countries
	Countries string `json:"countries"`
	// Decimals is the number of decimals in currency
	Decimals int `json:"decimals"`
	// IsoNum is the iso code of the country. Negative if null
	IsoNum int `json:"iso_num"`
	// Name is the name of the Currency
	Name string `json:"name"`
	// Symbol is the currency symbol
	Symbol string `json:"symbol"`
}

Currency is a currency type.

type CurrencyMap

type CurrencyMap = map[string]Currency

CurrencyMap of code->currency.

type Rate

type Rate struct {
	// BaseCode is the rate we're converting from
	BaseCode string
	// QuoteCode is the rate we're converting to
	QuoteCode string
	// RateValue is the conversion rate
	RateValue float64
	// Timestamp is the timestamp of the conversion
	Timestamp time.Time
}

Rate is the conversion rate.

func DeriveRate

func DeriveRate(baseQuote string, quoteCode string, rates [2]Rate) Rate

DeriveRate does a cross-currency rate conversion.

func NewRate

func NewRate(baseCode string, quoteCode string, rate float64) Rate

NewRate creates a rate from base quote->quote code (rate).

func (Rate) Convert

func (r Rate) Convert(value float64, valueCode string) (converted float64, code string)

Convert converts a value/code into a new currency.

func (Rate) Includes

func (r Rate) Includes(quote string) bool

Includes determines whether or not the Rate.BaseCode is Rate.BaseCode or the Rate.QuoteCode.

func (Rate) Invert

func (r Rate) Invert() Rate

Invert inverts the wad by flipping the currency conversion.

func (Rate) Other

func (r Rate) Other(code string) string

Other determines if base get quote if quote get base.

func (Rate) ToString

func (r Rate) ToString() string

ToString converts the rate to a string.

type Wad

type Wad struct {
	// MSats is the millisatoshi account in the wad
	MSats float64 `json:"MSats"`
	// AssetStable is wether or not the asset is a stable coin (usd, etc)
	AssetStable bool `json:"asset_stable"`
	// AssetUnit is the conversion rate of the asset
	AssetUnit float64 `json:"asset_unit"`
	// contains filtered or unexported fields
}

Wad is a unit of currencies.

func BitcoinWad

func BitcoinWad(msats float64) Wad

BitcoinWad creates a bitcoin wad.

func CadWad

func CadWad(cad float64, rate Rate) Wad

CadWad is a wad denominated in CAD.

func CustomWad

func CustomWad(units float64, rate Rate, code string, countries string, decimals int, name string, symbol string) Wad

CustomWad creates a custom wad at a given Rate.

func NewWad

func NewWad(msats float64, assetStable bool, assetUnit float64, code string) Wad

NewWad creates a wad.

func UsdWad

func UsdWad(usd float64, rate Rate) Wad

UsdWad is a wad denominated in USD.

func (Wad) FmtLong

func (w Wad) FmtLong() string

FmtLong formats a wad.

func (Wad) FmtShort

func (w Wad) FmtShort() string

FmtShort formats a Wad.

func (*Wad) UpdateCurrency

func (w *Wad) UpdateCurrency(currency Currency)

UpdateCurrency changes the Currency of a wad.

Jump to

Keyboard shortcuts

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