Documentation ¶
Index ¶
- Variables
- func CalcReceivedAmount(orders []*common.Order) ([]*bc.AssetAmount, []*bc.AssetAmount)
- func CalcRequestAmount(fromAmount uint64, ratioNumerator, ratioDenominator int64) uint64
- func IsMatched(orders []*common.Order) bool
- type AllocatedAssets
- type DefaultFeeStrategy
- type Engine
- type FeeStrategy
- type OrderBook
- func (o *OrderBook) AddOrder(order *common.Order)
- func (o *OrderBook) DelOrder(order *common.Order)
- func (o *OrderBook) PeekOrder(tradePair *common.TradePair) *common.Order
- func (o *OrderBook) PeekOrders(tradePairs []*common.TradePair) []*common.Order
- func (o *OrderBook) PopOrder(tradePair *common.TradePair)
- func (o *OrderBook) PopOrders(tradePairs []*common.TradePair) []*common.Order
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidAmountOfFee represent The fee charged is invalid ErrInvalidAmountOfFee = errors.New("amount of fee is invalid") )
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 ¶
CalcRequestAmount is from amount * numerator / ratioDenominator
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, takerPos int) *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, priceDiffs []*bc.AssetAmount, feeAmounts map[bc.AssetID]uint64, blockHeight 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 (*Engine) HasMatchedTx ¶
HasMatchedTx check does the input trade pair can generate a match deal
func (*Engine) NextMatchedTx ¶
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 // @return reallocated assets after calculating fees Allocate(receiveAmounts, priceDiffs []*bc.AssetAmount, takerPos int) *AllocatedAssets // Validate verify that the fee charged for a matching transaction is correct Validate(receiveAmounts, priceDiffs []*bc.AssetAmount, feeAmounts map[bc.AssetID]uint64, blockHeight 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
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) PeekOrder ¶ added in v1.1.0
PeekOrder return the next lowest order of given trade pair
func (*OrderBook) PeekOrders ¶ added in v1.1.0
PeekOrders return the next lowest orders by given array of trade pairs