Skip to content

Commit

Permalink
[CLOB-1007] add protos for final settlement clob pair status and remo…
Browse files Browse the repository at this point in the history
…val reason (#828)

* add protos for final settlement clob pair status and final settlement removal reason

* add missing indexer constants

* update proto formatting

* fix indexer test

* update comment and panic string

* update broken test
  • Loading branch information
jakob-dydx authored Dec 5, 2023
1 parent 9e08e81 commit f2e78ba
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 129 deletions.
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,14 @@ 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. Open stateful orders will be cancelled. Open short-term
* orders will be left to expire.
*/
STATUS_FINAL_SETTLEMENT = 6,
UNRECOGNIZED = -1,
}
/** Status of the CLOB. */
Expand Down Expand Up @@ -68,6 +76,14 @@ 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. Open stateful orders will be cancelled. Open short-term
* orders will be left to expire.
*/
STATUS_FINAL_SETTLEMENT = 6,
UNRECOGNIZED = -1,
}
export function clobPair_StatusFromJSON(object: any): ClobPair_Status {
Expand Down Expand Up @@ -96,6 +112,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 +142,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. */
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":
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
5 changes: 5 additions & 0 deletions proto/dydxprotocol/clob/clob_pair.proto
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ 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. Open stateful orders will be cancelled. Open short-term
// orders will be left to expire.
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.

9 changes: 8 additions & 1 deletion protocol/indexer/protocol/v1/v1_mappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,14 @@ 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")
panic(
fmt.Sprintf(
"ConvertToClobPairStatus: invalid clob pair status: %+v",
status,
),
)
}
}
Loading

0 comments on commit f2e78ba

Please sign in to comment.