Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLOB-1007] add protos for final settlement clob pair status and removal reason #828

Merged
merged 6 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions indexer/packages/postgres/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Record<SpecifiedClobPairStatus, PerpetualMarketStatus> = {
[ClobPairStatus.CLOB_PAIR_STATUS_PAUSED]: PerpetualMarketStatus.PAUSED,
[ClobPairStatus.CLOB_PAIR_STATUS_POST_ONLY]: PerpetualMarketStatus.POST_ONLY,
[ClobPairStatus.CLOB_PAIR_STATUS_INITIALIZING]: PerpetualMarketStatus.INITIALIZING,
[ClobPairStatus.CLOB_PAIR_STATUS_FINAL_SETTLEMENT]: PerpetualMarketStatus.FINAL_SETTLEMENT,
};

export const DEFAULT_POSTGRES_OPTIONS : Options = config.USE_READ_REPLICA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ export enum PerpetualMarketStatus {
CANCEL_ONLY = 'CANCEL_ONLY',
POST_ONLY = 'POST_ONLY',
INITIALIZING = 'INITIALIZING',
FINAL_SETTLEMENT = 'FINAL_SETTLEMENT',
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export enum ClobPair_Status {
* both short-term and post-only.
*/
STATUS_INITIALIZING = 5,

/**
* STATUS_FINAL_SETTLEMENT - STATUS_FINAL_SETTLEMENT represents a clob pair which is deactivated
* and trading has ceased. All open positions will be closed by the
* protocol.
*/
STATUS_FINAL_SETTLEMENT = 6,
UNRECOGNIZED = -1,
}
/** Status of the CLOB. */
Expand Down Expand Up @@ -68,6 +75,13 @@ export enum ClobPair_StatusSDKType {
* both short-term and post-only.
*/
STATUS_INITIALIZING = 5,

/**
* STATUS_FINAL_SETTLEMENT - STATUS_FINAL_SETTLEMENT represents a clob pair which is deactivated
* and trading has ceased. All open positions will be closed by the
* protocol.
*/
STATUS_FINAL_SETTLEMENT = 6,
UNRECOGNIZED = -1,
}
export function clobPair_StatusFromJSON(object: any): ClobPair_Status {
Expand Down Expand Up @@ -96,6 +110,10 @@ export function clobPair_StatusFromJSON(object: any): ClobPair_Status {
case "STATUS_INITIALIZING":
return ClobPair_Status.STATUS_INITIALIZING;

case 6:
case "STATUS_FINAL_SETTLEMENT":
return ClobPair_Status.STATUS_FINAL_SETTLEMENT;

case -1:
case "UNRECOGNIZED":
default:
Expand All @@ -122,6 +140,9 @@ export function clobPair_StatusToJSON(object: ClobPair_Status): string {
case ClobPair_Status.STATUS_INITIALIZING:
return "STATUS_INITIALIZING";

case ClobPair_Status.STATUS_FINAL_SETTLEMENT:
return "STATUS_FINAL_SETTLEMENT";

case ClobPair_Status.UNRECOGNIZED:
default:
return "UNRECOGNIZED";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ export enum ClobPairStatus {
* both short-term and post-only.
*/
CLOB_PAIR_STATUS_INITIALIZING = 5,

/**
* CLOB_PAIR_STATUS_FINAL_SETTLEMENT - CLOB_PAIR_STATUS_FINAL_SETTLEMENT represents a clob pair that has been
* deactivated. Clob pairs in this state do not accept new orders and trading
* is blocked. All open positions are closed by the protocol when the clob
* pair gains this status.
*/
CLOB_PAIR_STATUS_FINAL_SETTLEMENT = 6,
UNRECOGNIZED = -1,
}
/**
Expand Down Expand Up @@ -348,6 +356,14 @@ export enum ClobPairStatusSDKType {
* both short-term and post-only.
*/
CLOB_PAIR_STATUS_INITIALIZING = 5,

/**
* CLOB_PAIR_STATUS_FINAL_SETTLEMENT - CLOB_PAIR_STATUS_FINAL_SETTLEMENT represents a clob pair that has been
* deactivated. Clob pairs in this state do not accept new orders and trading
* is blocked. All open positions are closed by the protocol when the clob
* pair gains this status.
*/
CLOB_PAIR_STATUS_FINAL_SETTLEMENT = 6,
UNRECOGNIZED = -1,
}
export function clobPairStatusFromJSON(object: any): ClobPairStatus {
Expand Down Expand Up @@ -376,6 +392,10 @@ export function clobPairStatusFromJSON(object: any): ClobPairStatus {
case "CLOB_PAIR_STATUS_INITIALIZING":
return ClobPairStatus.CLOB_PAIR_STATUS_INITIALIZING;

case 6:
case "CLOB_PAIR_STATUS_FINAL_SETTLEMENT":
return ClobPairStatus.CLOB_PAIR_STATUS_FINAL_SETTLEMENT;

case -1:
case "UNRECOGNIZED":
default:
Expand All @@ -402,6 +422,9 @@ export function clobPairStatusToJSON(object: ClobPairStatus): string {
case ClobPairStatus.CLOB_PAIR_STATUS_INITIALIZING:
return "CLOB_PAIR_STATUS_INITIALIZING";

case ClobPairStatus.CLOB_PAIR_STATUS_FINAL_SETTLEMENT:
return "CLOB_PAIR_STATUS_FINAL_SETTLEMENT";

case ClobPairStatus.UNRECOGNIZED:
default:
return "UNRECOGNIZED";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export enum OrderRemovalReason {
* equity tier requirements.
*/
ORDER_REMOVAL_REASON_EQUITY_TIER = 13,

/** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed since its ClobPair has entered final settlement. */
ORDER_REMOVAL_REASON_FINAL_SETTLEMENT = 14,
UNRECOGNIZED = -1,
}
/** OrderRemovalReason is an enum of all the reasons an order was removed. */
Expand Down Expand Up @@ -155,6 +158,9 @@ export enum OrderRemovalReasonSDKType {
* equity tier requirements.
*/
ORDER_REMOVAL_REASON_EQUITY_TIER = 13,

/** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed since its ClobPair has entered final settlement. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment for ORDER_REMOVAL_REASON_FINAL_SETTLEMENT in the OrderRemovalReasonSDKType enum should be updated to match the new wording in the OrderRemovalReason enum for consistency.

-  /** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed since its ClobPair has entered final settlement. */
+  /** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed due to final settlement of its ClobPair. */

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
/** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed since its ClobPair has entered final settlement. */
/** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed due to final settlement of its ClobPair. */

ORDER_REMOVAL_REASON_FINAL_SETTLEMENT = 14,
UNRECOGNIZED = -1,
}
export function orderRemovalReasonFromJSON(object: any): OrderRemovalReason {
Expand Down Expand Up @@ -215,6 +221,10 @@ export function orderRemovalReasonFromJSON(object: any): OrderRemovalReason {
case "ORDER_REMOVAL_REASON_EQUITY_TIER":
return OrderRemovalReason.ORDER_REMOVAL_REASON_EQUITY_TIER;

case 14:
case "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment for ORDER_REMOVAL_REASON_FINAL_SETTLEMENT in the orderRemovalReasonFromJSON and orderRemovalReasonToJSON functions should be updated to match the new wording in the OrderRemovalReason enum for consistency.

-    case "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT":
+    case "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed due to final settlement of its ClobPair.":

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
case "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT":
case "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed due to final settlement of its ClobPair.":

return OrderRemovalReason.ORDER_REMOVAL_REASON_FINAL_SETTLEMENT;

case -1:
case "UNRECOGNIZED":
default:
Expand Down Expand Up @@ -265,6 +275,9 @@ export function orderRemovalReasonToJSON(object: OrderRemovalReason): string {
case OrderRemovalReason.ORDER_REMOVAL_REASON_EQUITY_TIER:
return "ORDER_REMOVAL_REASON_EQUITY_TIER";

case OrderRemovalReason.ORDER_REMOVAL_REASON_FINAL_SETTLEMENT:
return "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT";

case OrderRemovalReason.UNRECOGNIZED:
default:
return "UNRECOGNIZED";
Expand Down
1 change: 1 addition & 0 deletions indexer/services/comlink/public/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,7 @@ or
|*anonymous*|CANCEL_ONLY|
|*anonymous*|POST_ONLY|
|*anonymous*|INITIALIZING|
|*anonymous*|FINAL_SETTLEMENT|

## PerpetualMarketResponseObject

Expand Down
3 changes: 2 additions & 1 deletion indexer/services/comlink/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,8 @@
"PAUSED",
"CANCEL_ONLY",
"POST_ONLY",
"INITIALIZING"
"INITIALIZING",
"FINAL_SETTLEMENT"
],
"type": "string"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ BEGIN
WHEN '3'::jsonb THEN RETURN 'CANCEL_ONLY'; /** CLOB_PAIR_STATUS_CANCEL_ONLY */
WHEN '4'::jsonb THEN RETURN 'POST_ONLY'; /** CLOB_PAIR_STATUS_POST_ONLY */
WHEN '5'::jsonb THEN RETURN 'INITIALIZING'; /** CLOB_PAIR_STATUS_INITIALIZING */
WHEN '6'::jsonb THEN RETURN 'FINAL_SETTLEMENT'; /** CLOB_PAIR_STATUS_FINAL_SETTLEMENT */
ELSE RAISE EXCEPTION 'Invalid clob pair status: %', status;
END CASE;
END;
Expand Down
4 changes: 4 additions & 0 deletions proto/dydxprotocol/clob/clob_pair.proto
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ message ClobPair {
// Clob pairs in this state only accept orders which are
// both short-term and post-only.
STATUS_INITIALIZING = 5;
// STATUS_FINAL_SETTLEMENT represents a clob pair which is deactivated
// and trading has ceased. All open positions will be closed by the
// protocol.
jakob-dydx marked this conversation as resolved.
Show resolved Hide resolved
STATUS_FINAL_SETTLEMENT = 6;
}

Status status = 7;
Expand Down
5 changes: 5 additions & 0 deletions proto/dydxprotocol/indexer/protocol/v1/clob.proto
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,9 @@ enum ClobPairStatus {
// Clob pairs in this state only accept orders which are
// both short-term and post-only.
CLOB_PAIR_STATUS_INITIALIZING = 5;
// CLOB_PAIR_STATUS_FINAL_SETTLEMENT represents a clob pair that has been
// deactivated. Clob pairs in this state do not accept new orders and trading
// is blocked. All open positions are closed by the protocol when the clob
// pair gains this status.
CLOB_PAIR_STATUS_FINAL_SETTLEMENT = 6;
}
2 changes: 2 additions & 0 deletions proto/dydxprotocol/indexer/shared/removal_reason.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ enum OrderRemovalReason {
// The order has been removed since the subaccount does not satisfy the
// equity tier requirements.
ORDER_REMOVAL_REASON_EQUITY_TIER = 13;
// The order has been removed since its ClobPair has entered final settlement.
ORDER_REMOVAL_REASON_FINAL_SETTLEMENT = 14;
}
122 changes: 65 additions & 57 deletions protocol/indexer/protocol/v1/clob.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions protocol/indexer/protocol/v1/v1_mappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ func ConvertToClobPairStatus(status clobtypes.ClobPair_Status) ClobPairStatus {
return ClobPairStatus_CLOB_PAIR_STATUS_POST_ONLY
case clobtypes.ClobPair_STATUS_INITIALIZING:
return ClobPairStatus_CLOB_PAIR_STATUS_INITIALIZING
case clobtypes.ClobPair_STATUS_FINAL_SETTLEMENT:
return ClobPairStatus_CLOB_PAIR_STATUS_FINAL_SETTLEMENT
default:
panic("invalid clob pair status")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using panic in the default case of the switch statement can be dangerous as it will cause the application to crash if an unexpected status is encountered. Consider handling this case more gracefully, possibly by returning an error that can be handled by the caller, to avoid crashing the entire application.

jakob-dydx marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Loading
Loading