How I Built an Automated 24/7 Crypto Trading Bot with n8n and Bybit

Jan 15, 2026

The hardest part of crypto trading isn't developing a winning strategy. The hardest part is the execution.


Crypto never sleeps. The markets are open 24/7/365. Unfortunately, humans are not. We need to sleep, eat, and step away from the screens.


Recently, a client approached me with a classic, painful problem. They had excellent TradingView strategies set up that were firing highly profitable buy and sell signals. The catch? The best signals often fired at 3:00 AM local time.


By the time they woke up at 7:00 AM, the move was over. They were missing out on significant profits overnight and spending their days anxiously glued to charts, terrified of missing the next big swing.


They didn't need a better strategy; they needed a better execution system. They needed a clone that didn't need to sleep.


Here is a deep dive into how I used n8n to build a fully autonomous trading bot that executes trades instantly based on email alerts, handling everything from signal parsing to complex risk management on the Bybit exchange.


The Goal: Zero-Touch Execution


The client’s requirements were clear but technically demanding:

  • Ingest Signals: Listen for alert emails from TradingView.

  • Parse Intelligently: Determine if the alert is a BUY or SELL, and for which asset (e.g., BTC, ETH, XRP).

  • Dynamic Sizing (Buying): Before buying, check the current available USDT balance and invest exactly 50% of it.

  • Precision Sizing (Selling): Before selling, check exactly how much of that specific coin is held and sell 100% of it, handling complex decimal precision requirements to avoid API errors.

  • Secure Execution: Place market orders on Bybit using secure API authentication.

  • Feedback Loop: Send a confirmation email once the trade is successfully executed.

The Stack

  • Signal Source: TradingView Alerts (sent via email)

  • Middleware/Logic Core: n8n (self-hosted)

  • Exchange: Bybit (Spot Market via API v5)

  • Communication: Gmail

The Architecture: A Deep Dive into the Workflow


Image


The n8n workflow looks complex at a glance, but it functions as a linear pipeline with one major decision point. Let's break it down by phase.


Phase 1: The Wake-Up Call (Trigger & Parse)


The automation begins with a Gmail Trigger node. It polls the client's inbox every minute, specifically looking for emails from TradingView.


Once an email arrives, the raw data (subject line and body) needs to be converted into structured data. This is handled by a Code Node (JavaScript) using Regex.


TradingView alert emails can be messy. The subject line might read something like: "Alert: Order BUY filled on BTCUST @ 45000."


The parsing node performs several critical cleanup tasks:

  • It extracts the Action: "BUY" or "SELL".

  • It extracts the Symbol: "BTCUST".

  • Crucially, it normalizes symbols: TradingView sometimes abbreviates Tether as "UST," while Bybit requires "USDT." The code automatically corrects "BTCUST" to "BTCUSDT" to ensure the exchange accepts the order.


Phase 2: The Air Traffic Controller (The Decision Logic)


Once parsed, an IF Node acts as the traffic controller. It looks at the "action" variable extracted in Phase 1.

  • If action == buy, the workflow routes down the top path (The Green Path).

  • If action == sell, the workflow routes down the bottom path (The Red Path).

This split is essential because the logic for buying (checking stablecoin balance) is fundamentally different from the logic for selling (checking asset balance).


Phase 3: The Green Path (Executing a Buy Order)


When a BUY signal is received, the bot doesn't just blindly buy a fixed dollar amount. It performs dynamic risk management.

  • Authentication Prep: Several nodes prepare the necessary timestamps and API keys for Bybit. Bybit requires HMAC SHA256 signing for all requests, ensuring that requests cannot be intercepted or tampered with.

  • The Balance Check: The bot makes an HTTP GET request to Bybit's /v5/account/wallet-balance endpoint to ask: "How much free USDT is currently in the account?"

  • Dynamic Calculation: A Code node receives the balance (e.g., $10,000 USDT). It applies the client's risk parameter—in this case, 50%. It calculates an investment amount of $5,000.

  • Execution: The bot packages this data into a final POST request to Bybit's /v5/order/create endpoint, placing a Market Buy order for $5,000 worth of the target asset.


Phase 4: The Red Path (The Complexities of Selling)


Selling is technically trickier than buying. If you try to sell 1.000001 BTC when you only own 1.000000 BTC, the API will reject the order. Precision matters.

  • Asset Identification: If the signal is to SELL "XRPUSDT," the bot first strips the "USDT" to identify the base asset: "XRP."

  • Targeted Balance Query: It queries Bybit specifically for the balance of that coin. "How much XRP do we have?"

  • The Precision Challenge: This is where many amateur bots fail. Different coins have different decimal precisions. Bitcoin (BTC) might allow 6 decimal places in an order quantity. Ripple (XRP) might only allow 2.I wrote a specialized JavaScript node that handles this. It checks the coin type and rounds the balance down to the appropriate decimal place accepted by Bybit's API. This ensures we are selling 100% of available holdings without triggering an "insufficient balance" error due to rounding differences.

  • Execution: A Market Sell order for the precisely calculated quantity is sent to Bybit.


Phase 5: Closing the Loop


Regardless of whether it was a buy or a sell, the final step in both paths is a Gmail node.

n8n takes the response from Bybit (which includes the Order ID, execution price, and status) and formats it into a clean email sent back to the client. This provides peace of mind that the system is working correctly.


The Results: More Than Just Profit


The technical implementation was a success. The bot now runs seamlessly on a VPS, handling trades in milliseconds.

But the real impact for the client wasn't just about catching overnight price moves; it was about lifestyle.

  • Eliminated FOMO: They no longer feel the urge to check their phone during dinner or wake up in the middle of the night. If a signal fires, they know it will be executed.

  • Emotionless Trading: The bot doesn't hesitate when a sell signal hits because it "feels" the price might go higher. It executes the strategy exactly as programmed.

  • Regained Time: The hours previously spent staring at charts are now reclaimed.


By leveraging n8n, we transformed a high-stress, manual trading process into a "set-it-and-forget-it" passive system. It’s a perfect example of how low-code automation can solve complex, real-world financial problems.

© 2025 Dhilip Subramanian. All Rights Reserved.

© 2025 Dhilip Subramanian. All Rights Reserved.

© 2025 Dhilip Subramanian. All Rights Reserved.

© 2025 Dhilip Subramanian. All Rights Reserved.