Overview
TheTrade model stores individual trading records including entry/exit details, P&L, and associated metadata like images, videos, and tags.
Schema Fields
Unique identifier for the trade
- Constraint: Primary key, unique
- Default: Auto-generated UUID
The account number this trade belongs to
- Indexed: Yes (performance optimization)
- Used to group trades by account
Number of contracts/shares traded
- Must be a positive integer
Identifier for the entry order
- Default: Empty string
- Optional field for order tracking
Identifier for the closing order
- Default: Empty string
- Optional field for order tracking
Trading instrument symbol or ticker
- Examples: “ES”, “NQ”, “AAPL”
Price at which the position was entered
- Stored as string for precision
Price at which the position was closed
- Stored as string for precision
Date and time when the trade was entered
- Stored as string for flexible date formatting
Date and time when the trade was closed
- Stored as string for flexible date formatting
Profit and loss for the trade
- Can be positive (profit) or negative (loss)
Duration the position was held (in hours or minutes)
- Default: 0
ID of the user who owns this trade
- Links to the User model
Trade direction: “LONG” or “SHORT”
- Default: Empty string
Commission fees paid for this trade
- Default: 0
Timestamp when the trade record was created
- Default: Current timestamp
- Auto-generated on creation
User notes or comments about the trade
- Optional field for trade journaling
Array of tags associated with the trade
- Default: Empty array
- Used for categorization and filtering
Base64-encoded image of the trade chart
- Optional screenshot or chart image
- Legacy field (use
imagesarray for new trades)
URL to a video recording of the trade
- Optional field for video analysis
Base64-encoded secondary image
- Optional additional screenshot
- Legacy field (use
imagesarray for new trades)
ID of the group this trade belongs to
- Default: Empty string
- Indexed: Yes (performance optimization)
- Links to account groupings
Array of image URLs or Base64-encoded images
- Default: Empty array
- Replaces legacy
imageBase64fields
Indexes
The Trade model has the following indexes for query optimization:accountNumber- Fast lookup of trades by accountgroupId- Efficient filtering by group
Relationships
While the Trade model doesn’t have explicit foreign key relationships in the schema, it logically relates to:- User: Through the
userIdfield - Account: Through the
accountNumberfield - Group: Through the
groupIdfield
Database Location
This model is stored in thepublic schema of the PostgreSQL database.