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

[IND-486] update trades api with fill type #779

Merged
merged 4 commits into from
Nov 9, 2023
Merged

[IND-486] update trades api with fill type #779

merged 4 commits into from
Nov 9, 2023

Conversation

dydxwill
Copy link
Contributor

@dydxwill dydxwill commented Nov 9, 2023

Changelist

consolidate /v4/trades API endpoint response and websocket message.

Test Plan

unit tested.

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Copy link

linear bot commented Nov 9, 2023

Copy link
Contributor

coderabbitai bot commented Nov 9, 2023

# Walkthrough

The changes primarily revolve around the replacement of the `liquidation` and `deleveraging` properties with a single `type` property in various interfaces and objects across the codebase. This `type` property is of `FillType` and can take values such as "LIQUIDATION", "MARKET", or "LIMIT". The changes also involve updates to import statements, function signatures, and test cases to accommodate this new property.

# Changes

| File(s) | Change Summary |
| --- | --- |
| `.../kafka/src/constants.ts` | Updated `TRADES_WEBSOCKET_MESSAGE_VERSION` from '1.1.0' to '1.2.0'. |
| `.../postgres/src/types/websocket-message-types.ts`<br>`.../comlink/public/websocket-documentation.md`<br>`.../ender/src/handlers/order-fills/abstract-order-fill-handler.ts` | Replaced `liquidation` and `deleveraging` properties with `type` property. |
| `.../comlink/public/api-documentation.md` | Added "type" field of type "MARKET" to the data structure. |
| `.../comlink/src/request-helpers/request-transformer.ts`<br>`.../comlink/src/types.ts`<br>`.../ender/src/helpers/kafka-helper.ts` | Added or modified "type" property in various functions and interfaces. |
| `.../ender/__tests__/helpers/constants.ts`<br>`.../ender/__tests__/lib/kafka-publisher.test.ts`<br>`.../ender/__tests__/helpers/indexer-proto-helpers.ts` | Updated test cases and imports to accommodate the new `type` property. |

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9ed26bd and 3351d10.
Files ignored due to filter (1)
  • indexer/services/comlink/public/swagger.json
Files selected for processing (10)
  • indexer/packages/kafka/src/constants.ts (1 hunks)
  • indexer/packages/postgres/src/types/websocket-message-types.ts (1 hunks)
  • indexer/services/comlink/public/api-documentation.md (4 hunks)
  • indexer/services/comlink/public/websocket-documentation.md (2 hunks)
  • indexer/services/comlink/src/request-helpers/request-transformer.ts (1 hunks)
  • indexer/services/comlink/src/types.ts (1 hunks)
  • indexer/services/ender/tests/helpers/constants.ts (3 hunks)
  • indexer/services/ender/tests/helpers/indexer-proto-helpers.ts (1 hunks)
  • indexer/services/ender/tests/lib/kafka-publisher.test.ts (4 hunks)
  • indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • indexer/packages/kafka/src/constants.ts
Additional comments: 14
indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts (1)
  • 428-434: The type property is now required in the trade response object. Ensure that all consumers of this API are updated to handle this new property.
indexer/services/comlink/src/types.ts (1)
  • 174-180: The new type property of FillType is added to the TradeResponseObject interface. Ensure that all instances where TradeResponseObject is used are updated to handle this new property.
indexer/services/ender/__tests__/helpers/constants.ts (1)
  • 325-329: The type property has been added to the defaultTradeContent object. Ensure that all instances where this object is used have been updated to handle this new property.
indexer/services/comlink/src/request-helpers/request-transformer.ts (1)
  • 177-183: The new type property is correctly added to the TradeResponseObject. Ensure that all calls to this function throughout the codebase have been updated to handle the new type property.
indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts (1)
  • 807-813: The type property of the TradeMessageContents object is being set to takerFill!.type. Ensure that the type property is correctly derived from the takerFill object and that it accurately represents the type of the fill (e.g., 'maker', 'taker', 'liquidation', 'deleveraging'). If the type property is not correctly derived, it could lead to incorrect information being sent in the Kafka message.
indexer/packages/postgres/src/types/websocket-message-types.ts (1)
  • 175-179: The type property is now required in the TradeContent interface. Ensure that all instances of TradeContent in the codebase are updated to include this property.
indexer/services/ender/__tests__/lib/kafka-publisher.test.ts (2)
  • 19-25: The import statements have been reorganized for better readability and maintainability. This is a good practice as it helps in identifying the dependencies of the module at a glance.

  • 436-440: The liquidation and deleveraging properties have been replaced with type: FillType.LIMIT in the TradeContent objects. Ensure that this change is reflected in all places where these objects are used and that the type property is being correctly set based on the logic of your application.

indexer/services/comlink/public/websocket-documentation.md (2)
  • 717-717: The type property has been added to the TradeContent interface. Ensure that all instances of TradeContent in the codebase have been updated to include this property.

  • 739-763: The type property has been added to the trade objects in the example. Ensure that the logic for determining the type property is correctly implemented in the codebase.

indexer/services/comlink/public/api-documentation.md (4)
  • 1642-1642: The addition of the "type" field is consistent with the changes described in the pull request summary. Ensure that all references to this data structure in the codebase have been updated to include the "type" field.

  • 3066-3066: The addition of the "type" field is consistent with the changes described in the pull request summary. Ensure that all references to this data structure in the codebase have been updated to include the "type" field.

  • 3081-3081: The addition of the "type" field is consistent with the changes described in the pull request summary. Ensure that all references to this data structure in the codebase have been updated to include the "type" field.

  • 3100-3100: The addition of the "type" field is consistent with the changes described in the pull request summary. Ensure that all references to this data structure in the codebase have been updated to include the "type" field.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3351d10 and ea2117e.
Files selected for processing (3)
  • indexer/services/ender/tests/helpers/indexer-proto-helpers.ts (2 hunks)
  • indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts (2 hunks)
  • indexer/services/ender/src/helpers/kafka-helper.ts (2 hunks)
Additional comments: 3
indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts (1)
  • 426-429: Ensure that all references to the type property in the TradeMessageContents object have been updated throughout the codebase to reflect the new FillType enum values.
indexer/services/ender/src/helpers/kafka-helper.ts (2)
  • 2-30: The import list has been updated to include new types and remove unused ones. Ensure that these changes are reflected across the codebase.

  • 273-274: The generateOraclePriceContents function has been updated. Ensure that the changes are reflected in all calls to this function.

Comment on lines 805 to 811
price: takerFill!.price,
side: takerFill!.side.toString(),
createdAt: takerFill!.createdAt,
liquidation: isLiquidation(takerFill!),
deleveraging: isDeleveraging(takerFill!),
type: takerFill!.type,
},
],
};
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 9, 2023

Choose a reason for hiding this comment

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

The type property of the takerFill object is directly assigned to the type property of the trade object in the contents variable. This could potentially lead to incorrect data if the type property of the takerFill object does not match the expected values for the type property of the trade object. It would be safer to map the type property of the takerFill object to the corresponding value for the type property of the trade object.

- type: takerFill!.type,
+ type: mapFillTypeToTradeType(takerFill!.type),

Please ensure that the mapFillTypeToTradeType function is implemented to correctly map the type property of the takerFill object to the corresponding value for the type property of the trade object.


Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
price: takerFill!.price,
side: takerFill!.side.toString(),
createdAt: takerFill!.createdAt,
liquidation: isLiquidation(takerFill!),
deleveraging: isDeleveraging(takerFill!),
type: takerFill!.type,
},
],
};
price: takerFill!.price,
side: takerFill!.side.toString(),
createdAt: takerFill!.createdAt,
type: mapFillTypeToTradeType(takerFill!.type),
},
],
};

Copy link

Choose a reason for hiding this comment

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

I am OK with using FillType directly here. It wouldn't hurt to create a new TradeType and do the mapping, but it won't make any difference to FE at this moment.

Copy link
Contributor

Choose a reason for hiding this comment

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

@johnqh Understood. If you're confident that the FillType values will always align with the expected TradeType values, then using FillType directly should be fine. However, if there's any chance that these could diverge in the future, implementing a mapping function like mapFillTypeToTradeType could provide an extra layer of safety. But for now, we can proceed as is. Thank you for your input.

@@ -1639,6 +1639,7 @@ fetch('https://indexer.v4testnet.dydx.exchange/v4/trades/perpetualMarket/{ticker
"side": "BUY",
"size": "string",
"price": "string",
"type": "MARKET",
Copy link

Choose a reason for hiding this comment

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

I think the FillType from Indexer will never be "MARKET". FE has to use clientMetadata to derive "MARKET".

Comment on lines 805 to 811
price: takerFill!.price,
side: takerFill!.side.toString(),
createdAt: takerFill!.createdAt,
liquidation: isLiquidation(takerFill!),
deleveraging: isDeleveraging(takerFill!),
type: takerFill!.type,
},
],
};
Copy link

Choose a reason for hiding this comment

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

I am OK with using FillType directly here. It wouldn't hurt to create a new TradeType and do the mapping, but it won't make any difference to FE at this moment.

@@ -2,6 +2,6 @@ export const TO_ENDER_TOPIC: string = 'to-ender';

export const ORDERBOOKS_WEBSOCKET_MESSAGE_VERSION: string = '1.0.0';
export const SUBACCOUNTS_WEBSOCKET_MESSAGE_VERSION: string = '2.4.0';
export const TRADES_WEBSOCKET_MESSAGE_VERSION: string = '1.1.0';
export const TRADES_WEBSOCKET_MESSAGE_VERSION: string = '1.2.0';
Copy link
Contributor

Choose a reason for hiding this comment

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

Major version change? Some properties were removed and replaced with a different type of property.

Copy link

Choose a reason for hiding this comment

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

FE (Abacus) can handle the mapping from liquidation to FillType.LIQUIDATED. Not sure if any MM depends on this.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ea2117e and 7b74826.
Files selected for processing (2)
  • indexer/packages/kafka/src/constants.ts (1 hunks)
  • indexer/services/comlink/public/api-documentation.md (4 hunks)
Files skipped from review due to trivial changes (1)
  • indexer/packages/kafka/src/constants.ts
Additional comments: 4
indexer/services/comlink/public/api-documentation.md (4)
  • 1642-1642: The new "type" field is added to the data structure. Ensure that all parts of the codebase that use this structure are updated to handle the new field.

  • 3066-3066: The new "type" field is added to the data structure. Ensure that all parts of the codebase that use this structure are updated to handle the new field.

  • 3081-3081: The new "type" field is added to the data structure. Ensure that all parts of the codebase that use this structure are updated to handle the new field.

  • 3100-3100: The new "type" field is added to the data structure. Ensure that all parts of the codebase that use this structure are updated to handle the new field.

@@ -3094,6 +3097,7 @@ or
"side": "BUY",
"size": "string",
"price": "string",
"type": "LIMIT",
Copy link
Contributor

Choose a reason for hiding this comment

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

are you manually editing this? It should be autogenerated when comlink is built

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yeah, cc @johnqh

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7b74826 and 830e352.
Files selected for processing (1)
  • indexer/services/comlink/public/api-documentation.md (4 hunks)
Additional comments: 4
indexer/services/comlink/public/api-documentation.md (4)
  • 1642-1642: The addition of the "type" field to the data structure is consistent with the PR description. However, as per the previous comment by johnqh, the "type" field from the Indexer will never be "MARKET". This needs to be verified.

  • 3066-3066: The addition of the "type" field to the data structure is consistent with the PR description. However, as per the previous comment by johnqh, the "type" field from the Indexer will never be "MARKET". This needs to be verified.

  • 3081-3081: The addition of the "type" field to the data structure is consistent with the PR description. However, as per the previous comment by johnqh, the "type" field from the Indexer will never be "MARKET". This needs to be verified.

  • 3100-3100: The addition of the "type" field to the data structure is consistent with the PR description. However, as per the previous comment by johnqh, the "type" field from the Indexer will never be "MARKET". This needs to be verified.

@dydxwill dydxwill merged commit 52c8fb7 into main Nov 9, 2023
11 checks passed
@dydxwill dydxwill deleted the wl/api_change branch November 9, 2023 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants