Skip to content

Commit

Permalink
[CLOB-1058] Allow FOK/IOC Reduce Only Orders (#919)
Browse files Browse the repository at this point in the history
* allow FOK/IOC reduce only orders in validate basic

* add validation for disallowing replacement RO orders for existing non-RO orders

* validate basic tests

* e2e tests

* lint

* more state assertions
  • Loading branch information
jonfung-dydx committed Jan 8, 2024
1 parent d552a3d commit 0589d85
Show file tree
Hide file tree
Showing 7 changed files with 581 additions and 6 deletions.
87 changes: 87 additions & 0 deletions protocol/testutil/constants/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,20 @@ var (
Subticks: 500_000_000_000,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{GoodTilBlock: 10},
}
Order_Carl_Num0_Id0_Clob0_Buy10_Price500000_GTB20 = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Carl_Num0, ClientId: 0, ClobPairId: 0},
Side: clobtypes.Order_SIDE_BUY,
Quantums: 10,
Subticks: 500_000_000_000,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{GoodTilBlock: 20},
}
Order_Carl_Num0_Id0_Clob0_Buy80_Price500000_GTB20 = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Carl_Num0, ClientId: 0, ClobPairId: 0},
Side: clobtypes.Order_SIDE_BUY,
Quantums: 80,
Subticks: 500_000_000_000,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{GoodTilBlock: 20},
}
Order_Carl_Num0_Id2_Clob0_Sell5_Price10_GTB15 = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Carl_Num0, ClientId: 2, ClobPairId: 0},
Side: clobtypes.Order_SIDE_SELL,
Expand Down Expand Up @@ -1117,6 +1131,79 @@ var (
TimeInForce: clobtypes.Order_TIME_IN_FORCE_FILL_OR_KILL,
ReduceOnly: true,
}
Order_Alice_Num1_Id1_Clob1_Buy10_Price15_GTB20_FOK_RO = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Alice_Num1, ClientId: 1, ClobPairId: 1},
Side: clobtypes.Order_SIDE_BUY,
Quantums: 10,
Subticks: 15,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{GoodTilBlock: 20},
TimeInForce: clobtypes.Order_TIME_IN_FORCE_FILL_OR_KILL,
ReduceOnly: true,
}
Order_Alice_Num1_Id1_Clob0_Sell10_Price15_GTB20_FOK_RO = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Alice_Num1, ClientId: 1, ClobPairId: 0},
Side: clobtypes.Order_SIDE_SELL,
Quantums: 10,
Subticks: 15,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{GoodTilBlock: 20},
TimeInForce: clobtypes.Order_TIME_IN_FORCE_FILL_OR_KILL,
ReduceOnly: true,
}
Order_Alice_Num1_Id1_Clob0_Buy10_Price15_GTB20_FOK_RO = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Alice_Num1, ClientId: 1, ClobPairId: 0},
Side: clobtypes.Order_SIDE_BUY,
Quantums: 10,
Subticks: 15,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{GoodTilBlock: 20},
TimeInForce: clobtypes.Order_TIME_IN_FORCE_FILL_OR_KILL,
ReduceOnly: true,
}
// IOC + RO orders.
Order_Alice_Num1_Id1_Clob1_Sell10_Price15_GTB20_IOC_RO = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Alice_Num1, ClientId: 1, ClobPairId: 1},
Side: clobtypes.Order_SIDE_SELL,
Quantums: 10,
Subticks: 15,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{GoodTilBlock: 20},
TimeInForce: clobtypes.Order_TIME_IN_FORCE_IOC,
ReduceOnly: true,
}
Order_Alice_Num1_Id1_Clob1_Buy10_Price15_GTB20_IOC_RO = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Alice_Num1, ClientId: 1, ClobPairId: 1},
Side: clobtypes.Order_SIDE_BUY,
Quantums: 10,
Subticks: 15,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{GoodTilBlock: 20},
TimeInForce: clobtypes.Order_TIME_IN_FORCE_IOC,
ReduceOnly: true,
}
Order_Alice_Num1_Id1_Clob0_Sell10_Price15_GTB20_IOC_RO = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Alice_Num1, ClientId: 1, ClobPairId: 0},
Side: clobtypes.Order_SIDE_SELL,
Quantums: 10,
Subticks: 15,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{GoodTilBlock: 20},
TimeInForce: clobtypes.Order_TIME_IN_FORCE_IOC,
ReduceOnly: true,
}
Order_Alice_Num1_Id1_Clob0_Buy10_Price15_GTB20_IOC_RO = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Alice_Num1, ClientId: 1, ClobPairId: 0},
Side: clobtypes.Order_SIDE_BUY,
Quantums: 10,
Subticks: 15,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{GoodTilBlock: 20},
TimeInForce: clobtypes.Order_TIME_IN_FORCE_IOC,
ReduceOnly: true,
}
Order_Alice_Num1_Id1_Clob0_Sell15_Price500000_GTB20_IOC_RO = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Alice_Num1, ClientId: 1, ClobPairId: 0},
Side: clobtypes.Order_SIDE_SELL,
Quantums: 15,
Subticks: 500_000_000_000,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{GoodTilBlock: 20},
TimeInForce: clobtypes.Order_TIME_IN_FORCE_IOC,
ReduceOnly: true,
}

// Reduce-only orders.
Order_Alice_Num1_Id1_Clob0_Sell10_Price15_GTB20_RO = clobtypes.Order{
Expand Down
24 changes: 24 additions & 0 deletions protocol/testutil/constants/subaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ var (
},
PerpetualPositions: []*satypes.PerpetualPosition{},
}
Alice_Num1_1BTC_Short_100_000USD = satypes.Subaccount{
Id: &Alice_Num1,
AssetPositions: []*satypes.AssetPosition{
&Usdc_Asset_100_000,
},
PerpetualPositions: []*satypes.PerpetualPosition{
{
PerpetualId: 0,
Quantums: dtypes.NewInt(-100_000_000), // -1 BTC
},
},
}
Alice_Num1_1BTC_Long_500_000USD = satypes.Subaccount{
Id: &Alice_Num1,
AssetPositions: []*satypes.AssetPosition{
&Usdc_Asset_500_000,
},
PerpetualPositions: []*satypes.PerpetualPosition{
{
PerpetualId: 0,
Quantums: dtypes.NewInt(100_000_000), // +1 BTC
},
},
}
Bob_Num0_10_000USD = satypes.Subaccount{
Id: &Bob_Num0,
AssetPositions: []*satypes.AssetPosition{
Expand Down
Loading

0 comments on commit 0589d85

Please sign in to comment.