Closed Faouzijedidi1 closed 2 months ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Updated (UTC) |
---|---|---|---|
mr-market | ✅ Ready (Inspect) | Visit Preview | Apr 11, 2024 2:14am |
This PR is being deployed to Railway 🚅
PR Description updated to latest commit (https://github.com/Hu-Fi/Mr.Market/commit/fb2c2ef67dcb679dbbc635c27c44330ee8e9969d)
⏱️ Estimated effort to review [1-5] | 2, because the changes are straightforward, involving renaming and making fields nullable. The logic seems not to be heavily altered, which simplifies the review process. However, understanding the context and implications of these changes on the system's behavior requires some domain knowledge. |
🧪 Relevant tests | No |
🔍 Possible issues | Nullable Fields: Making several fields nullable in entities might introduce unexpected behavior or errors if the rest of the application does not handle null values properly. This is especially critical for fields like `amount`, `price`, `profit`, which are essential for financial calculations. |
🔒 Security concerns | No |
relevant file | server/src/common/entities/arbitrage-order.entity.ts |
suggestion | Consider implementing validation logic for nullable fields to ensure that when they are provided, they meet the expected format or range. This can prevent potential issues with data integrity and application logic. [important] |
relevant line | @Column({ nullable: true }) |
relevant file | server/src/common/entities/mm-order.entity.ts |
suggestion | Ensure that the application logic that interacts with `MMOrder` entities correctly handles cases where `amount` and `price` are null, to avoid runtime errors during financial calculations. [important] |
relevant line | @Column('decimal', { precision: 10, scale: 2, nullable: true }) |
relevant file | server/src/modules/strategy/strategy.service.ts |
suggestion | After renaming fields in `ArbitrageOrder`, verify that all references to these fields across the application are updated to prevent any issues with undefined properties. This includes checking any serialization/deserialization logic that might rely on the old field names. [important] |
relevant line | exchangeAName: exchangeA.name, |
relevant file | server/src/common/entities/arbitrage-order.entity.ts |
suggestion | For fields that are now nullable, consider adding logic to handle default values or fallback mechanisms where it makes sense, to maintain the robustness of the application's functionality. [medium] |
relevant line | @Column({ nullable: true }) |
Category | Suggestions |
Best practice |
Add explicit type annotations for new entity columns.___ **Consider adding explicit type annotations for the new columns to ensure clarity andmaintainability. TypeScript can infer types, but explicit types for entity columns can make the code more robust and easier to understand for new developers or when revisiting the code after some time.** [server/src/common/entities/arbitrage-order.entity.ts [18-25]](https://github.com/Hu-Fi/Mr.Market/pull/146/files#diff-ff5a2e5f3af4797869b2a42e0e031f8e629b36f0e4e628d5819683c1a44c79a6R18-R25) ```diff -@Column({ nullable: true }) +@Column({ type: 'varchar', nullable: true }) exchangeAName: string; -@Column({ nullable: true }) +@Column({ type: 'varchar', nullable: true }) exchangeBName: string; -@Column('decimal', { precision: 10, scale: 2, nullable: true }) +@Column({ type: 'decimal', precision: 10, scale: 2, nullable: true }) amount: number; ``` |
Use enums for fields with specific allowed values.___ **Given thatstatus and strategy fields have specific allowed values ('open', 'closed', 'canceled' for status and 'arbitrage', 'market-making', etc. for strategy ), consider using TypeScript enums to enforce these constraints at the type level. This approach enhances code readability and maintainability.** [server/src/common/entities/arbitrage-order.entity.ts [39-43]](https://github.com/Hu-Fi/Mr.Market/pull/146/files#diff-ff5a2e5f3af4797869b2a42e0e031f8e629b36f0e4e628d5819683c1a44c79a6R39-R43) ```diff -@Column({ nullable: true }) -status: string; // 'open', 'closed', 'canceled' +enum Status { + Open = 'open', + Closed = 'closed', + Canceled = 'canceled', +} -@Column({ nullable: true }) -strategy: string; // 'arbitrage', 'market-making', etc. +enum Strategy { + Arbitrage = 'arbitrage', + MarketMaking = 'market-making', +} +@Column({ type: 'enum', enum: Status, nullable: true }) +status: Status; + +@Column({ type: 'enum', enum: Strategy, nullable: true }) +strategy: Strategy; + ``` | |
Use enums for the
___
**For the | |
Enhancement |
Ensure
___
**For the |
Security |
Validate or sanitize exchange names to prevent security vulnerabilities.___ **Ensure thatexchangeA.name and exchangeB.name are validated or sanitized before being used to prevent potential security vulnerabilities, such as injection attacks. Consider implementing a validation layer if not already present.** [server/src/modules/strategy/strategy.service.ts [669-670]](https://github.com/Hu-Fi/Mr.Market/pull/146/files#diff-413cb1b28e0d47a46768f97d10145a8e14d9e46b0a195768786127305916d944R669-R670) ```diff -exchangeAName: exchangeA.name, -exchangeBName: exchangeB.name, +exchangeAName: sanitizeExchangeName(exchangeA.name), +exchangeBName: sanitizeExchangeName(exchangeB.name), ``` |
Type
enhancement
Description
ArbitrageOrder
andMMOrder
entities to support nullable fields for increased flexibility in order handling.ArbitrageOrder
entity frombuyExchange
andsellExchange
toexchangeAName
andexchangeBName
for clarity.StrategyService
to align with the renaming of exchange fields in theArbitrageOrder
entity.Changes walkthrough
arbitrage-order.entity.ts
Refactor ArbitrageOrder Entity for Flexibility
server/src/common/entities/arbitrage-order.entity.ts
buyExchange
andsellExchange
columns nullable and renamed them toexchangeAName
andexchangeBName
.amount
,buyPrice
,sellPrice
,profit
,executedAt
,status
, andstrategy
columns nullable.mm-order.entity.ts
Update MMOrder Entity to Support Optional Fields
server/src/common/entities/mm-order.entity.ts
amount
andprice
columns nullable to allow for flexibility inorder handling.
strategy
column to be nullable, aligning with changes inarbitrage orders.
strategy.service.ts
Align Strategy Service with Entity Renaming
server/src/modules/strategy/strategy.service.ts
buyExchange
andsellExchange
toexchangeAName
and
exchangeBName
in strategy service.