Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Conversation

@mzkrasner
Copy link
Collaborator

Implementation of Required Trade Reason Field

This PR adds a requirement for teams to provide a reason when executing trades in the trading simulator, enhancing transparency and providing valuable context for trading decisions.

Changes Implemented:

Database Layer:

  • Added a required reason TEXT NOT NULL column to the trades table in the database schema
  • Updated SQL queries to include the new field

Type Definitions:

  • Modified the Trade interface to include the required reason field
  • Updated TradeExecutionParams in API types to reflect the new required parameter

Repository Layer:

  • Updated the TradeRepository.create() method to handle the new field
  • Modified the mapToEntity() method to map the reason field from database rows

Service Layer:

  • Added the required reason parameter to the TradeSimulator.executeTrade() method
  • Implemented validation to ensure a reason is provided for each trade
  • Included the reason in trade record creation and API responses

Controller Layer:

  • Updated the TradeController.executeTrade() method to extract the reason from request body
  • Added validation to ensure requests include the reason parameter
  • Passed the reason field to the trade simulator service

API Documentation:

  • Updated the OpenAPI documentation for the /trade/execute endpoint to include the reason field
  • Updated trade response schema to include the reason field
  • Updated the account trade history endpoint documentation

Testing:

  • Updated E2E tests to include the reason parameter in all trade execution calls
  • Made consistent use of the team client's executeTrade() method across tests
  • Added a specific test to verify the reason field is correctly:
    • Received in the immediate trade execution response
    • Persisted and retrievable from the trade history endpoint
    • Preserved exactly as provided by the client

This change improves the quality of trading data by ensuring teams document their reasoning for trades, which will be valuable for:

  1. Competition evaluation and analysis
  2. Understanding algorithmic trading strategies
  3. Providing context for teams' trading decisions
  4. Creating a more transparent and auditable trading system

The implementation ensures backward compatibility with the existing API structure while enforcing this new requirement for better data quality.

@mzkrasner mzkrasner merged commit 48d4069 into main Apr 23, 2025
3 checks passed
@mzkrasner mzkrasner deleted the feat/trade-reason branch April 23, 2025 18:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants