Skip to content

Commit

Permalink
Full Node Status taker order status protos (#2003)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonfung-dydx committed Oct 18, 2024
1 parent bd349d9 commit b01af24
Show file tree
Hide file tree
Showing 6 changed files with 1,198 additions and 153 deletions.
20 changes: 20 additions & 0 deletions proto/dydxprotocol/clob/order.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dydxprotocol.clob;

import "gogoproto/gogo.proto";
import "dydxprotocol/subaccounts/subaccount.proto";
import "dydxprotocol/clob/liquidations.proto";

option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/clob/types";

Expand Down Expand Up @@ -227,3 +228,22 @@ message TransactionOrdering {
// Within the block, the unique transaction index.
uint32 transaction_index = 2;
}

// StreamLiquidationOrder represents an protocol-generated IOC liquidation order.
// Used in full node streaming.
message StreamLiquidationOrder {
// Information about this liquidation order.
PerpetualLiquidationInfo liquidation_info = 1;

// CLOB pair ID of the CLOB pair the liquidation order will be matched against.
uint32 clob_pair_id = 2;

// True if this is a buy order liquidating a short position, false if vice versa.
bool is_buy = 3;

// The number of base quantums for this liquidation order.
uint64 quantums = 4;

// The subticks this liquidation order will be submitted at.
uint64 subticks = 5;
}
35 changes: 35 additions & 0 deletions proto/dydxprotocol/clob/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,38 @@ message StreamOrderbookFill {
// Resulting fill amounts for each order in the orders array.
repeated uint64 fill_amounts = 3;
}

// StreamTakerOrder provides information on a taker order that was attempted
// to be matched on the orderbook.
// It is intended to be used only in full node streaming.
message StreamTakerOrder {
// The taker order that was matched on the orderbook. Can be a
// regular order or a liquidation order.
oneof taker_order {
Order order = 1;
StreamLiquidationOrder liquidation_order = 2;
}

// Information on the taker order after it is matched on the book,
// either successfully or unsuccessfully.
StreamTakerOrderStatus taker_order_status = 3;
}

// StreamTakerOrderStatus is a representation of a taker order
// after it is attempted to be matched on the orderbook.
// It is intended to be used only in full node streaming.
message StreamTakerOrderStatus {
// The state of the taker order after attempting to match it against the orderbook.
// Possible enum values can be found here:
// https://github.com/dydxprotocol/v4-chain/blob/main/protocol/x/clob/types/orderbook.go#L105
uint32 order_status = 1;

// The amount of remaining (non-matched) base quantums of this taker order.
uint64 remaining_quantums = 2;

// The amount of base quantums that were *optimistically* filled for this taker order
// when the order is matched against the orderbook. Note that if any quantums of this order
// were optimistically filled or filled in state before this invocation of the matching loop,
// this value will not include them.
uint64 optimistically_filled_quantums = 3;
}
12 changes: 12 additions & 0 deletions protocol/x/clob/types/liquidation_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ func NewLiquidationOrder(
}
}

// ToStreamLiquidationOrder converts the LiquidationOrder to a StreamLiquidationOrder
// to be emitted by full node streaming.
func (lo *LiquidationOrder) ToStreamLiquidationOrder() *StreamLiquidationOrder {
return &StreamLiquidationOrder{
LiquidationInfo: &lo.perpetualLiquidationInfo,
ClobPairId: uint32(lo.clobPairId),
IsBuy: lo.isBuy,
Quantums: lo.quantums.ToUint64(),
Subticks: lo.subticks.ToUint64(),
}
}

// IsBuy returns true if this is a buy order, false if not.
// This function is necessary for the `LiquidationOrder` type to implement the `MatchableOrder` interface.
func (lo *LiquidationOrder) IsBuy() bool {
Expand Down
Loading

0 comments on commit b01af24

Please sign in to comment.