Skip to content

Commit

Permalink
[OTE-529] feat(OE): Deprecate in-mem Untriggered Conditional Orders (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding authored Jul 26, 2024
1 parent 8932494 commit 749dff9
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 517 deletions.
70 changes: 70 additions & 0 deletions protocol/testutil/constants/stateful_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,20 @@ var (
ConditionType: clobtypes.Order_CONDITION_TYPE_STOP_LOSS,
ConditionalOrderTriggerSubticks: 20,
}
ConditionalOrder_Alice_Num1_Id0_Clob0_Buy5_Price20_GTBT15_StopLoss20 = clobtypes.Order{
OrderId: clobtypes.OrderId{
SubaccountId: Alice_Num1,
ClientId: 0,
OrderFlags: clobtypes.OrderIdFlags_Conditional,
ClobPairId: 0,
},
Side: clobtypes.Order_SIDE_BUY,
Quantums: 5,
Subticks: 20,
GoodTilOneof: &clobtypes.Order_GoodTilBlockTime{GoodTilBlockTime: 15},
ConditionType: clobtypes.Order_CONDITION_TYPE_STOP_LOSS,
ConditionalOrderTriggerSubticks: 20,
}
ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_TakeProfit20 = clobtypes.Order{
OrderId: clobtypes.OrderId{
SubaccountId: Alice_Num0,
Expand Down Expand Up @@ -554,6 +568,20 @@ var (
ConditionType: clobtypes.Order_CONDITION_TYPE_STOP_LOSS,
ConditionalOrderTriggerSubticks: 25,
}
ConditionalOrder_Alice_Num1_Id1_Clob0_Buy15_Price25_GTBT15_StopLoss25 = clobtypes.Order{
OrderId: clobtypes.OrderId{
SubaccountId: Alice_Num1,
ClientId: 1,
OrderFlags: clobtypes.OrderIdFlags_Conditional,
ClobPairId: 0,
},
Side: clobtypes.Order_SIDE_BUY,
Quantums: 15,
Subticks: 25,
GoodTilOneof: &clobtypes.Order_GoodTilBlockTime{GoodTilBlockTime: 15},
ConditionType: clobtypes.Order_CONDITION_TYPE_STOP_LOSS,
ConditionalOrderTriggerSubticks: 25,
}
ConditionalOrder_Alice_Num0_Id1_Clob0_Buy15_Price10_GTBT15_TakeProfit20 = clobtypes.Order{
OrderId: clobtypes.OrderId{
SubaccountId: Alice_Num0,
Expand Down Expand Up @@ -624,6 +652,20 @@ var (
ConditionType: clobtypes.Order_CONDITION_TYPE_TAKE_PROFIT,
ConditionalOrderTriggerSubticks: 20,
}
ConditionalOrder_Alice_Num1_Id2_Clob0_Sell20_Price20_GTBT15_TakeProfit20 = clobtypes.Order{
OrderId: clobtypes.OrderId{
SubaccountId: Alice_Num1,
ClientId: 2,
OrderFlags: clobtypes.OrderIdFlags_Conditional,
ClobPairId: 0,
},
Side: clobtypes.Order_SIDE_SELL,
Quantums: 20,
Subticks: 20,
GoodTilOneof: &clobtypes.Order_GoodTilBlockTime{GoodTilBlockTime: 15},
ConditionType: clobtypes.Order_CONDITION_TYPE_TAKE_PROFIT,
ConditionalOrderTriggerSubticks: 20,
}
ConditionalOrder_Alice_Num0_Id2_Clob0_Buy20_Price10_GTBT15_TakeProfit10 = clobtypes.Order{
OrderId: clobtypes.OrderId{
SubaccountId: Alice_Num0,
Expand Down Expand Up @@ -666,6 +708,20 @@ var (
ConditionType: clobtypes.Order_CONDITION_TYPE_STOP_LOSS,
ConditionalOrderTriggerSubticks: 25,
}
ConditionalOrder_Alice_Num1_Id3_Clob0_Buy25_Price25_GTBT15_StopLoss25 = clobtypes.Order{
OrderId: clobtypes.OrderId{
SubaccountId: Alice_Num1,
ClientId: 3,
OrderFlags: clobtypes.OrderIdFlags_Conditional,
ClobPairId: 0,
},
Side: clobtypes.Order_SIDE_BUY,
Quantums: 25,
Subticks: 10,
GoodTilOneof: &clobtypes.Order_GoodTilBlockTime{GoodTilBlockTime: 15},
ConditionType: clobtypes.Order_CONDITION_TYPE_STOP_LOSS,
ConditionalOrderTriggerSubticks: 25,
}
ConditionalOrder_Alice_Num0_Id3_Clob0_Buy25_Price10_GTBT15_TakeProfit20 = clobtypes.Order{
OrderId: clobtypes.OrderId{
SubaccountId: Alice_Num0,
Expand Down Expand Up @@ -722,6 +778,20 @@ var (
ConditionType: clobtypes.Order_CONDITION_TYPE_STOP_LOSS,
ConditionalOrderTriggerSubticks: 20,
}
ConditionalOrder_Alice_Num0_Id1_Clob1_Buy5_Price10_GTBT15_StopLoss20 = clobtypes.Order{
OrderId: clobtypes.OrderId{
SubaccountId: Alice_Num0,
ClientId: 0,
OrderFlags: clobtypes.OrderIdFlags_Conditional,
ClobPairId: 1,
},
Side: clobtypes.Order_SIDE_BUY,
Quantums: 5,
Subticks: 10,
GoodTilOneof: &clobtypes.Order_GoodTilBlockTime{GoodTilBlockTime: 15},
ConditionType: clobtypes.Order_CONDITION_TYPE_STOP_LOSS,
ConditionalOrderTriggerSubticks: 20,
}
ConditionalOrder_Alice_Num0_Id0_Clob1_Buy5_Price10_GTBT15_TakeProfit20 = clobtypes.Order{
OrderId: clobtypes.OrderId{
SubaccountId: Alice_Num0,
Expand Down
20 changes: 0 additions & 20 deletions protocol/x/clob/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,10 @@ func EndBlocker(
)
}

deliveredCancels := keeper.GetDeliveredCancelledOrderIds(ctx)
// Prune expired untriggered conditional orders from the in-memory UntriggeredConditionalOrders struct.
keeper.PruneUntriggeredConditionalOrders(
expiredStatefulOrderIds,
deliveredCancels,
)

// Update the memstore with expired order ids.
// These expired stateful order ids will be purged from the memclob in `Commit`.
processProposerMatchesEvents.ExpiredStatefulOrderIds = expiredStatefulOrderIds

// Before triggering conditional orders, add newly-placed conditional orders to the clob keeper's
// in-memory UntriggeredConditionalOrders data structure to allow conditional orders to
// trigger in the same block they are placed. Skip triggering orders which have been cancelled
// or expired.
// TODO(CLOB-773) Support conditional order replacements. Ensure replacements are de-duplicated.
conditionalOrdersIds := keeper.GetDeliveredConditionalOrderIds(ctx)
keeper.AddUntriggeredConditionalOrders(
ctx,
conditionalOrdersIds,
lib.UniqueSliceToSet(deliveredCancels),
lib.UniqueSliceToSet(expiredStatefulOrderIds),
)

// Poll out all triggered conditional orders from `UntriggeredConditionalOrders` and update state.
triggeredConditionalOrderIds := keeper.MaybeTriggerConditionalOrders(ctx)
// Update the memstore with conditional order ids triggered in the last block.
Expand Down
Loading

0 comments on commit 749dff9

Please sign in to comment.