match

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2020 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAmountOfFeeOutOfRange represent The fee charged is out of range
	ErrAmountOfFeeOutOfRange = errors.New("amount of fee is out of range")
)

Functions

func CalcReceivedAmount added in v1.1.0

func CalcReceivedAmount(orders []*common.Order) ([]*bc.AssetAmount, []*bc.AssetAmount)

CalcReceivedAmount return amount of assets received by each participant in the matching transaction and the price difference

func CalcRequestAmount

func CalcRequestAmount(fromAmount uint64, ratioNumerator, ratioDenominator int64) uint64

CalcRequestAmount is from amount * numerator / ratioDenominator

func IsMatched added in v1.1.0

func IsMatched(orders []*common.Order) bool

IsMatched check does the orders can be exchange

Types

type AllocatedAssets added in v1.1.0

type AllocatedAssets struct {
	Receives []*bc.AssetAmount
	Fees     []*bc.AssetAmount
}

AllocatedAssets represent reallocated assets after calculating fees

type DefaultFeeStrategy added in v1.1.0

type DefaultFeeStrategy struct{}

DefaultFeeStrategy represent the default fee charge strategy

func NewDefaultFeeStrategy added in v1.1.0

func NewDefaultFeeStrategy() *DefaultFeeStrategy

NewDefaultFeeStrategy return a new instance of DefaultFeeStrategy

func (*DefaultFeeStrategy) Allocate added in v1.1.0

func (d *DefaultFeeStrategy) Allocate(receiveAmounts, priceDiffs []*bc.AssetAmount) *AllocatedAssets

Allocate will allocate the price differential in matching transaction to the participants and the fee

func (*DefaultFeeStrategy) Validate added in v1.1.0

func (d *DefaultFeeStrategy) Validate(receiveAmounts []*bc.AssetAmount, feeAmounts map[bc.AssetID]uint64) error

Validate verify that the fee charged for a matching transaction is correct

type Engine

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

Engine is used to generate math transactions

func NewEngine

func NewEngine(orderBook *OrderBook, feeStrategy FeeStrategy, rewardProgram []byte) *Engine

NewEngine return a new Engine

func (*Engine) HasMatchedTx

func (e *Engine) HasMatchedTx(tradePairs ...*common.TradePair) bool

HasMatchedTx check does the input trade pair can generate a match deal

func (*Engine) NextMatchedTx

func (e *Engine) NextMatchedTx(tradePairs ...*common.TradePair) (*types.Tx, error)

NextMatchedTx return the next matchable transaction by the specified trade pairs the size of trade pairs at least 2, and the sequence of trade pairs can form a loop for example, [assetA -> assetB, assetB -> assetC, assetC -> assetA]

type FeeStrategy added in v1.1.0

type FeeStrategy interface {
	// Allocate will allocate the price differential in matching transaction to the participants and the fee
	// @param receiveAmounts the amount of assets that the participants in the matching transaction can received when no fee is considered
	// @param priceDiffs price differential of matching transaction
	// @return reallocated assets after calculating fees
	Allocate(receiveAmounts, priceDiffs []*bc.AssetAmount) *AllocatedAssets

	// Validate verify that the fee charged for a matching transaction is correct
	Validate(receiveAmounts []*bc.AssetAmount, feeAmounts map[bc.AssetID]uint64) error
}

FeeStrategy used to indicate how to charge a matching fee

type OrderBook added in v1.1.0

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

OrderBook is used to handle the mov orders in memory like stack

func NewOrderBook added in v1.1.0

func NewOrderBook(movStore database.MovStore, arrivalAddOrders, arrivalDelOrders []*common.Order) *OrderBook

NewOrderBook create a new OrderBook object

func (*OrderBook) AddOrder added in v1.1.0

func (o *OrderBook) AddOrder(order *common.Order)

AddOrder add the in memory temp order to order table, because temp order is what left for the partial trade order, so the price should be lowest.

func (*OrderBook) DelOrder added in v1.1.0

func (o *OrderBook) DelOrder(order *common.Order)

DelOrder mark the order has been deleted in order book

func (*OrderBook) PeekOrder added in v1.1.0

func (o *OrderBook) PeekOrder(tradePair *common.TradePair) *common.Order

PeekOrder return the next lowest order of given trade pair

func (*OrderBook) PeekOrders added in v1.1.0

func (o *OrderBook) PeekOrders(tradePairs []*common.TradePair) []*common.Order

PeekOrders return the next lowest orders by given array of trade pairs

func (*OrderBook) PopOrder added in v1.1.0

func (o *OrderBook) PopOrder(tradePair *common.TradePair)

PopOrder delete the next lowest order of given trade pair

func (*OrderBook) PopOrders added in v1.1.0

func (o *OrderBook) PopOrders(tradePairs []*common.TradePair) []*common.Order

PopOrders delete the next lowest orders by given trade pairs

Jump to

Keyboard shortcuts

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