Hu-Fi / Mr.Market

Mr. Market is the exchange oracle of HuFi, and a CeFi crypto bot on Mixin Messenger
https://mr-market-one.vercel.app
GNU Affero General Public License v3.0
1 stars 6 forks source link

Fix issue with arbitrage order #145

Closed Faouzijedidi1 closed 2 months ago

Faouzijedidi1 commented 2 months ago

Type

enhancement, bug_fix


Description


Changes walkthrough

Relevant files
Enhancement
app.module.ts
Rename Order Entity to MMOrder in AppModule Imports           

server/src/app.module.ts
  • Renamed Order entity to MMOrder in module imports and providers.
  • +2/-2     
    mm-order.entity.ts
    Rename and Update MMOrder Entity                                                 

    server/src/common/entities/mm-order.entity.ts
  • Renamed Order entity to MMOrder.
  • Made clientId column nullable.
  • +2/-2     
    orders.controller.ts
    Update OrdersController to Use MMOrder                                     

    server/src/modules/strategy/orders.controller.ts - Updated imports and method return types from `Order` to `MMOrder`.
    +2/-2     
    strategy.module.ts
    Update StrategyModule to Use MMOrder                                         

    server/src/modules/strategy/strategy.module.ts - Updated module imports and providers from `Order` to `MMOrder`.
    +2/-2     
    strategy.service.spec.ts
    Update StrategyService Spec to Use MMOrder                             

    server/src/modules/strategy/strategy.service.spec.ts - Updated mock repository token from `Order` to `MMOrder`.
    +2/-2     
    strategy.service.ts
    Refactor StrategyService to Use MMOrder                                   

    server/src/modules/strategy/strategy.service.ts
  • Updated imports, repository injections, and methods from Order to
    MMOrder.
  • +4/-4     
    Bug_fix
    arbitrage-order.entity.ts
    Make clientId Nullable in ArbitrageOrder Entity                   

    server/src/common/entities/arbitrage-order.entity.ts - Made `clientId` column nullable in `ArbitrageOrder` entity.
    +1/-1     

    PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    vercel[bot] commented 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 Apr 11, 2024 1:48am
    railway-app[bot] commented 2 months ago

    This PR is being deployed to Railway 🚅

    Mr.Market: ◻️ REMOVED

    github-actions[bot] commented 2 months ago

    PR Description updated to latest commit (https://github.com/Hu-Fi/Mr.Market/commit/9f7633b1d0dd98e1179629402711ec9d3c102a8e)

    github-actions[bot] commented 2 months ago

    PR Review

    ⏱️ Estimated effort to review [1-5] 2, because the changes are straightforward, involving renaming entities and making a column nullable. The PR touches multiple files but the nature of changes is repetitive and doesn't seem to introduce complex logic.
    🧪 Relevant tests No
    🔍 Possible issues Possible Bug: Making `clientId` nullable in `MMOrder` and `ArbitrageOrder` entities without updating related logic might introduce bugs where `clientId` is expected to be non-null.
    🔒 Security concerns No
    Code feedback:
    relevant fileserver/src/common/entities/mm-order.entity.ts
    suggestion       Consider adding a migration script for database changes, especially for making `clientId` nullable. This ensures existing databases are correctly updated without manual intervention. [important]
    relevant line@Column({ nullable: true })

    relevant fileserver/src/modules/strategy/strategy.service.ts
    suggestion       Ensure that the logic consuming `getUserOrders` method handles the case where `clientId` can be null, to avoid runtime errors. [important]
    relevant lineasync getUserOrders(userId: string): Promise {

    relevant fileserver/src/common/entities/arbitrage-order.entity.ts
    suggestion       Validate the impact of making `clientId` nullable on the business logic, especially in areas where `clientId` was previously assumed to be always present. [medium]
    relevant line@Column({ nullable: true })

    relevant fileserver/src/app.module.ts
    suggestion       After renaming `Order` to `MMOrder`, verify if any module imports or service injections need to be updated to reflect the new entity name to avoid dependency resolution issues. [medium]
    relevant lineimport { MMOrder } from './common/entities/mm-order.entity';


    ✨ Review tool usage guide:
    **Overview:** The `review` tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be [added](https://pr-agent-docs.codium.ai/tools/review/#general-configurations) by configuring the tool. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on any PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L23) related to the review tool (`pr_reviewer` section), use the following template: ``` /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_reviewer] some_config1=... some_config2=... ``` See the review [usage page](https://pr-agent-docs.codium.ai/tools/review/) for a comprehensive guide on using this tool.
    github-actions[bot] commented 2 months ago

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Correct a typo in the route path for better readability. ___ **Consider renaming the route from '/maretmaking/:userId' to '/marketmaking/:userId' to
    correct the typo and improve the API's readability.** [server/src/modules/strategy/orders.controller.ts [12]](https://github.com/Hu-Fi/Mr.Market/pull/145/files#diff-0069d0715a0f071e72068a2530df2fa7b1663ab751cc3b8f9a90d343369b516fR12-R12) ```diff -@Get('/maretmaking/:userId') +@Get('/marketmaking/:userId') ```
    Add error handling to database queries for improved robustness. ___ **When fetching user orders in getUserOrders, consider adding error handling to manage cases
    where the database query fails, improving the robustness of your application.** [server/src/modules/strategy/strategy.service.ts [710-713]](https://github.com/Hu-Fi/Mr.Market/pull/145/files#diff-413cb1b28e0d47a46768f97d10145a8e14d9e46b0a195768786127305916d944R710-R713) ```diff -return await this.orderRepository.find({ +try { + return await this.orderRepository.find({ + where: { userId }, + }); +} catch (error) { + throw new InternalServerErrorException(error); +} ```
    Best practice
    Specify column type for better database schema consistency. ___ **For the clientId column, consider adding an explicit type, such as varchar, to ensure
    consistency across different databases and to make the schema more readable.** [server/src/common/entities/mm-order.entity.ts [11]](https://github.com/Hu-Fi/Mr.Market/pull/145/files#diff-db3678ceab2b08be6527186ae21cae7c0bdb4eeedb4f035144aced59dbd28729R11-R11) ```diff -@Column({ nullable: true }) +@Column({ type: 'varchar', nullable: true }) ```
    Possible issue
    Verify the nullable attribute of clientId matches business requirements. ___ **Ensure that making clientId nullable aligns with your business logic, as it might affect
    the integrity of your data if clientId is expected to be present for certain operations.** [server/src/common/entities/arbitrage-order.entity.ts [12]](https://github.com/Hu-Fi/Mr.Market/pull/145/files#diff-ff5a2e5f3af4797869b2a42e0e031f8e629b36f0e4e628d5819683c1a44c79a6R12-R12) ```diff -@Column({ nullable: true }) +@Column({ nullable: false }) # If clientId is required ```
    Maintainability
    Organize imports in a consistent manner for better readability. ___ **Consider organizing imports in a consistent order, such as alphabetizing them or grouping
    by source location, to improve code readability and maintainability.** [server/src/app.module.ts [41]](https://github.com/Hu-Fi/Mr.Market/pull/145/files#diff-4e8033eb0f9fd87924c445b7ac0f1c1192d4890fc1589b2fad2679797d4f4ce0R41-R41) ```diff +import { ArbitrageOrder } from './common/entities/arbitrage-order.entity'; import { MMOrder } from './common/entities/mm-order.entity'; ```

    ✨ Improve tool usage guide:
    **Overview:** The `improve` tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on a PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L78) related to the improve tool (`pr_code_suggestions` section), use the following template: ``` /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_code_suggestions] some_config1=... some_config2=... ``` See the improve [usage page](https://pr-agent-docs.codium.ai/tools/improve/) for a comprehensive guide on using this tool.