trade

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromRoute

func FromRoute(route *Route) *fractions.Price

FromRoute creates a price from an incoming route

func InputOutputComparator

func InputOutputComparator(a, b *InputOutput) int

InputOutputComparator is used to compare the two inuts and outputs

Types

type BestTradeOptions

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

BestTradeOptions can define how complex the trade calculation should be

type InputOutput

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

InputOutput the input and output amount for the trade

type Pair

type Pair struct {
	LiquidityToken entities.Token        `json:"liquidityToken,omitempty"`
	TokenAmount0   fractions.TokenAmount `json:"tokenAmount0,omitempty"`
	TokenAmount1   fractions.TokenAmount `json:"tokenAmount1,omitempty"`
}

Pair the token pair used for exchange

func NewPair

func NewPair(tokenAmount0, tokenAmount1 *fractions.TokenAmount, pairAddress string) *Pair

NewPair the main constructor for Pairs

func (*Pair) ChainID

func (p *Pair) ChainID() int

ChainID get the chainID of the pair

func (*Pair) GetInputAmount

func (p *Pair) GetInputAmount(outputAmount *fractions.TokenAmount) (*fractions.TokenAmount, Pair)

GetInputAmount get the input amount token in exchange for the output token

Example: BNB-BTT pair GetInputAmount(2 BNB) should check the current price of the BNB-BTT pair And return the exchangable amount of BTT as result

func (*Pair) GetLiquidityMinted

func (p *Pair) GetLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB *fractions.TokenAmount) fractions.TokenAmount

GetLiquidityMinted get the minted LiquidityToken amount depending on the input amounts

func (*Pair) GetLiquidityValue

func (p *Pair) GetLiquidityValue(token *entities.Token, totalSupply, liquidity *fractions.TokenAmount, feeOn bool, last *big.Int) fractions.TokenAmount

GetLiquidityValue returns the actual value of the LiquidityToken

func (*Pair) GetOutputAmount

func (p *Pair) GetOutputAmount(inputAmount *fractions.TokenAmount) (*fractions.TokenAmount, Pair)

GetOutputAmount get the output amount token in exchange for the input token

Example: BNB-BTT pair GetOutputAmount(2 BNB) should check the current price of the BNB-BTT pair And return the exchangable amount of BTT as result

func (*Pair) InvolvesToken

func (p *Pair) InvolvesToken(token *entities.Token) bool

InvolvesToken check wether the input token is part of the pair

func (*Pair) PriceOf

func (p *Pair) PriceOf(token *entities.Token) fractions.Price

PriceOf the the current price of the input token

func (*Pair) Reserve0

func (p *Pair) Reserve0() *fractions.TokenAmount

Reserve0 get the reserve amount of the first token

func (*Pair) Reserve1

func (p *Pair) Reserve1() *fractions.TokenAmount

Reserve1 get the reserve amount of the second token

func (*Pair) ReserveOf

func (p *Pair) ReserveOf(token *entities.Token) *fractions.TokenAmount

ReserveOf get the reserve of the input token

func (*Pair) Token0

func (p *Pair) Token0() *entities.Token

Token0 the first of the token pair

func (*Pair) Token0Price

func (p *Pair) Token0Price() *fractions.Price

Token0Price the price of the first token

func (*Pair) Token1

func (p *Pair) Token1() *entities.Token

Token1 the second of the token pair

func (*Pair) Token1Price

func (p *Pair) Token1Price() *fractions.Price

Token1Price the price of the second token

type Route

type Route struct {
	Pairs         []Pair
	Path          []*entities.Token
	Input, Output entities.Token
	// contains filtered or unexported fields
}

Route defines which exchange route to take when trading

func NewRoute

func NewRoute(pairs []Pair, input, output entities.Token) *Route

NewRoute is the main constructor for routes

func (*Route) ChainID

func (r *Route) ChainID() int

ChainID get the chainID used by the route

func (*Route) MidPrice

func (r *Route) MidPrice() fractions.Price

MidPrice get the middle price for the given route

type Trade

type Trade struct {
	Route
	TradeType                    constants.TradeType
	InputAmount, OutputAmount    *fractions.CurrencyAmount
	ExecutionPrice, NextMidPrice *fractions.Price
	PriceImpact                  *fractions.Percent
}

Trade is used for exchange trade deinitions

func BestTradeExactIn

func BestTradeExactIn(
	pairs []Pair,
	currencyAmountIn *fractions.TokenAmount,
	currencyOut entities.Token,
	bestTradeOptions BestTradeOptions,
	currentPairs []Pair,
	originalAmountIn *fractions.TokenAmount,
	bestTrades []Trade,
) []Trade

BestTradeExactIn gets the best trade for the given pairs, when the exact input amount is set

func ExactIn

func ExactIn(route *Route, amountIn *fractions.TokenAmount) *Trade

ExactIn calculates a trade for an exact input amount

func ExactOut

func ExactOut(route *Route, amountOut *fractions.TokenAmount) *Trade

ExactOut calculates a trade for an exact output amount

func NewTrade

func NewTrade(route *Route, amount *fractions.TokenAmount, tradeType constants.TradeType) *Trade

NewTrade is used to construct a trade from route and tokenamount

func (*Trade) MinimumAmountIn

func (t *Trade) MinimumAmountIn(slippageTolerance *fractions.Percent) fractions.CurrencyAmount

MinimumAmountIn defines what is the minimum amount wanted by exact input

func (*Trade) MinimumAmountOut

func (t *Trade) MinimumAmountOut(slippageTolerance *fractions.Percent) fractions.CurrencyAmount

MinimumAmountOut defined what is the minimum amount wantd for the trade

Jump to

Keyboard shortcuts

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