Skip to content

Conversation

@Yebon56
Copy link
Collaborator

@Yebon56 Yebon56 commented Jan 14, 2026

Strategies Overview

1. Step Jump Capture Strategy

Target markets

  • Sports prediction markets
  • Other event-driven markets with discrete, step-like price movements

Logic

  • Selects the underdog outcome at strategy start (lowest ask).
  • Accumulates inventory when price trades within a fixed absolute “cheap” band.
  • Monitors recent ask prices to detect a step-up jump over a short rolling window.
  • Once a jump is detected, immediately sells the entire inventory at the best bid.
  • Designed for markets where prices move in abrupt regime shifts rather than smooth mean reversion.

2. Dump Hedge Strategy

Target markets

  • Short-horizon crypto price prediction markets
    (e.g. 15-minute up/down markets)

Logic

  • Watches the initial minutes of trading for a rapid downside move (“dump”).
  • Leg 1: Buys the dumped outcome at the current ask.
  • Leg 2: Buys the opposite outcome when the sum of entry prices falls below a predefined threshold.
  • Captures temporary mispricing caused by short-term panic selling.

Reference

@claude
Copy link

claude bot commented Jan 14, 2026

Pull Request Review: Add Jump Strategy and Dump Hedge Strategy

Overview

This PR adds two new trading strategies for prediction markets:

  1. Step Jump Capture Strategy (jump_strategy.py) - Accumulates inventory when price is cheap and sells all on a step-up jump
  2. Dump Hedge Strategy (dump_hedge_strategy.py) - Watches for rapid price dumps and executes a two-leg hedge

Code Quality & Best Practices

Strengths

  • Well-structured code: Both strategies properly inherit from the base Strategy class
  • Clear documentation: Good docstrings explaining the strategy logic and parameters
  • Type hints: Comprehensive type annotations throughout
  • Test mode support: Safe testing without placing real orders (good default behavior)
  • Configurable parameters: Flexible CLI arguments for tuning strategy parameters
  • Proper state management: Using dataclasses for clean state tracking

Issues & Recommendations

1. Violation of CLAUDE.md Guidelines

Per CLAUDE.md Rule 4: "Single Source of Truth: DO NOT place many variables in .env file. Place them in the code instead."

Both strategies use os.getenv() for defaults in multiple places:

  • dump_hedge_strategy.py:321-336
  • jump_strategy.py:397-425

Recommendation: Remove .env references and use hardcoded defaults only. Environment variables should be eliminated unless absolutely necessary.

2. Code Duplication

The find_market_id() function is duplicated in both files (276-315 in dump_hedge, 352-391 in jump_strategy). This is nearly identical code (~40 lines).

Recommendation: Extract this to a shared utility module (e.g., dr_manhattan/utils/market_helpers.py) or enhance the existing prompt_market_selection utility.

3. Error Handling - Silent Failures

Multiple locations have bare except Exception: that pass silently without logging:

  • dump_hedge_strategy.py:109, 297
  • jump_strategy.py:136, 373

Recommendation: Log errors or at minimum add a comment explaining why silent failure is acceptable.

# Before
except Exception:
    pass

# After  
except Exception as e:
    logger.debug(f"Failed to cancel orders during shutdown: {e}")

4. Potential Logic Issue - Inventory Tracking in Test Mode

In jump_strategy.py, the strategy tracks inventory_shares and updates it even in test mode:

  • Lines 216-218: self.state.inventory_shares += self.shares
  • Lines 251: self.state.inventory_shares = 0.0

However, in test mode no orders are actually placed, so the inventory tracking becomes fictional. This could lead to confusing test results where the strategy thinks it has inventory but doesn't.

Recommendation: Either skip inventory tracking in test mode or add clear warnings that test mode inventory is simulated.

5. Magic Numbers

Several magic values could be constants:

  • maxlen=50 (line 89, dump_hedge) and maxlen=300 (line 114, jump_strategy)
  • Loop range range(1, 6) for pagination (lines 291, 367)

Recommendation: Define as named constants at module level.

ASK_HISTORY_MAXLEN = 50
MAX_MARKET_SEARCH_PAGES = 5

Potential Bugs

1. Race Condition in Dump Hedge Strategy

Location: dump_hedge_strategy.py:152-153

while hist and (now - hist[0][0]) > self.dump_window_seconds:
    hist.popleft()

After this while loop clears old data, there's no guarantee hist[0] exists when accessed at line 158. While there's a check at line 155 (if len(hist) < 2), the deque could theoretically be emptied between checks in a concurrent scenario.

Severity: Low (unlikely in single-threaded context)
Recommendation: Restructure to avoid repeated indexing or add defensive checks.

2. Opposite Outcome Selection Logic

Location: dump_hedge_strategy.py:201

opp = self.outcomes[0] if self.outcomes[1] == leg1 else self.outcomes[1]

This assumes exactly 2 outcomes (checked at line 197), but if leg1 doesn't exactly match either outcome (e.g., whitespace differences), this could select the wrong outcome.

Severity: Low
Recommendation: Add assertion or use a more explicit lookup.

opp = next(o for o in self.outcomes if o != leg1)

Performance Considerations

1. Inefficient History Cleanup

Both strategies have O(n) deque cleanup operations in tight loops:

  • dump_hedge_strategy.py:152-153
  • jump_strategy.py:262-263

With default check_interval=1.0, this runs every second. For large history windows, this could accumulate overhead.

Recommendation: Consider using a timestamp-based filter rather than repeatedly popping from the front.

2. Repeated Type Conversions

Excessive float() casting throughout:

  • jump_strategy.py:81-94, 202, 239-241, 304-306
  • dump_hedge_strategy.py:76-80, 127, 174, 211-212

Since these values are already cast in __init__, the repeated conversions add unnecessary overhead.

Recommendation: Remove redundant float() calls on already-typed values.

Security Concerns

1. Order Execution Without Confirmation

When --live mode is enabled, both strategies place real orders without any confirmation prompt. A typo in parameters (e.g., --shares=200 instead of --shares=20) could place much larger orders than intended.

Recommendation: Add a confirmation prompt in live mode showing key parameters before starting.

2. Unbounded Position Growth (Jump Strategy)

The jump strategy accumulates inventory up to max_inventory, but if a jump never occurs, it could hold a large losing position indefinitely (until time_stop_seconds).

Recommendation: Consider adding:

  • Maximum loss threshold
  • Time-based position reduction
  • Alerts when accumulated inventory exceeds certain thresholds

Test Coverage

Major Issue: No test files were added for either strategy.

Recommendation: Add unit tests covering:

  • Strategy initialization
  • State transitions (phases, cycle states)
  • Price detection logic (_detect_dump, _detect_jump)
  • Edge cases (empty orderbook, invalid prices, timeout scenarios)
  • Test mode vs live mode behavior

Example test structure:

# tests/test_strategies.py
def test_dump_hedge_detect_dump():
    # Test dump detection with various price movements
    
def test_jump_strategy_phase_transitions():
    # Test ACCUMULATE -> DISTRIBUTE -> COOLDOWN flow
    
def test_strategies_respect_test_mode():
    # Verify no real orders placed in test mode

Documentation

Missing

  • No README or documentation explaining when/how to use these strategies
  • No examples of parameter tuning for different market conditions
  • No explanation of risk profile or capital requirements

Suggestions

Consider adding:

  • examples/README.md with strategy descriptions and usage examples
  • Parameter tuning guidelines
  • Risk warnings about live trading

Summary

Approval Recommendation: ⚠️ Approve with changes requested

The strategies are well-implemented with good structure, but have several issues that should be addressed:

Must Fix (Blockers)

  1. ❌ Remove .env variable usage per CLAUDE.md guidelines
  2. ❌ Add tests for both strategies
  3. ❌ Extract duplicated find_market_id() function

Should Fix (Important)

  1. ⚠️ Fix silent exception handling - add logging
  2. ⚠️ Add live mode confirmation prompt
  3. ⚠️ Document inventory tracking behavior in test mode

Nice to Have

  1. 💡 Extract magic numbers to constants
  2. 💡 Optimize history cleanup performance
  3. 💡 Remove redundant type conversions
  4. 💡 Add strategy documentation/README

Overall Assessment: Good code quality and clear implementation of interesting trading strategies. The main concerns are adherence to project conventions (CLAUDE.md), test coverage, and risk management in live mode.

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.

2 participants