calc

package
v0.6.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: BlueOak-1.0.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

View Source
const RateEncodingFactor = 1e8

RateEncodingFactor is used when encoding an exchange rate as an integer. https://github.com/decred/dcrdex/blob/master/spec/comm.mediawiki#Rate_Encoding

Variables

This section is empty.

Functions

func BaseToQuote

func BaseToQuote(rate uint64, base uint64) (quote uint64)

BaseToQuote computes a quote asset amount based on a base asset amount and an integer representation of the price rate. That is,

quoteAmt = rate * baseAmt / atomsPerCoin

func ConventionalRate added in v0.4.0

func ConventionalRate(msgRate uint64, baseInfo, quoteInfo dex.UnitInfo) float64

ConventionalRate converts an exchange rate in message-rate encoding to a conventional exchange rate, using the base and quote assets' UnitInfo.

func ConventionalRateAlt added in v0.4.0

func ConventionalRateAlt(msgRate uint64, baseFactor, quoteFactor uint64) float64

ConventionalRateAlt converts an exchange rate in message-rate encoding to a conventional exchange rate using the base and quote assets' conventional conversion factors.

func QuoteToBase

func QuoteToBase(rate uint64, quote uint64) (base uint64)

QuoteToBase computes a base asset amount based on a quote asset amount and an integer representation of the price rate. That is,

baseAmt = quoteAmt * atomsPerCoin / rate

func RequiredOrderFunds

func RequiredOrderFunds(swapVal, inputsSize, maxSwaps uint64, nfo *dex.Asset) uint64

RequiredOrderFunds calculates the required amount needed to fulfill the swap amount and pay transaction fees. swapVal is the total quantity needed to fulfill an order. inputsSize is the size of the serialized inputs associated with a set of UTXOs to be spent in the *first* swap txn. maxSwaps is the number of lots in the order. For the quote asset, maxSwaps is not swapVal / lotSize, so it must be a separate parameter. The chained swap txns will be the standard size as they will spend a previous swap's change output. For account-based assets, inputsSize will be zero, and nfo.SwapSize = nfo.SwapSizeBase.

func RequiredOrderFundsAlt added in v0.2.0

func RequiredOrderFundsAlt(swapVal, inputsSize, maxSwaps, swapSizeBase, swapSize, feeRate uint64) uint64

RequiredOrderFundsAlt is the same as RequiredOrderFunds, but built-in type parameters. For account-based assets, inputsSize will be zero, and swapSize = swapSizeBase.

Types

This section is empty.

Jump to

Keyboard shortcuts

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