Documentation ¶
Index ¶
- Constants
- func ValidateOrder(ord Order, status OrderStatus, lotSize uint64) error
- type CancelOrder
- type CoinID
- type Commitment
- type InstantOrder
- type Order
- type OrderID
- type OrderStatus
- type OrderType
- type P
- type Prefix
- func (p *Prefix) Base() uint32
- func (p *Prefix) Commitment() Commitment
- func (p *Prefix) Prefix() *Prefix
- func (p *Prefix) Quote() uint32
- func (p *Prefix) Serialize() []byte
- func (p *Prefix) SetTime(t time.Time)
- func (p *Prefix) Time() int64
- func (p *Prefix) Type() OrderType
- func (p *Prefix) User() account.AccountID
- type Preimage
- type T
- type Trade
Constants ¶
const CommitmentSize = hashSize
CommitmentSize is the length of the Commitment, a 32-byte Blake-256 hash according to the DEX specification.
const OrderIDSize = hashSize
OrderIDSize defines the length in bytes of an OrderID.
const PrefixLen = account.HashSize + 4 + 4 + 1 + 8 + 8 + CommitmentSize
PrefixLen is the length in bytes of the serialized order Prefix.
const PreimageSize = 32
PreimageSize defines the length of the preimage, which is a 32-byte value according to the DEX specification.
Variables ¶
This section is empty.
Functions ¶
func ValidateOrder ¶
func ValidateOrder(ord Order, status OrderStatus, lotSize uint64) error
ValidateOrder ensures that the order with the given status for the specified market is sensible. The ServerTime may not be set yet, so the OrderID cannot be computed.
Types ¶
type CancelOrder ¶
CancelOrder defines a cancel order in terms of an order Prefix and the ID of the order to be canceled.
func (*CancelOrder) Serialize ¶
func (o *CancelOrder) Serialize() []byte
Serialize marshals the CancelOrder into a []byte.
func (*CancelOrder) String ¶
func (o *CancelOrder) String() string
String is the same as UID. It is defined to satisfy Stringer.
func (*CancelOrder) Trade ¶
func (o *CancelOrder) Trade() *Trade
Trade returns a pointer to the orders embedded Trade.
func (*CancelOrder) UID ¶
func (o *CancelOrder) UID() string
UID computes the order ID, returning the string representation.
type CoinID ¶
type CoinID []byte
CoinID should be used to wrap a []byte so that it may be used as a map key.
type Commitment ¶
type Commitment hash
Commitment is the Blake-256 hash of the Preimage.
func (*Commitment) IsZero ¶
func (c *Commitment) IsZero() bool
IsZero indicates if the Commitment is the zero-value for the type.
func (*Commitment) Scan ¶
func (c *Commitment) Scan(src interface{}) error
Scan implements the sql.Scanner interface. NULL table values are scanned as the zero-value Commitment.
func (Commitment) String ¶
func (c Commitment) String() string
String returns a hexadecimal representation of the Commitment. String implements fmt.Stringer.
type InstantOrder ¶
InstantOrder defines a instant order in terms of a Prefix and the order details, including the backing Coins, the order direction/side, order quantity, and the address where the matched client will send funds. The order quantity is in atoms of the base asset, and must be an integral multiple of the asset's lot size, except for Market buy orders when it is in units of the quote asset and is not bound by integral lot size multiple constraints.
func (*InstantOrder) Serialize ¶
func (o *InstantOrder) Serialize() []byte
Serialize marshals the LimitOrder into a []byte.
func (*InstantOrder) String ¶
func (o *InstantOrder) String() string
String is the same as UID. It is defined to satisfy Stringer.
func (*InstantOrder) UID ¶
func (o *InstantOrder) UID() string
UID computes the order ID, returning the string representation.
type Order ¶
type Order interface { // Prefix returns the order *Prefix. Prefix() *Prefix // Trade returns the order *Trade if a limit or market order, else nil. Trade() *Trade // ID computes the Order's ID from its serialization. Serialization is // detailed in the 'Client Order Management' section of the DEX // specification. ID() OrderID // UID gives the string representation of the order ID. It is named to // reflect the intent of providing a unique identifier. UID() string // User gives the user's account ID. User() account.AccountID // Serialize marshals the order. Serialization is detailed in the 'Client // Order Management' section of the DEX specification. Serialize() []byte // Type indicates the Order's type (e.g. LimitOrder, MarketOrder, etc.). Type() OrderType // Time returns the Order's server time in milliseconds, when it was received by the server. Time() int64 // SetTime sets the ServerTime field of the prefix. SetTime(time.Time) // Base returns the unique integer identifier of the base asset as defined // in the asset package. Base() uint32 // Quote returns the unique integer identifier of the quote asset as defined // in the asset package. Quote() uint32 // Commitment returns the order's preimage commitment. Commitment() Commitment }
Order specifies the methods required for a type to function as a DEX order. See the concrete implementations of MarketOrder, LimitOrder, and CancelOrder.
type OrderID ¶
type OrderID hash
OrderID is the unique identifier for each order. It is defined as the Blake256 hash of the serialized order.
func (OrderID) MarshalJSON ¶
MarshalJSON satisfies the json.Marshaller interface, and will marshal the id to a hex string.
type OrderStatus ¶
type OrderStatus uint16
OrderStatus indicates the state of an order.
const ( // OrderStatusUnknown is a sentinel value to be used when the status of an // order cannot be determined. OrderStatusUnknown OrderStatus = iota // OrderStatusEpoch is for orders that have been received and validated, but // not processed yet by the epoch order matcher. OrderStatusEpoch // OrderStatusBooked is for orders that have been put on the book // ("standing" time in force). This includes partially filled orders. As // such, when an order with this "booked" status is matched with another // order, it should have its filled amount updated, and its status should // only be changed to OrderStatusExecuted if the remaining quantity becomes // less than the lot size, or perhaps to OrderStatusRevoked if the swap has // failed and DEX conduct policy requires that it be removed from the order // book. OrderStatusBooked // OrderStatusExecuted is for orders that have been successfully processed // and taken off the book. An order may reach this state if it is (1) // matched one or more times and removed from the books, or (2) unmatched in // epoch processing and with a time-in-force that forbids the order from // entering the books. Orders in the first category (matched and // subsequently removed from the book) include: a matched cancel order, a // completely filled limit or market order, or a partially filled market // buy order. Market and limit orders in the second category will not // necessarily be completely unfilled. Partially filled orders that are // still on the order book remain in OrderStatusBooked. // // Note: The DB driver must be able to distinguish cancel orders that have // not matched from those that were not matched, but OrderStatusExecuted // will be returned for both such orders, although a new exported status may // be added so the consumer can query this information (TODO). The DB knows // the match status for cancel orders and how the cancel order was finalized // (ExecuteOrder for matched, and FailCancelOrder for unmatched). OrderStatusExecuted // OrderStatusCanceled is for orders that were on the book, but matched with // a cancel order. This does not mean the order is completely unfilled. OrderStatusCanceled // OrderStatusRevoked is DEX-revoked orders that were not canceled by // matching with the client's cancel order but by DEX policy. This includes // standing limit orders that were matched but have failed to swap (neither // executed nor canceled), and preimage misses. OrderStatusRevoked )
There are two general classes of orders: ACTIVE and ARCHIVED. Orders with one of the ACTIVE order statuses that follow are likely to be updated.
type OrderType ¶
type OrderType uint8
OrderType distinguishes the different kinds of orders (e.g. limit, market, cancel).
The different OrderType values.
type P ¶
type P = Prefix
P is an alias for Prefix. Embedding with the alias allows us to define a method on the interface called Prefix that returns the *Prefix.
type Prefix ¶
type Prefix struct { AccountID account.AccountID BaseAsset uint32 QuoteAsset uint32 OrderType OrderType ClientTime time.Time ServerTime time.Time Commit Commitment // contains filtered or unexported fields }
Prefix is the order prefix containing data fields common to all orders.
func (*Prefix) Commitment ¶
func (p *Prefix) Commitment() Commitment
Commitment returns the order Commitment.
type Preimage ¶
type Preimage [PreimageSize]byte
Preimage represents the 32-byte preimage as a byte slice.
func (*Preimage) Commit ¶
func (pi *Preimage) Commit() Commitment
Commit computes the preimage commitment as the Blake-256 hash of the Preimage.
type T ¶
type T = Trade
T is an alias for Trade. Embedding with the alias allows us to define a method on the interface called Trade that returns the *Trade.
type Trade ¶
type Trade struct { Coins []CoinID Sell bool Quantity uint64 Address string FillAmt uint64 // use Filled and AddFill methods for thread-safe access // contains filtered or unexported fields }
Trade is information about a trade-type order. Both limit and market orders are trade-type orders.
func (*Trade) Copy ¶
Copy makes a shallow copy of a Trade. This is useful when attempting to assign a newly-created trade to an order's field without a linter warning about copying a mutex (e.g. MarketOrder{T: *aNewTrade.Copy()}).
func (*Trade) SwapAddress ¶
SwapAddress returns the order's payment address.