Orders are uniquely identified using the OrderID struct, containing the MarketAccountKey and the counter.
The counter for an order is a per market account unique identifier. It is derived from an incrementing counter stored on the market account. The counter is a u32 so the maximum number of orders an account can place is about 4 trillion.
structOrderID has store, copy, drop {// Key of market account this order was placed for. accountKey:MarketAccountKey,// Counter for this market account. counter:u32,}
// Used to identify user that placed the order from a given protocol.// Should only be able to be generated using a ProtocolCapability.structAccountIdentifier has drop { protocolAddress: address, // 0x0 is reserved as the sentinal value. userAddress: address, // 0x0 is reserved as the sentinal value.}
MarketAccountKey
Generated from get_market_account_key, used to store and place orders placed on behalf of users in specific markets.
// Each market account is uniquely described by a protocol and user address.structMarketAccountKey has store, copy, drop { protocolAddress: address, userAddress: address,}
Order Metadata
Stores information about an order.
structOrderMetadata has drop, store, copy {// Side for this order. See the OrderSide enum. side:u8,// Behaviour for this order. See the OrderBehaviour enum. behaviour:u8,// Limit price for this order. price:u64,// The original quantity of the order. originalQty:u64,// The remaining qty of the order + any pending crank qty. The order is fully filled if// unfilledQty - <pending crank qty> == 0. <pending crank qty> is equal to the takerCrankPendingQty, stored on// the order, and the maker crank pending qty, which is only stored in the price store for efficiancy.// Mutable field. unfilledQty:u64,// Qty of a taker order which was executed but is still waiting for the crank to be turned so executions can// be created.// Mutable field. takerCrankPendingQty:u64,// Optional metadata provided for this order. clientOrderID:u32,// Address of the owner of this order. Could be the user's address directly or the address of a protocol// owned resource account. ownerAddress: address,// ID which uniquely identifies this order in the API. Note that this is different from the internal id of the// order, which is used internally to map to previously created order objects. orderID:OrderID,// The remaining collateral for a market buy order.// Mutable field. marketBuyRemainingCollateral:u64,}
Events
IndexingCreationEvent
Emitted when an order is created.
structIndexingCreationEvent has drop, store {// Type info for the instrument coin type for the order. instrumentType: type_info::TypeInfo,// Type info for the quote coin type for the order. quoteType: type_info::TypeInfo,// Orders metadata. orderMetadata:OrderMetadata,// Timestamp this event was produced at. timestampSecs:u64,}
IndexingFinalizeEvent
Emitted when an order is finalized.
structIndexingFinalizeEvent has drop, store {// Type info for the instrument coin type for the order. instrumentType: type_info::TypeInfo,// Type info for the quote coin type for the order. quoteType: type_info::TypeInfo,// Orders metadata. orderMetadata:OrderMetadata,// Timestamp this event was produced at. timestampSecs:u64,}
IndexingExecutionEvent
Emitted when an order is executed.
structIndexingExecutionEvent has drop, store {// Type info for the instrument coin type for the order. instrumentType: type_info::TypeInfo,// Type info for the quote coin type for the order. quoteType: type_info::TypeInfo,// Metadata for the maker order after the execution. makerOrderMetadata:OrderMetadata,// Metadata for the taker order after the execution. takerOrderMetadata:OrderMetadata,// Price of the execution. Fixedpoint value. price:u64,// Qty of the execution. Fixedpoint value. qty:u64,// Information about the fee charged to the taker. takerFeeInfo:ExecFeeInfo,// Information about the fee charged to the maker. makerFeeInfo:ExecFeeInfo,// Timestamp this event was produced at. timestampSecs:u64}
IndexingPriceUpdateEvent
Emitted when the price for a pair potentially changes (when an order is added or cancelled).
structIndexingPriceUpdateEvent has drop, store {// Type info for the instrument coin type for the market. instrumentType: type_info::TypeInfo,// Type info for the quote coin type for the market. quoteType: type_info::TypeInfo,// The most someone is willing to pay for the given instrument/quote pair.// Represented as a fixed point number. maxBid:u64,// How much quantity there is the the maxBid price point.// Represented as a fixed point number. bidSize:u64,// The least someone is willing to accept as payment for the given instrument/quote pair.// Represented as a fixed point number. minAsk:u64,// How much quantity there is the the minAsk price point.// Represented as a fixed point number. askSize:u64,// The chain timestamp this quote was issued at. timestampMicroSeconds:u64}
Enums
OrderSide
The side of the order. Can be a buy or a sell.
// Represents a sell order.const SIDE_SELL:u8=1;// Represents a buy order.const SIDE_BUY:u8=2;
OrderBehaviour
The behaviour of the order. See Order Behaviour for more information.
// Represents a standard limit order.const TYPE_GTC:u8=1;// Represents a limit post order.const TYPE_POST:u8=2;// Represents a limit immediate or cancel (IOC) order.const TYPE_IOC:u8=3;// Represents a limit fill or kill (FOK) order.const TYPE_FOK:u8=4;