Commit Graph

13 Commits

Author SHA1 Message Date
b2d7495ec0 Relax LLM entry filters, show 1h-bullish HOLD reasons in cycle report
- llm_analyzer.py: change 5m filters from hard requirements to confidence
  adjustments (volume, ADX<15, OBV direction now ±0.1 instead of blocking);
  1h ADX<20 lowers confidence instead of preventing entry
- slack_notifier.py: when all symbols HOLD, show 1h-bullish symbols with
  their HOLD reason instead of generic "no action" message
- main.py: log all 15 HOLD reasons instead of first 3

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 01:32:51 +00:00
d261b36460 Add hourly Slack trend report, log all HOLD reasons, whale correlation analysis
- hourly_trend_report.py: standalone cron script (XX:00:30) sends 1h bullish/bearish status
- slack_notifier.py: add send_market_trend_report() — simple bullish/bearish only, no entry signals
- main.py: log all 15 HOLD reasons (not just first 3) for debugging all-HOLD cycles
- backtest/whale_correlation.py: blockchain.com on-chain correlation analysis (result: no signal)
- memory/: update project memory with architecture split, cron layout, feedback

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 13:45:52 +00:00
b6bd45b151 Fix SELL P&L calculation, add debug logging, and multiple improvements
- Fix realized_pnl always being 0 on SELL (use amount*price instead of amount_usdt)
- Add debug logging for all-HOLD LLM cycles (log sample HOLD reasons)
- Fix nonce collision in Bitfinex API auth (add counter)
- Fix timezone to UTC+8 in main, trade_logger, sync_cost_basis, check_errors
- Fix stop-loss retry with longer delay after cancel
- Add min order amount check in trader before BUY
- Fix risk_manager to skip positions with amount <= 0
- Cap trade_history to 500 entries to prevent unbounded growth
- Fix greedy regex in LLM response parser
- Reset cost_tracking start dates to null

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 06:23:54 +00:00
41ad549ae2 Fix stop-loss placement failure after cancel by increasing delay and adding retry
Bitfinex needs time to release locked balance after cancelling a stop order.
Increased wait from 0.3s to 1.0s, and added a one-time retry with 2s delay
if the first attempt fails.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 04:11:34 +00:00
36225df832 Add Claude auto-fix to check_errors.py, distinguish LLM failure in Slack reports
- check_errors.py: on errors, call Claude CLI to diagnose and attempt auto-fix,
  include fix report in Slack alert
- slack_notifier.py: show "LLM 分析失敗" when LLM fails instead of "All HOLD"
- main.py: track llm_ok flag and pass to Slack reporter
- setup.sh: restore ~/.local/bin in crontab PATH for claude CLI
- llm_analyzer.py: use shutil.which for robust claude binary lookup

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 03:08:06 +00:00
17303d5d3d Add deposit-based total return, session persistence flag, dual return rates
- Add fetch_total_deposits() with hourly local cache (deposit_cache.json)
- Use deposit total as capital base for accurate total return calculation
- Add --no-session-persistence to claude CLI subprocess calls
- Show both total return (deposit-based) and change rate (cost-based) in reports
- Update portfolio summary with Total Return line

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 10:21:39 +00:00
ddc1b9e3eb Add ATR-based dynamic stop-loss and pass current_prices to validate_trade
- Add _calc_atr_stop_price(): ATR × 3 with 3-8% bounds
- place_stop_loss_order() accepts explicit stop_price from ATR calc
- Stop-loss backfill uses stored stop price before falling back to fixed %
- Pass current_prices to validate_trade() for LLM SELL PnL calculation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 03:26:54 +00:00
1abfdefecd Add advanced indicators: MTF analysis, ADX, StochRSI, OBV, CMF, pivot points
- config.py: Add HTF_TIMEFRAME (1h) and HTF_CANDLE_LIMIT (50)
- data_fetcher.py: Fetch both 5m and 1h candles per symbol
- indicators.py: Add ADX, StochRSI, OBV+slope, CMF to 5m indicators;
  new functions for HTF indicators, pivot points, and their summaries
- main.py: Wire up HTF data flow (1h indicators + pivots → LLM summary)
- llm_analyzer.py: Rewrite prompt with MTF filter (1h trend alignment),
  require 2+ confirmations for BUY, confidence scoring guide

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 03:26:59 +00:00
9249d0f4d9 Fix UnboundLocalError: load tracked_stops before stop-loss sync loop
tracked_stops was used in the stop reconciliation loop (line 141) but
only loaded later in the fill detection section, causing a crash every
cycle since the last commit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 03:21:44 +00:00
fa148da196 Fix exchange API errors: stop cascade BUY failures and stop-loss race condition
- Set available_usdt=0 after BUY fails with "not enough balance" to prevent
  subsequent BUY signals from hitting the exchange in the same cycle
- Add 0.3s delay after canceling stop orders before placing new ones to let
  Bitfinex release locked balance

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 03:12:54 +00:00
c473a581b0 Add realized P&L reporting, stop-loss fill detection, and balance margin
- Show realized P&L (USDT + %) in Slack for all SELL trades (TP, LLM, stop-loss)
- Detect filled stop-loss orders via stop_orders.json persistence and report as [止損觸發]
- Deduct 1 USDT margin from available balance to prevent exchange insufficient balance errors

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 02:44:46 +00:00
ce88afdb96 Add cost basis sync, fix stop-loss reliability, improve reporting
- New sync_cost_basis.py: recalculate entry_price from order history,
  sync amounts/balances from wallet (cron every 30 min)
- Fix stop-loss ID staleness: update stop_orders_by_sym in step 2b
  after placing new stops, preventing SELL failures from stale IDs
- Fix position limit inconsistency: use same total_balance in
  validate_trade instead of calling check_position_limit
- Skip stop-loss for positions below MIN_ORDER_AMOUNT
- Add API response body logging for 500 errors
- Cancel "Order not found" treated as success (not error)
- Post-trade wallet refresh to ensure fresh balances
- Report: show total value, total return %, exclude dust positions
- Crontab offset +1 min from candle close for complete data
- Handle PARTIALLY FILLED order status in cost calculation
- Sort orders by mts_create in Python (Bitfinex sort unreliable)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 11:18:49 +00:00
972d66ab1b Initial commit: LLM-driven crypto trading bot
Includes: Bitfinex API integration, technical indicators,
LLM signal generation, risk management, Slack notifications.

Recent fixes:
- SELL orders use position value instead of total balance
- SELL signals always close full position
- Failed orders added to rejected list for Slack reporting
- Position/exposure limits auto-cap to remaining room
- BUY order minimum raised to 10% of portfolio

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 03:25:18 +00:00