Closed Faouzijedidi1 closed 1 week ago
๐ Previously deployed to Railway in the quiet-desk project. Environment has been deleted.
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 | Jun 26, 2024 9:52pm |
โฑ๏ธ Estimated effort to review [1-5] | 3 |
๐งช Relevant tests | Yes |
๐ Security concerns | No |
โก Key issues to review |
Possible Bug: The ExchangeInitService initializes exchanges in its constructor, which might not handle asynchronous initialization properly if any of the exchange APIs require async operations. This could lead to incomplete or failed initializations without proper error handling or retries. |
Hardcoded API Keys: The initialization of exchanges directly uses environment variables within the class. It's generally a better practice to inject these dependencies to make the service easier to test and configure. | |
Error Handling: The method getExchange in ExchangeInitService throws a generic InternalServerErrorException which might not be informative enough for the caller to understand the actual issue. Consider throwing more specific exceptions or returning error codes. |
Category | Suggestion | Score |
Possible issue |
Add error handling to the exchange initialization process to manage potential exceptions___ **Add error handling for theinitializeExchanges method to manage exceptions that may occur during the initialization of exchanges, such as network issues or invalid configuration.** [server/src/modules/exchangeInit/exchangeInit.service.ts [14-20]](https://github.com/Hu-Fi/Mr.Market/pull/204/files#diff-7568abcdca44efd6412caab9f5b788bcb5158285fe49e402618f72683ae16784R14-R20) ```diff private initializeExchanges() { - // Initialize exchanges - this.exchanges.set( - 'okx', - new ccxt.pro.okx({ - apiKey: process.env.OKX_API_KEY, - secret: process.env.OKX_SECRET, - }), - ); + try { + // Initialize exchanges + this.exchanges.set( + 'okx', + new ccxt.pro.okx({ + apiKey: this.configService.get('OKX_API_KEY'), + secret: this.configService.get('OKX_SECRET'), + }), + ); + // Add other exchanges similarly + } catch (error) { + this.logger.error('Failed to initialize exchanges', error); + throw new InternalServerErrorException('Failed to initialize exchanges'); + } } ``` Suggestion importance[1-10]: 10Why: Adding error handling is crucial for robustness, ensuring that the system can gracefully handle initialization failures. | 10 |
Security |
Improve security by using a configuration service to manage environment variables___ **Consider using environment variables more securely by not directly accessingprocess.env within the ExchangeInitService . Instead, use a configuration service that can provide these values. This approach improves security by centralizing the management of environment variables and potentially integrating with secret management tools.** [server/src/modules/exchangeInit/exchangeInit.service.ts [19-20]](https://github.com/Hu-Fi/Mr.Market/pull/204/files#diff-7568abcdca44efd6412caab9f5b788bcb5158285fe49e402618f72683ae16784R19-R20) ```diff -apiKey: process.env.OKX_API_KEY, -secret: process.env.OKX_SECRET, +apiKey: this.configService.get('OKX_API_KEY'), +secret: this.configService.get('OKX_SECRET'), ``` Suggestion importance[1-10]: 9Why: This suggestion enhances security by centralizing environment variable management, reducing the risk of exposing sensitive information. | 9 |
Maintainability |
Refactor repetitive exchange setup code into a loop for better maintainability___ **Refactor the repetitive code for setting up each exchange into a loop that iterates over aconfiguration object. This will reduce the amount of code and make it easier to add or remove exchanges in the future.** [server/src/modules/exchangeInit/exchangeInit.service.ts [16-20]](https://github.com/Hu-Fi/Mr.Market/pull/204/files#diff-7568abcdca44efd6412caab9f5b788bcb5158285fe49e402618f72683ae16784R16-R20) ```diff -this.exchanges.set( - 'okx', - new ccxt.pro.okx({ - apiKey: process.env.OKX_API_KEY, - secret: process.env.OKX_SECRET, - }), -); +const exchangeConfigs = [ + { name: 'okx', type: ccxt.pro.okx }, + { name: 'bitfinex', type: ccxt.pro.bitfinex }, + // Add other exchanges here +]; +exchangeConfigs.forEach(config => { + this.exchanges.set( + config.name, + new config.type({ + apiKey: this.configService.get(`${config.name.toUpperCase()}_API_KEY`), + secret: this.configService.get(`${config.name.toUpperCase()}_SECRET`), + }) + ); +}); ``` Suggestion importance[1-10]: 8Why: This refactoring improves code maintainability and readability by reducing redundancy and making it easier to add or remove exchanges. | 8 |
Best practice |
Adjust the
___
**Ensure that the | 7 |
User description
Description
Add exchange init service Add Bigone, BitMart, and Lbank to supported exchanges.
Summary of changes
How to test the changes
PR Type
Enhancement, Tests
Description
ExchangeInitService
to manage and initialize exchange instances.StrategyService
to useExchangeInitService
for exchange management.ExchangeInitService
..env.example
with API keys and secrets for Lbank, Bigone, and BitMart exchanges.Changes walkthrough ๐
app.module.ts
Add ExchangeInitService to AppModule providers
server/src/app.module.ts - Added `ExchangeInitService` to the providers array.
exchangeInit.service.ts
Implement ExchangeInitService for managing exchanges
server/src/modules/exchangeInit/exchangeInit.service.ts
ExchangeInitService
to initialize and manage exchangeinstances.
strategy.service.ts
Refactor StrategyService to use ExchangeInitService
server/src/modules/strategy/strategy.service.ts
ExchangeInitService
for exchange management.exchangeInit.service.spec.ts
Add unit tests for ExchangeInitService
server/src/modules/exchangeInit/exchangeInit.service.spec.ts
ExchangeInitService
..env.example
Update .env.example with new exchange credentials
server/.env.example