Documentation ¶
Index ¶
- Variables
- func Deposit(rx, ry, ps, x, y sdk.Int) (ax, ay, pc sdk.Int)
- func DeriveTranslation(rx, ry sdk.Int, minPrice, maxPrice sdk.Dec) (transX, transY sdk.Dec)
- func DistributeOrderAmountToOrders(orders []Order, amt sdk.Int, price sdk.Dec) (quoteCoinDiff sdk.Int)
- func DistributeOrderAmountToTick(tick *orderBookTick, amt sdk.Int, price sdk.Dec) (quoteCoinDiff sdk.Int)
- func DownTick(price sdk.Dec, prec int) sdk.Dec
- func FillOrder(order Order, amt sdk.Int, price sdk.Dec) (quoteCoinDiff sdk.Int)
- func FindMatchPrice(ov OrderView, tickPrec int) (matchPrice sdk.Dec, found bool)
- func FulfillOrder(order Order, price sdk.Dec) (quoteCoinDiff sdk.Int)
- func FulfillOrders(orders []Order, price sdk.Dec) (quoteCoinDiff sdk.Int)
- func HighestTick(prec int) sdk.Dec
- func InitialPoolCoinSupply(x, y sdk.Int) sdk.Int
- func LowestTick(prec int) sdk.Dec
- func MatchableAmount(order Order, price sdk.Dec) (matchableAmt sdk.Int)
- func OfferCoinAmount(dir OrderDirection, price sdk.Dec, amt sdk.Int) sdk.Int
- func PriceToDownTick(price sdk.Dec, prec int) sdk.Dec
- func PriceToUpTick(price sdk.Dec, prec int) sdk.Dec
- func RandomTick(r *rand.Rand, minPrice, maxPrice sdk.Dec, prec int) sdk.Dec
- func RoundPrice(price sdk.Dec, prec int) sdk.Dec
- func RoundTickIndex(i int) int
- func SortOrders(orders []Order)
- func TickFromIndex(i, prec int) sdk.Dec
- func TickGap(price sdk.Dec, prec int) sdk.Dec
- func TickToIndex(price sdk.Dec, prec int) int
- func TotalAmount(orders []Order) sdk.Int
- func TotalMatchableAmount(orders []Order, price sdk.Dec) (amt sdk.Int)
- func UpTick(price sdk.Dec, prec int) sdk.Dec
- func ValidateRangedPoolParams(minPrice, maxPrice, initialPrice sdk.Dec) error
- func Withdraw(rx, ry, ps, pc sdk.Int, feeRate sdk.Dec) (x, y sdk.Int)
- type BaseOrder
- func (order *BaseOrder) GetAmount() sdk.Int
- func (order *BaseOrder) GetBatchId() uint64
- func (order *BaseOrder) GetDirection() OrderDirection
- func (order *BaseOrder) GetOfferCoinAmount() sdk.Int
- func (order *BaseOrder) GetOpenAmount() sdk.Int
- func (order *BaseOrder) GetPaidOfferCoinAmount() sdk.Int
- func (order *BaseOrder) GetPrice() sdk.Dec
- func (order *BaseOrder) GetReceivedDemandCoinAmount() sdk.Int
- func (order *BaseOrder) HasPriority(other Order) bool
- func (order *BaseOrder) IsMatched() bool
- func (order *BaseOrder) SetOpenAmount(amt sdk.Int)
- func (order *BaseOrder) SetPaidOfferCoinAmount(amt sdk.Int)
- func (order *BaseOrder) SetReceivedDemandCoinAmount(amt sdk.Int)
- func (order *BaseOrder) String() string
- type BaseOrderer
- type BasicPool
- func (pool *BasicPool) Balances() (rx, ry sdk.Int)
- func (pool *BasicPool) BuyAmountOver(price sdk.Dec, _ bool) (amt sdk.Int)
- func (pool *BasicPool) BuyAmountTo(price sdk.Dec) (amt sdk.Int)
- func (pool *BasicPool) Clone() Pool
- func (pool *BasicPool) HighestBuyPrice() (price sdk.Dec, found bool)
- func (pool *BasicPool) IsDepleted() bool
- func (pool *BasicPool) LowestSellPrice() (price sdk.Dec, found bool)
- func (pool *BasicPool) PoolCoinSupply() sdk.Int
- func (pool *BasicPool) Price() sdk.Dec
- func (pool *BasicPool) SellAmountTo(price sdk.Dec) (amt sdk.Int)
- func (pool *BasicPool) SellAmountUnder(price sdk.Dec, _ bool) (amt sdk.Int)
- func (pool *BasicPool) SetBalances(rx, ry sdk.Int, _ bool)
- type MultipleOrderViews
- func (views MultipleOrderViews) BuyAmountOver(price sdk.Dec, inclusive bool) sdk.Int
- func (views MultipleOrderViews) HighestBuyPrice() (price sdk.Dec, found bool)
- func (views MultipleOrderViews) LowestSellPrice() (price sdk.Dec, found bool)
- func (views MultipleOrderViews) SellAmountUnder(price sdk.Dec, inclusive bool) sdk.Int
- type Order
- func PoolBuyOrders(pool Pool, orderer Orderer, lowestPrice, highestPrice sdk.Dec, tickPrec int) (orders []Order)
- func PoolOrders(pool Pool, orderer Orderer, lowestPrice, highestPrice sdk.Dec, tickPrec int) []Order
- func PoolSellOrders(pool Pool, orderer Orderer, lowestPrice, highestPrice sdk.Dec, tickPrec int) (orders []Order)
- type OrderBook
- func (ob *OrderBook) AddOrder(orders ...Order)
- func (ob *OrderBook) BuyOrdersAt(price sdk.Dec) []Order
- func (ob *OrderBook) FindMatchableAmountAtSinglePrice(matchPrice sdk.Dec) (matchableAmt sdk.Int, found bool)
- func (ob *OrderBook) FullString(tickPrec int) string
- func (ob *OrderBook) HighestPrice() (sdk.Dec, bool)
- func (ob *OrderBook) LowestPrice() (sdk.Dec, bool)
- func (ob *OrderBook) MakeView() *OrderBookView
- func (ob *OrderBook) Match(lastPrice sdk.Dec) (matchPrice sdk.Dec, quoteCoinDiff sdk.Int, matched bool)
- func (ob *OrderBook) MatchAtSinglePrice(matchPrice sdk.Dec) (quoteCoinDiff sdk.Int, matched bool)
- func (ob *OrderBook) Orders() []Order
- func (ob *OrderBook) PriceDirection(lastPrice sdk.Dec) PriceDirection
- func (ob *OrderBook) SellOrdersAt(price sdk.Dec) []Order
- func (ob *OrderBook) String() string
- type OrderBookView
- func (view *OrderBookView) BuyAmountOver(price sdk.Dec, inclusive bool) sdk.Int
- func (view *OrderBookView) BuyAmountUnder(price sdk.Dec, inclusive bool) sdk.Int
- func (view *OrderBookView) HighestBuyPrice() (sdk.Dec, bool)
- func (view *OrderBookView) LowestSellPrice() (sdk.Dec, bool)
- func (view *OrderBookView) Match()
- func (view *OrderBookView) SellAmountOver(price sdk.Dec, inclusive bool) sdk.Int
- func (view *OrderBookView) SellAmountUnder(price sdk.Dec, inclusive bool) sdk.Int
- type OrderDirection
- type OrderGroup
- type OrderView
- type Orderer
- type Pool
- type PriceDirection
- type RangedPool
- func (pool *RangedPool) Balances() (rx, ry sdk.Int)
- func (pool *RangedPool) BuyAmountOver(price sdk.Dec, _ bool) (amt sdk.Int)
- func (pool *RangedPool) BuyAmountTo(price sdk.Dec) (amt sdk.Int)
- func (pool *RangedPool) Clone() Pool
- func (pool *RangedPool) HighestBuyPrice() (price sdk.Dec, found bool)
- func (pool *RangedPool) IsDepleted() bool
- func (pool *RangedPool) LowestSellPrice() (price sdk.Dec, found bool)
- func (pool *RangedPool) MaxPrice() sdk.Dec
- func (pool *RangedPool) MinPrice() sdk.Dec
- func (pool *RangedPool) PoolCoinSupply() sdk.Int
- func (pool *RangedPool) Price() sdk.Dec
- func (pool *RangedPool) SellAmountTo(price sdk.Dec) (amt sdk.Int)
- func (pool *RangedPool) SellAmountUnder(price sdk.Dec, _ bool) (amt sdk.Int)
- func (pool *RangedPool) SetBalances(rx, ry sdk.Int, derive bool)
- func (pool *RangedPool) Translation() (transX, transY sdk.Dec)
- type TickPrecision
- func (prec TickPrecision) DownTick(price sdk.Dec) sdk.Dec
- func (prec TickPrecision) HighestTick() sdk.Dec
- func (prec TickPrecision) LowestTick() sdk.Dec
- func (prec TickPrecision) PriceToDownTick(price sdk.Dec) sdk.Dec
- func (prec TickPrecision) PriceToUpTick(price sdk.Dec) sdk.Dec
- func (prec TickPrecision) RandomTick(r *rand.Rand, minPrice, maxPrice sdk.Dec) sdk.Dec
- func (prec TickPrecision) RoundPrice(price sdk.Dec) sdk.Dec
- func (prec TickPrecision) TickFromIndex(i int) sdk.Dec
- func (prec TickPrecision) TickGap(price sdk.Dec) sdk.Dec
- func (prec TickPrecision) TickToIndex(tick sdk.Dec) int
- func (prec TickPrecision) UpTick(price sdk.Dec) sdk.Dec
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( MinCoinAmount = sdk.NewInt(100) MaxCoinAmount = sdk.NewIntWithDecimal(1, 40) )
The minimum and maximum coin amount used in the amm package.
var ( MinPoolPrice = sdk.NewDecWithPrec(1, 15) // 10^-15 MaxPoolPrice = sdk.NewIntWithDecimal(1, 20).ToDec() // 10^20 MinRangedPoolPriceGapRatio = sdk.NewDecWithPrec(1, 3) // 0.001, 0.1% )
var (
DefaultOrderer = BaseOrderer{}
)
Functions ¶
func Deposit ¶
Deposit returns accepted x and y coin amount and minted pool coin amount when someone deposits x and y coins.
func DeriveTranslation ¶
func DistributeOrderAmountToOrders ¶
func DistributeOrderAmountToOrders(orders []Order, amt sdk.Int, price sdk.Dec) (quoteCoinDiff sdk.Int)
DistributeOrderAmountToOrders distributes the given order amount to the orders proportional to each order's amount. The caller must sort orders before calling DistributeOrderAmountToOrders. After distributing the amount based on each order's proportion, remaining amount due to the decimal truncation is distributed to the orders again, by priority. This time, the proportion is not considered and each order takes up the amount as much as possible.
func DistributeOrderAmountToTick ¶
func DistributeOrderAmountToTick(tick *orderBookTick, amt sdk.Int, price sdk.Dec) (quoteCoinDiff sdk.Int)
DistributeOrderAmountToTick distributes the given order amount to the orders at the tick. Orders with higher priority(have lower batch id) get matched first, then the remaining amount is distributed to the remaining orders.
func DownTick ¶
DownTick returns the next highest price tick under the price. DownTick doesn't check if the price is the lowest price tick.
func FindMatchPrice ¶
func FulfillOrder ¶
FulfillOrder fills the order by its remaining open amount at given price.
func FulfillOrders ¶
FulfillOrders fills multiple orders by their remaining open amount at given price.
func HighestTick ¶
HighestTick returns the highest possible price tick.
func InitialPoolCoinSupply ¶
InitialPoolCoinSupply returns ideal initial pool coin minting amount.
func LowestTick ¶
LowestTick returns the lowest possible price tick.
func MatchableAmount ¶
MatchableAmount returns matchable amount of an order considering remaining offer coin and price.
func OfferCoinAmount ¶
OfferCoinAmount returns the minimum offer coin amount for given order direction, price and order amount.
func PriceToDownTick ¶
PriceToDownTick returns the highest price tick under(or equal to) the price.
func PriceToUpTick ¶
PriceToUpTick returns the lowest price tick greater or equal than the price.
func RandomTick ¶
RandomTick returns a random tick within range [minPrice, maxPrice]. If prices are not on ticks, then prices are adjusted to the nearest ticks.
func RoundPrice ¶
RoundPrice returns rounded price using banker's rounding.
func RoundTickIndex ¶
RoundTickIndex returns rounded tick index using banker's rounding.
func SortOrders ¶
func SortOrders(orders []Order)
SortOrders sorts orders using its HasPriority condition.
func TickFromIndex ¶
TickFromIndex returns a price for given tick index. See TickToIndex for more details about tick indices.
func TickToIndex ¶
TickToIndex returns a tick index for given price. Tick index 0 means the lowest possible price fit in ticks.
func TotalAmount ¶
TotalAmount returns total amount of orders.
func TotalMatchableAmount ¶
TotalMatchableAmount returns total matchable amount of orders.
Types ¶
type BaseOrder ¶
type BaseOrder struct { Direction OrderDirection Price sdk.Dec Amount sdk.Int OfferCoinAmount sdk.Int // Match info OpenAmount sdk.Int PaidOfferCoinAmount sdk.Int ReceivedDemandCoinAmount sdk.Int }
BaseOrder is the base struct for an Order.
func NewBaseOrder ¶
NewBaseOrder returns a new BaseOrder.
func (*BaseOrder) GetBatchId ¶
func (*BaseOrder) GetDirection ¶
func (order *BaseOrder) GetDirection() OrderDirection
GetDirection returns the order direction.
func (*BaseOrder) GetOfferCoinAmount ¶
func (*BaseOrder) GetOpenAmount ¶
func (*BaseOrder) GetPaidOfferCoinAmount ¶
func (*BaseOrder) GetReceivedDemandCoinAmount ¶
func (*BaseOrder) HasPriority ¶
HasPriority returns whether the order has higher priority than the other order.
func (*BaseOrder) SetOpenAmount ¶
func (*BaseOrder) SetPaidOfferCoinAmount ¶
func (*BaseOrder) SetReceivedDemandCoinAmount ¶
type BaseOrderer ¶
type BaseOrderer struct{}
BaseOrderer creates new BaseOrder with sufficient offer coin amount considering price and amount.
func (BaseOrderer) Order ¶
func (orderer BaseOrderer) Order(dir OrderDirection, price sdk.Dec, amt sdk.Int) Order
type BasicPool ¶
type BasicPool struct {
// contains filtered or unexported fields
}
BasicPool is the basic pool type.
func NewBasicPool ¶
NewBasicPool returns a new BasicPool. It is OK to pass an empty sdk.Int to ps when ps is not going to be used.
func (*BasicPool) BuyAmountOver ¶
BuyAmountOver returns the amount of buy orders for price greater than or equal to given price. amt = (X - P*Y)/P
func (*BasicPool) BuyAmountTo ¶
BuyAmountTo returns the amount of buy orders of the pool for price, where BuyAmountTo is used when the pool price is higher than the highest price of the order book.
func (*BasicPool) HighestBuyPrice ¶
HighestBuyPrice returns the highest buy price of the pool.
func (*BasicPool) IsDepleted ¶
IsDepleted returns whether the pool is depleted or not.
func (*BasicPool) LowestSellPrice ¶
LowestSellPrice returns the lowest sell price of the pool.
func (*BasicPool) PoolCoinSupply ¶
PoolCoinSupply returns the pool coin supply.
func (*BasicPool) SellAmountTo ¶
SellAmountTo returns the amount of sell orders of the pool for price, where SellAmountTo is used when the pool price is lower than the lowest price of the order book.
func (*BasicPool) SellAmountUnder ¶
type MultipleOrderViews ¶
type MultipleOrderViews []OrderView
func (MultipleOrderViews) BuyAmountOver ¶
func (MultipleOrderViews) HighestBuyPrice ¶
func (views MultipleOrderViews) HighestBuyPrice() (price sdk.Dec, found bool)
func (MultipleOrderViews) LowestSellPrice ¶
func (views MultipleOrderViews) LowestSellPrice() (price sdk.Dec, found bool)
func (MultipleOrderViews) SellAmountUnder ¶
type Order ¶
type Order interface { GetDirection() OrderDirection // GetBatchId returns the batch id where the order was created. // Batch id of 0 means the current batch. GetBatchId() uint64 GetPrice() sdk.Dec GetAmount() sdk.Int // The original order amount GetOfferCoinAmount() sdk.Int GetPaidOfferCoinAmount() sdk.Int SetPaidOfferCoinAmount(amt sdk.Int) GetReceivedDemandCoinAmount() sdk.Int SetReceivedDemandCoinAmount(amt sdk.Int) GetOpenAmount() sdk.Int SetOpenAmount(amt sdk.Int) IsMatched() bool // HasPriority returns true if the order has higher priority // than the other order. HasPriority(other Order) bool String() string }
Order is the universal interface of an order.
func PoolBuyOrders ¶
func PoolOrders ¶
type OrderBook ¶
type OrderBook struct {
// contains filtered or unexported fields
}
OrderBook is an order book.
func NewOrderBook ¶
NewOrderBook returns a new OrderBook.
func (*OrderBook) BuyOrdersAt ¶
BuyOrdersAt returns buy orders at given price in the order book. Note that the orders are not sorted.
func (*OrderBook) FindMatchableAmountAtSinglePrice ¶
func (ob *OrderBook) FindMatchableAmountAtSinglePrice(matchPrice sdk.Dec) (matchableAmt sdk.Int, found bool)
FindMatchableAmountAtSinglePrice returns the largest matchable amount of orders when matching orders at single price(batch auction).
func (*OrderBook) FullString ¶
FullString returns a full string representation of the order book. FullString includes all possible price ticks from the order book's highest price to the lowest price.
Example ¶
ob := amm.NewOrderBook( newOrder(amm.Sell, utils.ParseDec("1.2"), sdk.NewInt(10000)), newOrder(amm.Buy, utils.ParseDec("1.17"), sdk.NewInt(10000)), newOrder(amm.Sell, utils.ParseDec("1.15"), sdk.NewInt(5000)), newOrder(amm.Sell, utils.ParseDec("1.1"), sdk.NewInt(3000)), newOrder(amm.Buy, utils.ParseDec("1.1"), sdk.NewInt(5000)), newOrder(amm.Buy, utils.ParseDec("1.1"), sdk.NewInt(1000)), newOrder(amm.Sell, utils.ParseDec("1.09"), sdk.NewInt(6000)), newOrder(amm.Sell, utils.ParseDec("1.09"), sdk.NewInt(4000)), newOrder(amm.Buy, utils.ParseDec("1.06"), sdk.NewInt(15000)), ) fmt.Println(ob.FullString(2))
Output: +--------sell--------+------------price-------------+--------buy---------+ | 10000 | 1.200000000000000000 | 0 | | 0 | 1.190000000000000000 | 0 | | 0 | 1.180000000000000000 | 0 | | 0 | 1.170000000000000000 | 10000 | | 0 | 1.160000000000000000 | 0 | | 5000 | 1.150000000000000000 | 0 | | 0 | 1.140000000000000000 | 0 | | 0 | 1.130000000000000000 | 0 | | 0 | 1.120000000000000000 | 0 | | 0 | 1.110000000000000000 | 0 | | 3000 | 1.100000000000000000 | 6000 | | 10000 | 1.090000000000000000 | 0 | | 0 | 1.080000000000000000 | 0 | | 0 | 1.070000000000000000 | 0 | | 0 | 1.060000000000000000 | 15000 | +--------------------+------------------------------+--------------------+
func (*OrderBook) MakeView ¶
func (ob *OrderBook) MakeView() *OrderBookView
func (*OrderBook) Match ¶
func (ob *OrderBook) Match(lastPrice sdk.Dec) (matchPrice sdk.Dec, quoteCoinDiff sdk.Int, matched bool)
Match matches orders sequentially, starting from buy orders with the highest price and sell orders with the lowest price. The matching continues until there's no more matchable orders.
func (*OrderBook) MatchAtSinglePrice ¶
MatchAtSinglePrice matches all matchable orders(buy orders with higher(or equal) price than the price and sell orders with lower(or equal) price than the price) at the price.
func (*OrderBook) PriceDirection ¶
func (ob *OrderBook) PriceDirection(lastPrice sdk.Dec) PriceDirection
PriceDirection returns the estimated price direction within this batch considering the last price.
func (*OrderBook) SellOrdersAt ¶
SellOrdersAt returns sell orders at given price in the order book. Note that the orders are not sorted.
func (*OrderBook) String ¶
String returns a compact string representation of the order book. String includes a tick only when there is at least one order on it.
Example ¶
ob := amm.NewOrderBook( newOrder(amm.Sell, utils.ParseDec("1.2"), sdk.NewInt(10000)), newOrder(amm.Buy, utils.ParseDec("1.17"), sdk.NewInt(10000)), newOrder(amm.Sell, utils.ParseDec("1.15"), sdk.NewInt(5000)), newOrder(amm.Sell, utils.ParseDec("1.1"), sdk.NewInt(3000)), newOrder(amm.Buy, utils.ParseDec("1.1"), sdk.NewInt(5000)), newOrder(amm.Buy, utils.ParseDec("1.1"), sdk.NewInt(1000)), newOrder(amm.Sell, utils.ParseDec("1.09"), sdk.NewInt(6000)), newOrder(amm.Sell, utils.ParseDec("1.09"), sdk.NewInt(4000)), newOrder(amm.Buy, utils.ParseDec("1.06"), sdk.NewInt(15000)), ) fmt.Println(ob.String())
Output: +--------sell--------+------------price-------------+--------buy---------+ | 10000 | 1.200000000000000000 | 0 | | 0 | 1.170000000000000000 | 10000 | | 5000 | 1.150000000000000000 | 0 | | 3000 | 1.100000000000000000 | 6000 | | 10000 | 1.090000000000000000 | 0 | | 0 | 1.060000000000000000 | 15000 | +--------------------+------------------------------+--------------------+
type OrderBookView ¶
type OrderBookView struct {
// contains filtered or unexported fields
}
func (*OrderBookView) BuyAmountOver ¶
func (*OrderBookView) BuyAmountUnder ¶ added in v2.1.0
func (*OrderBookView) HighestBuyPrice ¶
func (view *OrderBookView) HighestBuyPrice() (sdk.Dec, bool)
func (*OrderBookView) LowestSellPrice ¶
func (view *OrderBookView) LowestSellPrice() (sdk.Dec, bool)
func (*OrderBookView) Match ¶
func (view *OrderBookView) Match()
func (*OrderBookView) SellAmountOver ¶ added in v2.1.0
func (*OrderBookView) SellAmountUnder ¶
type OrderDirection ¶
type OrderDirection int
OrderDirection specifies an order direction, either buy or sell.
const ( Buy OrderDirection = iota + 1 Sell )
OrderDirection enumerations.
func (OrderDirection) String ¶
func (dir OrderDirection) String() string
type OrderGroup ¶
OrderGroup represents a group of orders with same batch id.
func GroupOrdersByBatchId ¶
func GroupOrdersByBatchId(orders []Order) (groups []*OrderGroup)
GroupOrdersByBatchId groups orders by their batch id and returns a slice of OrderGroup.
type Pool ¶
type Pool interface { Balances() (rx, ry sdk.Int) SetBalances(rx, ry sdk.Int, derive bool) PoolCoinSupply() sdk.Int Price() sdk.Dec IsDepleted() bool HighestBuyPrice() (sdk.Dec, bool) LowestSellPrice() (sdk.Dec, bool) BuyAmountOver(price sdk.Dec, inclusive bool) sdk.Int SellAmountUnder(price sdk.Dec, inclusive bool) sdk.Int BuyAmountTo(price sdk.Dec) sdk.Int SellAmountTo(price sdk.Dec) sdk.Int Clone() Pool }
Pool is the interface of a pool.
type PriceDirection ¶
type PriceDirection int
PriceDirection specifies estimated price direction within this batch.
const ( PriceStaying PriceDirection = iota + 1 PriceIncreasing PriceDecreasing )
func (PriceDirection) String ¶
func (dir PriceDirection) String() string
type RangedPool ¶
type RangedPool struct {
// contains filtered or unexported fields
}
func CreateRangedPool ¶
func CreateRangedPool(x, y sdk.Int, minPrice, maxPrice, initialPrice sdk.Dec) (pool *RangedPool, err error)
CreateRangedPool creates new RangedPool from given inputs, while validating the inputs and using only needed amount of x/y coins(the rest should be refunded).
func NewRangedPool ¶
func NewRangedPool(rx, ry, ps sdk.Int, minPrice, maxPrice sdk.Dec) *RangedPool
NewRangedPool returns a new RangedPool.
func (*RangedPool) Balances ¶
func (pool *RangedPool) Balances() (rx, ry sdk.Int)
Balances returns the balances of the pool.
func (*RangedPool) BuyAmountOver ¶
BuyAmountOver returns the amount of buy orders for price greater than or equal to given price.
func (*RangedPool) BuyAmountTo ¶
func (pool *RangedPool) BuyAmountTo(price sdk.Dec) (amt sdk.Int)
BuyAmountTo returns the amount of buy orders of the pool for price, where BuyAmountTo is used when the pool price is higher than the highest price of the order book.
func (*RangedPool) Clone ¶
func (pool *RangedPool) Clone() Pool
func (*RangedPool) HighestBuyPrice ¶
func (pool *RangedPool) HighestBuyPrice() (price sdk.Dec, found bool)
HighestBuyPrice returns the highest buy price of the pool.
func (*RangedPool) IsDepleted ¶
func (pool *RangedPool) IsDepleted() bool
IsDepleted returns whether the pool is depleted or not.
func (*RangedPool) LowestSellPrice ¶
func (pool *RangedPool) LowestSellPrice() (price sdk.Dec, found bool)
LowestSellPrice returns the lowest sell price of the pool.
func (*RangedPool) MaxPrice ¶
func (pool *RangedPool) MaxPrice() sdk.Dec
func (*RangedPool) MinPrice ¶
func (pool *RangedPool) MinPrice() sdk.Dec
func (*RangedPool) PoolCoinSupply ¶
func (pool *RangedPool) PoolCoinSupply() sdk.Int
PoolCoinSupply returns the pool coin supply.
func (*RangedPool) SellAmountTo ¶
func (pool *RangedPool) SellAmountTo(price sdk.Dec) (amt sdk.Int)
SellAmountTo returns the amount of sell orders of the pool for price, where SellAmountTo is used when the pool price is lower than the lowest price of the order book.
func (*RangedPool) SellAmountUnder ¶
SellAmountUnder returns the amount of sell orders for price less than or equal to given price.
func (*RangedPool) SetBalances ¶
func (pool *RangedPool) SetBalances(rx, ry sdk.Int, derive bool)
SetBalances sets RangedPool's balances without recalculating transX and transY.
func (*RangedPool) Translation ¶
func (pool *RangedPool) Translation() (transX, transY sdk.Dec)
type TickPrecision ¶
type TickPrecision int
TickPrecision represents a tick precision.
func (TickPrecision) HighestTick ¶
func (prec TickPrecision) HighestTick() sdk.Dec
func (TickPrecision) LowestTick ¶
func (prec TickPrecision) LowestTick() sdk.Dec
func (TickPrecision) PriceToDownTick ¶
func (prec TickPrecision) PriceToDownTick(price sdk.Dec) sdk.Dec
func (TickPrecision) PriceToUpTick ¶
func (prec TickPrecision) PriceToUpTick(price sdk.Dec) sdk.Dec
func (TickPrecision) RandomTick ¶
func (TickPrecision) RoundPrice ¶
func (prec TickPrecision) RoundPrice(price sdk.Dec) sdk.Dec
func (TickPrecision) TickFromIndex ¶
func (prec TickPrecision) TickFromIndex(i int) sdk.Dec
func (TickPrecision) TickToIndex ¶
func (prec TickPrecision) TickToIndex(tick sdk.Dec) int