price_function

package
v0.0.0-...-a9c8dba Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertFloat64ToString

func ConvertFloat64ToString(num float64) string

ConvertFloat64ToString converts a `float64` to `string`.

func GetApiResponseValidator

func GetApiResponseValidator() (*validator.Validate, error)

GetApiResponseValidator returns a validator with custom logic registered to validate fields returned by various exchange API responses.

func GetMedianPricesFromTickers

func GetMedianPricesFromTickers[T Ticker](
	tickers []T,
	tickerToExponent map[string]int32,
	resolver types.Resolver,
) (tickerToPrice map[string]uint64, unavailableTickers map[string]error, err error)

GetMedianPricesFromTickers processes through a list of `tickers` and calculates a median price (from `LastPrice`, `AskPrice`, and `BidPrice`) for each ticker in `tickerToExponent` and marks a ticker as unavailable if it's not present in `tickers` or its ticker's validation or calculation fails.

func GetOnlyTickerAndExponent

func GetOnlyTickerAndExponent(
	tickerToExponent map[string]int32,
	exchange string,
) (string, int32, error)

GetOnlyTickerAndExponent returns the only ticker and exponent in the provided `tickerToExponent` map. If the map contains more than one key, an error is returned.

func GetUint64MedianFromReverseShiftedBigFloatValues

func GetUint64MedianFromReverseShiftedBigFloatValues(
	bigFloatSlice []*big.Float,
	exponent int32,
	resolver func([]uint64) (uint64, error),
) (uint64, error)

GetUint64MedianFromReverseShiftedBigFloatValues shifts all values in a slice of floats by an exponent, converts the shifted slice values to uint64 and then returns the median of the slice. 1) Verify length of slice is > 0. 2) Reverse shift big float price values by the exponent for the market. 3) Convert big float values to uint64 values. 4) Get the median value from the uint64 price values and return.

func IsGenericExchangeError

func IsGenericExchangeError(err error) bool

IsGenericExchangeError returns true if the error message has been positively identified as being due to an exchange side error. These errors could occur on any exchange.

Types

type ExchangeError

type ExchangeError interface {
	error
	GetExchangeId() types.ExchangeId
}

ExchangeError describes an error that is specific to a particular exchange. These errors are emitted by an exchange's price function whenever the exchange's API returns a valid http response.

func NewExchangeError

func NewExchangeError(exchangeId types.ExchangeId, msg string) ExchangeError

NewExchangeError returns a new ExchangeError.

type ExchangeErrorImpl

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

ExchangeErrorImpl implements ExchangeError.

func (*ExchangeErrorImpl) Error

func (e *ExchangeErrorImpl) Error() string

Error returns a string representation of the error.

func (*ExchangeErrorImpl) GetExchangeId

func (e *ExchangeErrorImpl) GetExchangeId() types.ExchangeId

GetExchangeId returns the exchange id associated with the error.

type Ticker

type Ticker interface {
	GetPair() string
	GetAskPrice() string
	GetBidPrice() string
	GetLastPrice() string
}

Ticker encodes a ticker response returned by an exchange API. It contains accessors for the ticker's ask price, bid price, and last price, which are medianized to compute an exchange price.

Jump to

Keyboard shortcuts

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