types

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Index

Constants

View Source
const (
	FeeTypeOrderNew     = "new"
	FeeTypeOrderCancel  = "cancel"
	FeeTypeOrderExpire  = "expire"
	FeeTypeOrderDeal    = "deal"
	FeeTypeOrderReceive = "receive"
	TestTokenPair       = common.TestToken + "_" + sdk.DefaultBondDenom
	BuyOrder            = "BUY"
	SellOrder           = "SELL"
)

nolint

View Source
const (
	CodeInvalidAddress                        uint32 = 63000
	CodeSizeIsInvalid                         uint32 = 63001
	CodeTokenPairNotExist                     uint32 = 63002
	CodeSendCoinsFailed                       uint32 = 63003
	CodeTradingPairIsDelisting                uint32 = 63004
	CodePriceOverAccuracy                     uint32 = 63005
	CodeQuantityOverAccuracy                  uint32 = 63006
	CodeMsgQuantityLessThan                   uint32 = 63007
	CodeOrderIsNotExist                       uint32 = 63008
	CodeCheckTokenPairUnderDexDelistFailed    uint32 = 63009
	CodeIsProductLocked                       uint32 = 63010
	CodeNoOrdersIsCanceled                    uint32 = 63011
	CodeOrderStatusIsNotOpen                  uint32 = 63012
	CodeOrderIsNotExistOrClosed               uint32 = 63013
	CodeUnknownOrderQueryType                 uint32 = 63014
	CodeOrderItemCountsBiggerThanLimit        uint32 = 63015
	CodeOrderItemCountsIsEmpty                uint32 = 63016
	CodeOrderItemProductCountsIsEmpty         uint32 = 63017
	CodeOrderItemProductSymbolError           uint32 = 63018
	CodeOrderItemProductSymbolIsEqual         uint32 = 63019
	CodeOrderItemSideIsNotBuyAndSell          uint32 = 63020
	CodeOrderItemPriceOrQuantityIsNotPositive uint32 = 63021
	CodeOrderIDsIsEmpty                       uint32 = 63022
	CodeCancelOrderBiggerThanLimit            uint32 = 63023
	CodeOrderIDsHasDuplicatedID               uint32 = 63024
	CodeUserInputOrderIDIsEmpty               uint32 = 63025
	CodeNotOrderOwner                         uint32 = 63026
	CodeProductIsEmpty                        uint32 = 63027
	CodeAllOrderFailedToExecute               uint32 = 63028
)

const uint32

View Source
const (
	// ModuleName is the name of the order module
	ModuleName        = "order"
	DefaultParamspace = ModuleName
	DefaultCodespace  = ModuleName

	// QuerierRoute is the querier route for the order module
	QuerierRoute = ModuleName

	// RouterKey is the msg router key for the order module
	RouterKey = ModuleName

	// QueryOrderDetail query endpoints supported by the governance Querier
	QueryOrderDetail = "detail"
	QueryDepthBook   = "depthbook"
	QueryParameters  = "params"
	QueryStore       = "store"
	QueryDepthBookV2 = "depthbookV2"

	OrderStoreKey = ModuleName
)

nolint

View Source
const (
	OrderItemLimit            = 200
	MultiCancelOrderItemLimit = 200
)

nolint

View Source
const (
	OrderStatusOpen                   = 0
	OrderStatusFilled                 = 1
	OrderStatusCancelled              = 2
	OrderStatusExpired                = 3
	OrderStatusPartialFilledCancelled = 4
	OrderStatusPartialFilledExpired   = 5
)

nolint

View Source
const (
	OrderExtraInfoKeyNewFee     = "newFee"
	OrderExtraInfoKeyCancelFee  = "cancelFee"
	OrderExtraInfoKeyExpireFee  = "expireFee"
	OrderExtraInfoKeyDealFee    = "dealFee"
	OrderExtraInfoKeyReceiveFee = "receiveFee"
)

nolint

View Source
const (
	// System param
	DefaultOrderExpireBlocks = 259200 // order will be expired after 86400 blocks.
	DefaultMaxDealsPerBlock  = 1000   // deals limit per block

	// Fee param
	DefaultFeeAmountPerBlock     = "0" // okt
	DefaultFeeDenomPerBlock      = common.NativeToken
	DefaultFeeRateTrade          = "0.001" // percentage
	DefaultNewOrderMsgGasUnit    = 40000
	DefaultCancelOrderMsgGasUnit = 30000
)

nolint

View Source
const DefaultTestFeeAmountPerBlock = "0.000001" // okt

Variables

View Source
var (

	// iterator keys
	OrderKey             = []byte{0x11}
	DepthBookKey         = []byte{0x12}
	OrderIDsKey          = []byte{0x13}
	PriceKey             = []byte{0x14}
	ExpireBlockHeightKey = []byte{0x15}
	OrderNumPerBlockKey  = []byte{0x16}

	// none iterator keys
	RecentlyClosedOrderIDsKey = []byte{0x17}
	LastExpiredBlockHeightKey = []byte{0x18}
	OpenOrderNumKey           = []byte{0x19}
	StoreOrderNumKey          = []byte{0x20}
)

nolint

View Source
var (
	KeyOrderExpireBlocks     = []byte("OrderExpireBlocks")
	KeyMaxDealsPerBlock      = []byte("MaxDealsPerBlock")
	KeyFeePerBlock           = []byte("FeePerBlock")
	KeyTradeFeeRate          = []byte("TradeFeeRate")
	KeyNewOrderMsgGasUnit    = []byte("NewOrderMsgGasUnit")
	KeyCancelOrderMsgGasUnit = []byte("CancelOrderMsgGasUnit")
	DefaultFeePerBlock       = sdk.NewDecCoinFromDec(DefaultFeeDenomPerBlock, sdk.MustNewDecFromStr(DefaultFeeAmountPerBlock))
)

nolint : Parameter keys

View Source
var ModuleCdc *codec.Codec

ModuleCdc generic sealed codec to be used throughout this module

Functions

func ErrAllOrderFailedToExecute

func ErrAllOrderFailedToExecute() sdk.EnvelopedErr

func ErrCancelOrderBiggerThanLimit

func ErrCancelOrderBiggerThanLimit(limit int) sdk.EnvelopedErr

func ErrCheckTokenPairUnderDexDelistFailed

func ErrCheckTokenPairUnderDexDelistFailed() sdk.EnvelopedErr

func ErrInvalidAddress

func ErrInvalidAddress(address string) sdk.EnvelopedErr

func ErrInvalidSizeParam

func ErrInvalidSizeParam(size uint) sdk.EnvelopedErr

invalid size

func ErrIsProductLocked

func ErrIsProductLocked(product string) sdk.EnvelopedErr

func ErrMsgQuantityLessThan

func ErrMsgQuantityLessThan(minQuantity string) sdk.EnvelopedErr

func ErrNoOrdersIsCanceled

func ErrNoOrdersIsCanceled() sdk.EnvelopedErr

func ErrNotOrderOwner

func ErrNotOrderOwner(orderID string) sdk.EnvelopedErr

func ErrOrderIDsHasDuplicatedID

func ErrOrderIDsHasDuplicatedID() sdk.EnvelopedErr

func ErrOrderIDsIsEmpty

func ErrOrderIDsIsEmpty() sdk.EnvelopedErr

func ErrOrderIsNotExist

func ErrOrderIsNotExist(order string) sdk.EnvelopedErr

func ErrOrderIsNotExistOrClosed

func ErrOrderIsNotExistOrClosed(orderID string) sdk.EnvelopedErr

func ErrOrderItemCountsBiggerThanLimit

func ErrOrderItemCountsBiggerThanLimit(limit int) sdk.EnvelopedErr

func ErrOrderItemCountsIsEmpty

func ErrOrderItemCountsIsEmpty() sdk.EnvelopedErr

func ErrOrderItemPriceOrQuantityIsNotPositive

func ErrOrderItemPriceOrQuantityIsNotPositive() sdk.EnvelopedErr

func ErrOrderItemProductCountsIsEmpty

func ErrOrderItemProductCountsIsEmpty() sdk.EnvelopedErr

func ErrOrderItemProductFormat

func ErrOrderItemProductFormat() sdk.EnvelopedErr

func ErrOrderItemProductSymbolIsEqual

func ErrOrderItemProductSymbolIsEqual() sdk.EnvelopedErr

func ErrOrderItemSideIsNotBuyAndSell

func ErrOrderItemSideIsNotBuyAndSell() sdk.EnvelopedErr

func ErrOrderStatusIsNotOpen

func ErrOrderStatusIsNotOpen() sdk.EnvelopedErr

func ErrPriceOverAccuracy

func ErrPriceOverAccuracy(price sdk.Dec, priceDigit int64) sdk.EnvelopedErr

func ErrQuantityOverAccuracy

func ErrQuantityOverAccuracy(quantity sdk.Dec, quantityDigit int64) sdk.EnvelopedErr

func ErrSendCoinsFailed

func ErrSendCoinsFailed(coins string, to string) sdk.EnvelopedErr

func ErrTokenPairNotExist

func ErrTokenPairNotExist(product string) sdk.EnvelopedErr

func ErrTradingPairIsDelisting

func ErrTradingPairIsDelisting(product string) sdk.EnvelopedErr

func ErrUnknownOrderQueryType

func ErrUnknownOrderQueryType() sdk.EnvelopedErr

func ErrUserInputOrderIDIsEmpty

func ErrUserInputOrderIDIsEmpty() sdk.EnvelopedErr

func FormatOrderID

func FormatOrderID(blockHeight, orderNum int64) string

nolint

func FormatOrderIDPrefix

func FormatOrderIDPrefix(blockHeight int64) string

nolint

func FormatOrderIDsKey

func FormatOrderIDsKey(product string, price sdk.Dec, side string) string

nolint

func GetBlockHeightFromOrderID

func GetBlockHeightFromOrderID(orderID string) int64

nolint

func GetDepthBookKey

func GetDepthBookKey(key string) []byte

nolint

func GetExpireBlockHeightKey

func GetExpireBlockHeightKey(blockHeight int64) []byte

nolint

func GetKey

func GetKey(it sdk.Iterator) string

nolint

func GetOrderIDsKey

func GetOrderIDsKey(key string) []byte

nolint

func GetOrderKey

func GetOrderKey(key string) []byte

nolint

func GetOrderNumPerBlockKey

func GetOrderNumPerBlockKey(blockHeight int64) []byte

nolint

func GetPriceKey

func GetPriceKey(key string) []byte

nolint

func ParamKeyTable

func ParamKeyTable() params.KeyTable

ParamKeyTable for auth module

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers concrete types on the Amino codec

Types

type BlockMatchResult

type BlockMatchResult struct {
	BlockHeight int64                  `json:"block_height"`
	ResultMap   map[string]MatchResult `json:"result_map"`
	TimeStamp   int64                  `json:"timestamp"`
}

nolint

type Deal

type Deal struct {
	OrderID     string  `json:"order_id"`
	Side        string  `json:"side"`
	Quantity    sdk.Dec `json:"quantity"`
	Fee         string  `json:"fee"`
	FeeReceiver string  `json:"fee_receiver"`
}

nolint

type DepthBook

type DepthBook struct {
	Items []DepthBookItem
}

nolint

func (*DepthBook) Copy

func (depthBook *DepthBook) Copy() *DepthBook

Copy : depth copy of depth book

func (*DepthBook) InsertOrder

func (depthBook *DepthBook) InsertOrder(order *Order)

InsertOrder : Items in depth book are sorted by price desc insert a new order into depth book

func (*DepthBook) RemoveIfEmpty

func (depthBook *DepthBook) RemoveIfEmpty(index int) bool

RemoveIfEmpty : remove the filled or empty item

func (*DepthBook) RemoveOrder

func (depthBook *DepthBook) RemoveOrder(order *Order)

RemoveOrder : remove an order from depth book when order cancelled/expired

func (*DepthBook) Sub

func (depthBook *DepthBook) Sub(index int, num sdk.Dec, side string)

Sub : subtract the buy or sell quantity

type DepthBookItem

type DepthBookItem struct {
	Price        sdk.Dec `json:"price"`
	BuyQuantity  sdk.Dec `json:"buy_quantity"`
	SellQuantity sdk.Dec `json:"sell_quantity"`
}

nolint

type MatchResult

type MatchResult struct {
	BlockHeight int64   `json:"block_height"`
	Price       sdk.Dec `json:"price"`
	Quantity    sdk.Dec `json:"quantity"`
	Deals       []Deal  `json:"deals"`
}

nolint

type MsgCancelOrder

type MsgCancelOrder struct {
	Sender  sdk.AccAddress `json:"sender"`
	OrderID string         `json:"order_id"`
}

nolint

type MsgCancelOrders

type MsgCancelOrders struct {
	Sender   sdk.AccAddress `json:"sender"` // order maker address
	OrderIDs []string       `json:"order_ids"`
}

nolint

func NewMsgCancelOrder

func NewMsgCancelOrder(sender sdk.AccAddress, orderID string) MsgCancelOrders

NewMsgCancelOrder is a constructor function for MsgCancelOrder

func NewMsgCancelOrders

func NewMsgCancelOrders(sender sdk.AccAddress, orderIDItems []string) MsgCancelOrders

NewMsgCancelOrders is a constructor function for MsgCancelOrder

func (MsgCancelOrders) CalculateGas

func (msg MsgCancelOrders) CalculateGas(gasUnit uint64) uint64

Calculate customize gas

func (MsgCancelOrders) GetSignBytes

func (msg MsgCancelOrders) GetSignBytes() []byte

GetSignBytes encodes the message for signing

func (MsgCancelOrders) GetSigners

func (msg MsgCancelOrders) GetSigners() []sdk.AccAddress

GetSigners defines whose signature is required

func (MsgCancelOrders) Route

func (msg MsgCancelOrders) Route() string

nolint

func (MsgCancelOrders) Type

func (msg MsgCancelOrders) Type() string

nolint

func (MsgCancelOrders) ValidateBasic

func (msg MsgCancelOrders) ValidateBasic() sdk.Error

nolint

type MsgNewOrder

type MsgNewOrder struct {
	Sender   sdk.AccAddress `json:"sender"`   // order maker address
	Product  string         `json:"product"`  // product for trading pair in full name of the tokens
	Side     string         `json:"side"`     // BUY/SELL
	Price    sdk.Dec        `json:"price"`    // price of the order
	Quantity sdk.Dec        `json:"quantity"` // quantity of the order
}

nolint

type MsgNewOrders

type MsgNewOrders struct {
	Sender     sdk.AccAddress `json:"sender"` // order maker address
	OrderItems []OrderItem    `json:"order_items"`
}

********************MsgNewOrders************* nolint

func NewMsgNewOrder

func NewMsgNewOrder(sender sdk.AccAddress, product string, side string, price string,
	quantity string) MsgNewOrders

NewMsgNewOrder is a constructor function for MsgNewOrder

func NewMsgNewOrders

func NewMsgNewOrders(sender sdk.AccAddress, orderItems []OrderItem) MsgNewOrders

NewMsgNewOrders is a constructor function for MsgNewOrder

func (MsgNewOrders) CalculateGas

func (msg MsgNewOrders) CalculateGas(gasUnit uint64) uint64

Calculate customize gas

func (MsgNewOrders) GetSignBytes

func (msg MsgNewOrders) GetSignBytes() []byte

GetSignBytes : encodes the message for signing

func (MsgNewOrders) GetSigners

func (msg MsgNewOrders) GetSigners() []sdk.AccAddress

GetSigners defines whose signature is required

func (MsgNewOrders) Route

func (msg MsgNewOrders) Route() string

nolint

func (MsgNewOrders) Type

func (msg MsgNewOrders) Type() string

nolint

func (MsgNewOrders) ValidateBasic

func (msg MsgNewOrders) ValidateBasic() sdk.Error

ValidateBasic : Implements Msg.

type Order

type Order struct {
	TxHash            string         `json:"txhash"`           // txHash of the place order tx
	OrderID           string         `json:"order_id"`         // order id
	Sender            sdk.AccAddress `json:"sender"`           // order maker address
	Product           string         `json:"product"`          // product for trading pair
	Side              string         `json:"side"`             // BUY/SELL
	Price             sdk.Dec        `json:"price"`            // price of the order
	Quantity          sdk.Dec        `json:"quantity"`         // quantity of the order
	Status            int64          `json:"status"`           // order status, see OrderStatusXXX
	FilledAvgPrice    sdk.Dec        `json:"filled_avg_price"` // filled average price
	RemainQuantity    sdk.Dec        `json:"remain_quantity"`  // Remaining quantity of the order
	RemainLocked      sdk.Dec        `json:"remain_locked"`    // Remaining locked quantity of token
	Timestamp         int64          `json:"timestamp"`        // created timestamp
	OrderExpireBlocks int64          `json:"order_expire_blocks"`
	FeePerBlock       sdk.SysCoin    `json:"fee_per_block"`
	ExtraInfo         string         `json:"extra_info"` // extra info of order in json format
}

nolint

func MockOrder

func MockOrder(orderID, product, side, price, quantity string) *Order

nolint

func NewOrder

func NewOrder(txHash string, sender sdk.AccAddress, product, side string, price, quantity sdk.Dec,
	timestamp int64, orderExpireBlocks int64, feePerBlock sdk.SysCoin) *Order

nolint

func (*Order) Cancel

func (order *Order) Cancel()

nolint

func (*Order) Expire

func (order *Order) Expire()

nolint

func (*Order) Fill

func (order *Order) Fill(price, fillAmount sdk.Dec)

nolint

func (*Order) GetExtraInfoWithKey

func (order *Order) GetExtraInfoWithKey(key string) string

nolint

func (*Order) NeedLockCoins

func (order *Order) NeedLockCoins() sdk.SysCoins

NeedLockCoins : when place a new order, we should lock the coins of sender

func (*Order) NeedUnlockCoins

func (order *Order) NeedUnlockCoins() sdk.SysCoins

NeedUnlockCoins : when order be cancelled/expired, we should unlock the coins of sender

func (*Order) RecordOrderCancelFee

func (order *Order) RecordOrderCancelFee(fee sdk.SysCoins)

nolint

func (*Order) RecordOrderDealFee

func (order *Order) RecordOrderDealFee(fee sdk.SysCoins)

RecordOrderDealFee : An order may have several deals

func (*Order) RecordOrderNewFee

func (order *Order) RecordOrderNewFee(fee sdk.SysCoins)

nolint

func (*Order) RecordOrderReceiveFee

func (order *Order) RecordOrderReceiveFee(fee sdk.SysCoins)

nolint

func (*Order) String

func (order *Order) String() string

func (*Order) Unlock

func (order *Order) Unlock()

nolint

type OrderItem

type OrderItem struct {
	Product  string  `json:"product"`  // product for trading pair in full name of the tokens
	Side     string  `json:"side"`     // BUY/SELL
	Price    sdk.Dec `json:"price"`    // price of the order
	Quantity sdk.Dec `json:"quantity"` // quantity of the order
}

nolint

func NewOrderItem

func NewOrderItem(product string, side string, price string,
	quantity string) OrderItem

nolint

type OrderResult

type OrderResult struct {
	Error   error  `json:"error"`
	Message string `json:"msg"`     // order return error message
	OrderID string `json:"orderid"` // order return orderid
}

nolint

type OrderStatus

type OrderStatus int

nolint

const (
	Open OrderStatus = iota
	Filled
	Cancelled
	Expired
	PartialFilledCancelled
	PartialFilledExpired
)

nolint

func (OrderStatus) String

func (p OrderStatus) String() string

type Params

type Params struct {
	OrderExpireBlocks     int64       `json:"order_expire_blocks"`
	MaxDealsPerBlock      int64       `json:"max_deals_per_block"`
	FeePerBlock           sdk.SysCoin `json:"fee_per_block"`
	TradeFeeRate          sdk.Dec     `json:"trade_fee_rate"`
	NewOrderMsgGasUnit    uint64      `json:"new_order_msg_gas_unit"`
	CancelOrderMsgGasUnit uint64      `json:"cancel_order_msg_gas_unit"`
}

nolint : order parameters

func DefaultParams

func DefaultParams() Params

DefaultParams returns a default set of parameters.

func DefaultTestParams

func DefaultTestParams() Params

func (*Params) ParamSetPairs

func (p *Params) ParamSetPairs() params.ParamSetPairs

ParamSetPairs implements the ParamSet interface and returns all the key/value pairs pairs of auth module's parameters. nolint

func (Params) String

func (p Params) String() string

String implements the stringer interface.

type ProductLock

type ProductLock struct {
	BlockHeight  int64
	Price        sdk.Dec
	Quantity     sdk.Dec
	BuyExecuted  sdk.Dec
	SellExecuted sdk.Dec
}

nolint

type ProductLockMap

type ProductLockMap struct {
	Data map[string]*ProductLock
}

nolint

func NewProductLockMap

func NewProductLockMap() *ProductLockMap

nolint

Jump to

Keyboard shortcuts

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