Closed Faouzijedidi1 closed 2 months ago
The latest updates on your projects. Learn more about Vercel for Git โ๏ธ
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
mr-market | โ Ready (Inspect) | Visit Preview | ๐ฌ Add feedback | Jul 16, 2024 1:16pm |
๐ Previously deployed to Railway in the quiet-desk project. Environment has been deleted.
โฑ๏ธ Estimated effort to review: 3 ๐ต๐ต๐ตโชโช |
๐งช PR contains tests |
๐ No security concerns identified |
โก Key issues to review Error Handling The method `getExchange` in `TradeService` throws an `InternalServerErrorException` if an exchange is not configured. This exception is generic and might not provide clear information about the actual issue. Consider throwing a more specific exception or adding more detailed error messages. Test Completeness The tests for `executeMarketTrade` and `executeLimitTrade` methods should also verify that the `updateTradeStatus` method of `TradeRepository` is called with the correct parameters after successful order creation. |
Category | Suggestion | Score |
Security |
Validate inputs in the cancelOrder function to prevent invalid operations___ **To enhance the security and reliability of thecancelOrder function, validate the inputs orderId and symbol to ensure they are not empty or invalid types before attempting to cancel the order.** [server/src/modules/trade/trade.service.ts [147]](https://github.com/Hu-Fi/Mr.Market/pull/212/files#diff-4432350be63f9e2463145381a3748ee74fcf5656391b0269244b96a3bd55bd3eR147-R147) ```diff async cancelOrder(orderId: string, symbol: string): Promise Suggestion importance[1-10]: 10Why: Validating inputs in the `cancelOrder` function is crucial for preventing invalid operations and enhancing security and reliability. | 10 |
Error handling |
Add error handling for unexpected responses from createOrder___ **Consider adding error handling for the case whenexchange.createOrder might return null or an unexpected value. This will prevent potential runtime errors and make the function more robust.** [server/src/modules/trade/trade.service.ts [76]](https://github.com/Hu-Fi/Mr.Market/pull/212/files#diff-4432350be63f9e2463145381a3748ee74fcf5656391b0269244b96a3bd55bd3eR76-R76) ```diff const order = await this.exchange.createOrder( +if (!order) { + throw new InternalServerErrorException('Failed to create order due to unexpected response.'); +} ``` Suggestion importance[1-10]: 9Why: Adding error handling for unexpected responses from `createOrder` is a good practice to prevent runtime errors and improve the robustness of the function. | 9 |
Add error handling for the updateTradeStatus method to manage exceptions___ **To avoid potential issues with unhandled promise rejections, consider adding acatch block for the updateTradeStatus method call within the cancelOrder function.**
[server/src/modules/trade/trade.service.ts [151]](https://github.com/Hu-Fi/Mr.Market/pull/212/files#diff-4432350be63f9e2463145381a3748ee74fcf5656391b0269244b96a3bd55bd3eR151-R151)
```diff
-await this.tradeRepository.updateTradeStatus(orderId, 'cancelled');
+await this.tradeRepository.updateTradeStatus(orderId, 'cancelled').catch(error => {
+ this.logger.error(`Failed to update trade status: ${error.message}`);
+ throw new InternalServerErrorException('Failed to update trade status.');
+});
```
Suggestion importance[1-10]: 8Why: Adding error handling for the `updateTradeStatus` method is a good practice to manage exceptions and avoid unhandled promise rejections. | 8 |
User description
Description
Fix trade issues
PR Type
Bug fix, Tests
Description
TradeService
to useExchangeInitService
for initializing exchanges, improving modularity and error handling.TradeService
to cover market and limit trades, as well as order cancellation scenarios.ExchangeInitService
to the providers inTradeModule
.Changes walkthrough ๐
trade.module.ts
Include ExchangeInitService in Trade module providers
server/src/modules/trade/trade.module.ts - Added `ExchangeInitService` to providers.
trade.service.spec.ts
Enhance trade service tests with exchange and cancellation
server/src/modules/trade/trade.service.spec.ts
ExchangeInitService
.trade.service.ts
Refactor trade service to use ExchangeInitService
server/src/modules/trade/trade.service.ts
ExchangeInitService
for exchange initialization.