Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 11, 2025

Summary

This PR implements buy prevention logic to avoid buying when market conditions make it difficult to sell later at a profit, addressing issue #224.

Changes Made

  • New Configuration Settings:

    • MaxSpreadPercentToBuy: Maximum allowed bid-ask spread percentage (default: 1.0%)
    • MinimumCombinedLiquidityToBuy: Minimum required combined liquidity at best bid/ask (default: 1,000,000)
  • New Market Condition Checks:

    • Added IsMarketConditionsSuitableForBuying() method that checks:
      • Bid-ask spread is not too wide (prevents buying when spread makes profit difficult)
      • Combined market liquidity is sufficient (prevents buying in illiquid markets)
  • Applied Prevention Logic to:

    • Initial buy order placement (line ~473)
    • Buy order price change logic (line ~521)
    • Automatic buy order cancellation when conditions become unsuitable

Configuration Updates

Updated both appsettings.TMON.json and appsettings.TRUR.json with sensible default values:

  • MaxSpreadPercentToBuy: 1.0% (prevents buying when spread is too wide)
  • MinimumCombinedLiquidityToBuy: 1,000,000 (ensures sufficient market liquidity)

How It Works

The bot will now refuse to buy when:

  1. Wide Spreads: The bid-ask spread exceeds the configured percentage threshold
  2. Low Liquidity: The combined order size at best bid and ask is below the minimum threshold

This prevents the scenario described in issue #224 where the bot would buy in conditions that make it "much harder to sell" later.

Test Plan

  • Code compiles successfully in both Debug and Release modes
  • No runtime errors introduced
  • Configuration settings properly logged on startup
  • Buy prevention logic applied to all relevant code paths

Related Issues

Fixes #224

🤖 Generated with Claude Code

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

Issue: #224
@konard konard self-assigned this Sep 11, 2025
konard and others added 2 commits September 11, 2025 12:04
- Add MaxSpreadPercentToBuy and MinimumCombinedLiquidityToBuy settings
- Add IsMarketConditionsSuitableForBuying method to check market conditions
- Prevent buying when bid-ask spread is too wide (configurable threshold)
- Prevent buying when market liquidity is too low (configurable threshold)
- Apply conditions to both initial buy orders and buy order price changes
- Update configuration files with sensible default values (1.0% max spread, 1M minimum liquidity)

Fixes #224

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

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Trader Bot: Do not buy in this case Trader Bot: Implement buy prevention logic for problematic market conditions Sep 11, 2025
@konard konard marked this pull request as ready for review September 11, 2025 09:12
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 Bot: Do not buy in this case

2 participants