decred.org/dcrdex@v1.0.5/dex/order/status.go (about) 1 // This code is available on the terms of the project LICENSE.md file, 2 // also available online at https://blueoakcouncil.org/license/1.0.0. 3 4 package order 5 6 // OrderStatus indicates the state of an order. 7 type OrderStatus uint16 8 9 // There are two general classes of orders: ACTIVE and ARCHIVED. Orders with one 10 // of the ACTIVE order statuses that follow are likely to be updated. 11 const ( 12 // OrderStatusUnknown is a sentinel value to be used when the status of an 13 // order cannot be determined. 14 OrderStatusUnknown OrderStatus = iota 15 16 // OrderStatusEpoch is for orders that have been received and validated, but 17 // not processed yet by the epoch order matcher. 18 OrderStatusEpoch 19 20 // OrderStatusBooked is for orders that have been put on the book 21 // ("standing" time in force). This includes partially filled orders. As 22 // such, when an order with this "booked" status is matched with another 23 // order, it should have its filled amount updated, and its status should 24 // only be changed to OrderStatusExecuted if the remaining quantity becomes 25 // less than the lot size, or perhaps to OrderStatusRevoked if the swap has 26 // failed and DEX conduct policy requires that it be removed from the order 27 // book. 28 OrderStatusBooked 29 30 // OrderStatusExecuted is for orders that have been successfully processed 31 // and taken off the book. An order may reach this state if it is (1) 32 // matched one or more times and removed from the books, or (2) unmatched in 33 // epoch processing and with a time-in-force that forbids the order from 34 // entering the books. Orders in the first category (matched and 35 // subsequently removed from the book) include: a matched cancel order, a 36 // completely filled limit or market order, or a partially filled market 37 // buy order. Market and limit orders in the second category will not 38 // necessarily be completely unfilled. Partially filled orders that are 39 // still on the order book remain in OrderStatusBooked. 40 // 41 // Note: The DB driver must be able to distinguish cancel orders that have 42 // not matched from those that were not matched, but OrderStatusExecuted 43 // will be returned for both such orders, although a new exported status may 44 // be added so the consumer can query this information (TODO). The DB knows 45 // the match status for cancel orders and how the cancel order was finalized 46 // (ExecuteOrder for matched, and FailCancelOrder for unmatched). 47 OrderStatusExecuted 48 49 // OrderStatusCanceled is for orders that were on the book, but matched with 50 // a cancel order. This does not mean the order is completely unfilled. 51 OrderStatusCanceled 52 53 // OrderStatusRevoked is DEX-revoked orders that were not canceled by 54 // matching with the client's cancel order but by DEX policy. This includes 55 // standing limit orders that were matched but have failed to swap (neither 56 // executed nor canceled), and preimage misses. 57 OrderStatusRevoked 58 ) 59 60 var orderStatusNames = map[OrderStatus]string{ 61 OrderStatusUnknown: "unknown", 62 OrderStatusEpoch: "epoch", 63 OrderStatusBooked: "booked", 64 OrderStatusExecuted: "executed", 65 OrderStatusCanceled: "canceled", 66 OrderStatusRevoked: "revoked", 67 } 68 69 // String implements Stringer. 70 func (s OrderStatus) String() string { 71 name, ok := orderStatusNames[s] 72 if !ok { 73 panic("unknown order status!") // programmer error 74 } 75 return name 76 } 77 78 // IsActive returns whether the status is considered active. 79 func (s OrderStatus) IsActive() bool { 80 return s == OrderStatusEpoch || s == OrderStatusBooked 81 }