Skip to main content

I Thought My Crypto Agent Lost Money Overnight. Then I Found the Bug?

Published: December 7, 20253 min read
#Crypto#Agent#Progress#Analytics#BuildinPublic#TradingBot

I Thought My AI Lost Money Overnight. Then I Found the Bug.

Day 19 of building an AI-powered crypto trading system in public


I woke up at 8am to check on my AI trading bot. It had been running autonomously for 12+ hours overnight. The numbers looked wrong.

Something Didn't Add Up

My SOL SHORT position was closed. The stats said:

  • Trade count: 43 → 44
  • Win rate: 32.6% → 31.8%
  • Open positions: 1 → 0

Win rate dropped, so it was recorded as a loss. But here's the thing:

My stop loss was $134.67. The 24-hour high was $134.18.

The stop was never hit. So why did my position close?

The Detective Work

I started digging through 12 hours of deployment logs. The position was open at 23:59. By 03:10, it was gone. Somewhere in that 4-hour window, something went wrong.

Then I found it. Buried in the logs at 00:02:33:

Exchange positions: 0
Database open trades: 1
⚠️ Positions in database not on exchange: {'SOL'}

The reconciliation job - which syncs the database with the exchange - thought my position was orphaned. It closed it automatically at entry price with $0.00 P&L.

The Root Cause

My trading system supports two modes: spot trading and perpetual futures. The reconciliation job was only checking the spot adapter for positions.

But my SOL position was a perpetual (SOL-PERP). The spot adapter couldn't see it. So the system concluded: "Position in database but not on exchange = orphan = close it."

It closed a profitable position because it was looking in the wrong place.

The Fix

Two hours of debugging later:

  1. Fixed the reconciliation job to check BOTH spot and perpetual adapters
  2. Created a migration to correct Trade #44:
    • Exit price: $132.68 → $132.12 (actual market at closure)
    • P&L: $0.00 → $2.52 (the profit I should have had)
    • Status: Loss → Win

The code is now deployed. This bug won't happen again.

What the AI Actually Did Overnight

With the bug investigation complete, here's what the system did right:

64 market analyses. 0 new trades.

Every hour, DeepSeek analyzed BTC, ETH, SOL, and XRP. Every time, it said "NO_TRADE."

Coin ADX Verdict
BTC 21 "Neutral regime, weak trend, no clear direction"
ETH 12 "Choppy market, trend-following prone to whipsaws"
SOL 27 "Bear trend but no good entry point"
XRP 13 "Below ADX threshold, range-bound conditions"

The AI recognized a choppy, directionless market and stayed flat. That's exactly what I want.

The Validation Layer Worked Too

Around 10:35am UTC, DeepSeek proposed a trade: SHORT SOL at 84% confidence.

The validation layer rejected it:

"Entry at $132.10 is above the current price of $132.04, creating immediate negative slippage."

Strategist proposes. Validator disposes. Capital preserved.

Lessons from Today

  1. Logs are everything. Without detailed logging, I'd never have found this bug.

  2. Bugs hide in the integration points. The spot adapter worked. The perpetual adapter worked. The bug was in how they talked to each other.

  3. Autonomous systems need observability. "It ran overnight" isn't enough. You need to know exactly what happened and why.

  4. Fix bugs, don't accept losses. My first instinct was "the stop must have hit." Digging deeper revealed the real problem.

Current State (Corrected)

  • Portfolio: Flat (no open positions)
  • Total trades: 44
  • Win rate: 32.6% (corrected - Trade #44 is now a win)
  • Total P&L: -$100.45 (corrected - $2.52 profit recovered)
  • System status: HEALTHY
  • Bug status: FIXED

Building Trader-7 in public. Still in paper trading mode, still learning, still debugging.

Tech stack: Python, DeepSeek Reasoner, Railway deployment, SQLite, Streamlit dashboard

Share this post