Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 11, 2025

Summary

This PR implements the features requested in issue #202:

  • Automatic sell before market close: Optional feature that can be enabled via configuration to automatically sell all positions before the market closes
  • Profit/loss limits during sell: Ability to set maximum profit and loss percentages that trigger automatic sells when reached

Key Features

1. Auto-sell before market close

  • New EnableAutoSellBeforeMarketClose boolean setting (default: false)
  • New AutoSellMarketCloseTime setting to specify when to trigger auto-sell (format: "HH:mm:ss")
  • When enabled, the bot will sell all positions at the current bid price to ensure execution before market close

2. Profit/Loss limits

  • New MaxProfitPercent setting (optional, nullable decimal) - triggers sell when profit reaches this percentage
  • New MaxLossPercent setting (optional, nullable decimal) - triggers sell when loss reaches this percentage
  • Profit/loss calculation based on purchase price vs current bid price

3. Configuration flexibility

  • Both features are optional and can be independently enabled/disabled
  • Updated existing configuration files with examples
  • TMON configuration has features disabled by default
  • TRUR configuration demonstrates enabled features with reasonable limits

Implementation details

  • Added new properties to TradingSettings class
  • Enhanced TradingService with helper methods for checking conditions
  • Integrated checks into both no-active-orders and active-sell-orders scenarios
  • Uses bid price for emergency sells to ensure quick execution
  • Comprehensive logging for all new functionality

Test plan

  • Code compiles without errors
  • Build succeeds with existing warnings (not related to new features)
  • Configuration files are valid JSON
  • New settings are properly logged on startup
  • Example files demonstrate proper usage
  • Both optional features can be disabled independently

Files changed

  • TradingSettings.cs: Added new configuration properties
  • TradingService.cs: Implemented auto-sell logic and profit/loss checking
  • appsettings.TMON.json: Updated with disabled features as example
  • appsettings.TRUR.json: Updated with enabled features as example
  • examples/: Added example configuration and test files

🤖 Generated with Claude Code


Resolves #202

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

Issue: #202
@konard konard self-assigned this Sep 11, 2025
konard and others added 2 commits September 11, 2025 12:44
- Add EnableAutoSellBeforeMarketClose optional setting
- Add AutoSellMarketCloseTime configuration
- Add MaxProfitPercent and MaxLossPercent limits
- Implement automatic sell logic in TradingService
- Update configuration files with new settings
- Add examples and test files for the new features

Resolves #202

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

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Trader: add automatic sell just before market is closed (it should be optional) Trader: Add automatic sell before market close and profit/loss limits Sep 11, 2025
@konard konard marked this pull request as ready for review September 11, 2025 09:50
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 automatic sell just before market is closed (it should be optional)

2 participants