Today on our table is the project jhonwick547/trading_bot.
At first glance, it looks like a serious claim to success. An automatic trading bot for Binance, written in Python. But in reality, it's a guide on how not to write financial software. If you run this on a real account, the market will eat you alive.
What's the nightmare? 🤡
1️⃣Schrödinger's Machine Learning
The code proudly imports
sklearn and loads a model:self.model = joblib.load(model_path)But in the
generate_signals method... it is never used. 🤡Signals are generated through a set of
if statements at a 5th-grade level: "If RSI < 60 and MACD is rising — buy."Why is Random Forest there? Apparently, to make the laptop fan hum more convincingly.
2️⃣ Deadly Race
Look at the
execute_trade function.1. The bot sends a market order (
create_market_buy_order).2. The bot attempts to place Stop Loss and Take Profit with separate requests.
The million-dollar question: what happens if between step 1 and step 2 your internet goes out, the script crashes, or Binance returns an API error?
Answer: You'll be left with an open position without a stop loss. One candle in the wrong direction — and hello, liquidation.
In normal systems, OCO orders (One Cancels the Other) are used, or a batch of orders is sent so that entry and stop are atomic (or at least as close as possible).
3️⃣ Math That Doesn't Work
The position sizing function
calculate_position_size:risk_amount = balance * self.balance_pct # 10% of deposit
position_size = risk_amount / (entry_price - stop_loss)The author confuses risk per trade with entry volume.
If
entry_price is close to stop_loss, the denominator approaches zero, and the position size skyrockets. There's a min() there, but the logic of calculating volume from fixed risk is implemented crookedly. As a result, you either risk pennies or your entire deposit, depending on volatility.4️⃣ Double Work
In the
start_trading loop, the bot downloads candles (fetch_data) and calculates indicators to check for a signal.If there is a signal, it calls
execute_trade, where... it downloads candles again and calculates indicators again.Apparently, to get Binance to ban your IP faster for excessive requests.
5️⃣ Hardcoded Keys
In
if __name__ == "__main__":, keys are suggested to be written directly into the code.api_key = 'YOUR_API_KEY'Never. Do you hear? Never store secrets in code. Use
.env.👨🏻⚖️ Verdict:
Looks like a trading bot on the surface, but in essence — a random loss generator.
#roasting_code
Comments
0No comments yet.
Sign in to join the discussion.