lib

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PriceCmp

func PriceCmp(a, b Price) int

PriceCmp implements a standard comparator function for the Price type.

func PriceCmpUnsafe

func PriceCmpUnsafe(a, b Price) int

PriceCmpUnsafe implements a standard comparator function for the Price type.

NOTE: unsafe from under/overflows. Ensure the inputs are valid Price [MinPrice, MaxPrice].

Types

type FeedOption

type FeedOption int

FeedOption is an enum for the different types of price feeds that can be queried.

const (
	Feed_ZERO       FeedOption = iota // 0 => no price feed to query
	Feed_SINGULAR                     // 1 => only 1 price feed to query for the final price
	Feed_TRIANGULAR                   // 2 => use triangular arbitrage to get price from target

)

type Price

type Price int64

Prices are represented by int64s.

const (
	MinPrice Price = 0
	MaxPrice Price = math.MaxInt64
)

The min/max possible price of an order.

func CalculateTriangularConf

func CalculateTriangularConf(
	baseP, quoteP, baseC, quoteC Price, desiredPrecision int,
) Price

Returns the confidence of baseP/quoteP in the desired precision. Assumes baseP/quoteP are in the same precision. Logic taken from Pyth Rust SDK. (https://github.com/pyth-network/pyth-sdk-rs/blob/main/pyth-sdk/src/price.rs#L424)

func CalculateTriangularPrice

func CalculateTriangularPrice(baseP, quoteP Price, desiredPrecision int) Price

Returns baseP/quoteP in the desired precision. Assumes baseP/quoteP are in the same precision.

func NormalizeToPrecision

func NormalizeToPrecision(i int64, decimals, precision int) Price

NormalizeToPrecision normalizes a int64 of decimals to a int64 with the desired precision.

type PriceUpdate

type PriceUpdate struct {
	PairIndex      uint64
	Price          Price
	Conf           Price
	TimeStamp      uint64
	PythUpdateData [][]byte
	PythUpdateFee  *big.Int
}

PriceUpdate represents a price update received by the oracle.

func GetPriceUpdateFromPythResult

func GetPriceUpdateFromPythResult(
	lpd *types.LatestPriceData, pairIndex uint64, useEma bool, desiredPrecision int,
) *PriceUpdate

Builds a PriceUpdate for a Pyth oracle result.

NOTE: does not set the PythUpdateFee or the FeedType.

func GetPriceUpdateFromPythStructsPriceFeed

func GetPriceUpdateFromPythStructsPriceFeed(
	pf *apyth.PythStructsPriceFeed, pairIndex uint64, useEma bool, desiredPrecision int,
) *PriceUpdate

Builds a PriceUpdate for a Pyth price feed struct.

NOTE: does not set the PythUpdateFee or the FeedType.

type PriceUpdates

type PriceUpdates map[uint64]*PriceUpdate

PriceUpdates is a map of price updates, keyed by pair index.

Jump to

Keyboard shortcuts

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