Skip to content

Trader: add comprehensive loss detection logging - #273

Open
konard wants to merge 3 commits into
mainfrom
issue-200-bfd7e535
Open

Trader: add comprehensive loss detection logging#273
konard wants to merge 3 commits into
mainfrom
issue-200-bfd7e535

Conversation

@konard

@konard konard commented Sep 11, 2025

Copy link
Copy Markdown
Member

Summary

This PR implements comprehensive loss detection logging for the trader bot as requested in issue #200. The enhanced logging allows careful investigation of reasons for losses by tracking all scenarios where trades might result in losses.

Changes Made

1. Enhanced Loss Detection in Core Methods

  • GetMinimumSellPrice(): Added warnings when MinimumProfitSteps < 0 indicating loss selling is allowed
  • Main sell order placement: Added profit/loss logging when placing initial sell orders
  • Early sell logic: Added loss detection when selling at top bid price results in losses
  • Price change logic: Added loss detection when sell order prices are adjusted downward

2. Realized Profit/Loss Tracking

  • UpdateCashBalance(): Enhanced to track actual realized profits/losses when sell orders execute
  • Source price tracking: Utilizes ActiveSellOrderSourcePrice to compare execution price vs original buy price

3. Comprehensive Logging Strategy

  • Loss scenarios: Logged at LogWarning level for easy detection and filtering
  • Profit scenarios: Logged at LogInformation level for comparison
  • Detailed information: Each log includes source price, target price, actual amount, and lot quantity

Loss Detection Points

  1. Potential losses - When orders are configured to allow losses (MinimumProfitSteps < 0)
  2. Planned losses - When sell orders are placed below purchase price
  3. Early sell losses - When market conditions force selling at top bid price for losses
  4. Price adjustment losses - When sell order prices are changed and result in losses
  5. Realized losses - When sell trades actually execute at a loss

Configuration Context

The bot is currently configured to allow losses:

  • TMON: MinimumProfitSteps: -1 (allows 1 price step loss)
  • TRUR: MinimumProfitSteps: -2 (allows 2 price step loss)

Example Log Output

WARN: Loss detection: selling at loss allowed. Source price: 100.50, minimum sell price: 100.25, potential loss: 0.25 (-1 price steps)
WARN: Loss detection: placing sell order at LOSS. Source price: 100.50, target sell price: 100.25, actual loss: 0.25, lots: 10
WARN: Loss realized: SELL EXECUTED at LOSS. Source price: 100.50, execution price: 100.25, lots: 10, realized loss: 2.50, total revenue: 1002.50

Testing

  • Code compiles successfully with no errors
  • All new logging follows existing patterns and conventions
  • Uses proper log levels (Warning for losses, Information for profits)

Fixes #200

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #200
@konard konard self-assigned this Sep 11, 2025
konard and others added 2 commits September 11, 2025 12:50
- Enhanced GetMinimumSellPrice() with loss detection warnings when MinimumProfitSteps < 0
- Added profit/loss logging when placing sell orders to detect loss scenarios
- Added early sell loss detection with clear warnings when selling at top bid results in loss
- Added price change loss detection when sell order prices are adjusted downward
- Added realized profit/loss tracking in UpdateCashBalance() for executed sell trades
- All loss scenarios now logged with LogWarning level for easy detection and investigation
- Profit scenarios logged with LogInformation level for comparison
- Each log message includes source price, target price, actual loss/profit amount, and lot quantity

This allows careful investigation of loss reasons as requested in issue #200.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Trader: add additional log messages to detect losses Trader: add comprehensive loss detection logging Sep 11, 2025
@konard
konard marked this pull request as ready for review September 11, 2025 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trader: add additional log messages to detect losses

1 participant