price_function

package
v0.3.0-dev2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: AGPL-3.0 Imports: 8 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 ExtractFirstStringFromSliceField

func ExtractFirstStringFromSliceField(strToSliceMap map[string]interface{}, fieldName string) (string, error)

ExtractFirstStringFromSliceField takes a generic unmarshalled JSON object, interprets it as a slice of strings, and returns the first element.

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 GetInnerMapFromMap

func GetInnerMapFromMap(
	responseJson map[string]interface{},
	key string,
) (map[string]interface{}, error)

GetInnerMapFromMap returns JSON map that correspond to the specific key from a JSON map.

func GetMedianPricesFromTickers

func GetMedianPricesFromTickers[T Ticker](
	tickers []T,
	tickerToExponent map[string]int32,
	medianizer lib.Medianizer,
) (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 GetStringOrFloatValuesFromMap

func GetStringOrFloatValuesFromMap[V string | float64](
	responseJson map[string]interface{},
	keys []string,
) ([]V, error)

GetStringOrFloatValuesFromMap returns string or float64 values that correspond to the specified keys from a JSON map.

func GetUint64MedianFromReverseShiftedBigFloatValues

func GetUint64MedianFromReverseShiftedBigFloatValues(
	bigFloatSlice []*big.Float,
	exponent int32,
	medianizer lib.Medianizer,
) (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.

func ReverseShiftBigFloat

func ReverseShiftBigFloat(
	value *big.Float,
	exponent int32,
) *big.Float

ReverseShiftBigFloat shifts the given float by exponent in the reverse direction. If the exponent is 0, then do nothing (i.e. `123.456` -> `123.456`) If the exponent is positive, then shift to the right (i.e. exponent = 1, `123.456` -> `12.3456`) If the exponent is negative, then shift to the left (i.e. exponent = -1, `123.456` -> `1234.56`)

Types

type ExchangeError

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

func NewExchangeError

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

type ExchangeErrorImpl

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

func (*ExchangeErrorImpl) Error

func (e *ExchangeErrorImpl) Error() string

func (*ExchangeErrorImpl) GetExchangeId

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

type Ticker

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

Jump to

Keyboard shortcuts

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