Building an AI Trading Assistant with Claude Code: Full Walkthrough from Order Execution to Risk Management

Building an AI trading assistant with Claude Code + Telegram for natural language orders and smart analysis.
This article walks through building a complete AI trading assistant using Claude Code (Agent mode) and Telegram. The system supports natural language order placement, batch trading, portfolio report generation, funding rate scanning, copying top traders' strategies, and TradingView Webhook automation. Running locally for security, the setup keeps API keys on-device with withdrawals disabled. The author cautions users to start small, monitor continuously, and remember that AI cannot guarantee profits.
Introduction: AI Is Changing the Game for Retail Traders
For decades, the technological edge in trading has belonged to institutional investors — hedge funds and market makers with entire quant and engineering teams building automated systems that monitor markets 24/7, execute trades in milliseconds, and manage risk automatically. Retail traders, on the other hand, have been stuck manually reading charts and placing orders, perpetually disadvantaged in both information access and execution speed.
But with the rapid advancement of large language models like Claude — especially the emergence of Claude Code (Agent mode) — a single individual can now build a trading assistance system approaching institutional grade. Recently, a content creator on Bilibili published a complete hands-on test of building an AI trading assistant using Claude Code + Telegram, covering everything from one-sentence order placement to portfolio report generation, demonstrating the real-world capabilities and boundaries of AI in trading scenarios.

Core Architecture: The Claude Code + Telegram Stack
Why Choose Claude Code as a Trading Agent?
Claude Code differs from a typical chat-based AI — it's an Agent version that doesn't just converse but can actually "take action." It can connect to exchange APIs, read position data, place real orders, and handle all interactions through natural language. It's currently available with the Pro plan at $20/month.
The Fundamental Difference Between Agent Mode and Traditional Chat AI: Agent mode represents one of the most important paradigm shifts in AI over the past two years. Traditional chat-based AI (like ChatGPT's basic conversation mode) can only generate text responses within a dialog box — it's essentially an "advisor" that tells you what to do but can't do it for you. Agent-mode AI, however, has "Tool Use" capabilities and can proactively execute code, call external APIs, read and write files, and operate databases. Technically, the Agent operates through a continuous loop of "think → act → observe": it first analyzes user intent, then calls the appropriate tools to execute operations, observes the returned results, and decides on the next action. This is what enables Claude Code to truly be an "executor" rather than merely a "consultant" — and it's the fundamental reason it can serve as a trading assistant.
Telegram as the Mobile Control Interface
The system's operational logic works like this: the bot runs in the background on a local computer, the user sends commands via Telegram, and Claude executes operations on the exchange and sends confirmation back. This means you can complete trading operations from anywhere, at any time, simply by opening your phone and typing a message.
Feature Walkthrough: From Basic Orders to Advanced Analysis
One-Sentence Position Opening with Risk Controls
The most basic capability is natural language order placement. In testing, entering "Open a 5x ETH long with $10, set stop-loss at -3% and take-profit at 8%" resulted in Claude completing the position opening, setting stop-loss and take-profit, and returning confirmation details for every parameter — all within seconds.
How Exchange APIs Work: The technical foundation behind this is the exchange API (Application Programming Interface) — a programmatic interface provided by exchanges that allows external software to communicate directly with exchange systems. Major exchanges like Binance, Bybit, and OKX offer two types of interfaces: REST API for operations like placing orders and querying accounts, and WebSocket API for receiving real-time market data pushes. Using an API requires generating a key pair — an API Key (public key for identity verification) and a Secret Key (private key for signature verification). Through permission settings, users can precisely control what the API can do: read-only, trading, and withdrawal permissions can be toggled independently, which forms the foundation of the security architecture discussed later in this article.
Even more powerful is batch execution: "Open a 5x BTC long, a 5x SOL long, and a 5x DOGE short — all with -3% stop-loss and 8% take-profit" — three trades, three stop-losses, three take-profits, all completed with a single sentence.
Professional-Grade Portfolio Dashboard
Entering "Give me a complete portfolio dashboard" prompts Claude to pull all account data and generate a visual report containing:
- Equity curve trends
- Win rate statistics
- Funding fee income broken down by token
- Liquidation distance for each position
This is the kind of report-level output typically produced by professional trading desks, now available with a single prompt in seconds.
Funding Rate Scanner
The funding rate is a fee that perpetual futures exchanges pay to traders on the "correct side" every 8 hours. When the funding rate is positive, longs pay shorts; when negative, the reverse applies. Some trading pairs can yield annualized rates of 50% or even over 100%.
Perpetual Futures and the Funding Rate Mechanism Explained: Perpetual futures are a unique invention of the cryptocurrency market, first introduced by BitMEX in 2016. Unlike traditional futures, perpetual contracts have no expiration date and can theoretically be held indefinitely. But this creates a problem: without an expiration and settlement mechanism, how does the contract price stay anchored to the spot price? The answer is the funding rate mechanism. Every 8 hours (or every hour on some exchanges), the system calculates a rate based on the deviation between the contract price and the spot price: when the contract price is above spot (too many longs), longs pay shorts, incentivizing more people to short and push the price down — and vice versa. This mechanism creates a unique arbitrage strategy — funding rate arbitrage: simultaneously holding a spot long and a contract short to earn funding fees without taking directional risk. The annualized returns can be attractive, but it's not risk-free — extreme market conditions can still lead to liquidation.
With the command "Scan all futures pairs and find the highest current funding rates," Claude scans every trading pair, sorts by rate, calculates annualized returns, and tells you which direction to open a position to collect the fee. This kind of pair-by-pair analysis is virtually impossible for a human to do manually, but AI handles it in seconds.
Advanced Strategies: AI as a Trading Decision Support Tool
Copying Profitable Traders' Strategies
This was one of the most impressive use cases in the test. Leveraging the fully transparent on-chain data of Hyperliquid (a decentralized exchange), you can view the current positions of the most profitable traders via the Hyperdash website, then:
- Screenshot the top trader's positions on Hyperliquid
- Screenshot the Bitcoin daily chart on TradingView
- Paste both screenshots into Telegram with an analysis prompt
Hyperliquid and On-Chain Transparency: Hyperliquid is a decentralized perpetual futures exchange that rose to prominence in 2023–2024, running on its own Layer 1 blockchain. The biggest difference from centralized exchanges (CEX) is that all trading data is fully public on-chain. Every address's opens, closes, and P&L records can be viewed by anyone — something impossible on centralized exchanges, where order books and user positions are private data. This transparency has spawned a "copy-trading analysis" ecosystem: third-party tools like Hyperdash track the trading behavior of high-profit addresses and analyze their strategy patterns. This is the technical prerequisite that makes it possible to screenshot top traders' positions — on-chain, there is no privacy, and all alpha is public.
Claude then comprehensively analyzes the profitable traders' position directions, chart technical structure, and real-time market data, making a probability-based decision and opening a trade with reasonable risk management.
This isn't a simple "buy or sell" button — it's having an AI model make a comprehensive judgment based on real profitable traders' data, real chart analysis, and real market conditions.
End-to-End Automation via TradingView Webhooks
Taking it a step further, you can use webhooks to send TradingView strategy signals directly to Claude for execution. When your technical strategy triggers a signal, Claude immediately completes the full suite of entry, stop-loss, and take-profit operations on the exchange — fully automated end-to-end, requiring no manual intervention once set up.
The Technical Pipeline of TradingView Webhooks: TradingView is the world's largest charting and analysis platform, and its Pine Script programming language allows users to write custom technical indicators and strategies. When strategy conditions are met (such as a moving average crossover or RSI oversold), TradingView can send an HTTP POST request to a specified URL via Webhook, carrying signal data in JSON format (such as trade direction, asset, quantity, etc.). In traditional automated trading, developers need to set up a server to receive these webhook signals and convert them into exchange API calls. In the approach described here, Claude Code acts as this "middleware" layer — receiving signals, using natural language understanding to parse intent, and then calling exchange APIs to execute, eliminating a significant amount of hardcoded development work. This dramatically lowers the technical barrier to strategy automation.
Security and Risk Considerations
Security Architecture Design
- The system runs on a local machine; API keys never leave the device
- No third-party servers store credentials
- Withdrawal permissions are disabled, so funds cannot be transferred out
Usage Recommendations
Although the architecture itself is relatively secure, you should still keep the following in mind:
- Start small — don't hand over all your capital to AI
- Monitor continuously — don't go completely hands-off
- Accept responsibility for risk — AI judgments are not 100% accurate
- This is not investment advice; all trading carries the risk of loss
Conclusion: Capabilities and Limitations of an AI Trading Assistant
This Claude Code + Telegram AI trading assistant demonstrates the current capability level of AI Agents in real-world financial scenarios. Its core value lies not only in improved execution efficiency (completing complex operations with a single sentence) but also in using AI as a decision support tool — performing probability-based analysis by synthesizing multi-dimensional data sources.
Of course, it's important to maintain a clear-eyed perspective: AI cannot guarantee profits, and market uncertainty remains ever-present. But what is undeniable is that traders who effectively leverage AI tools gain a significant edge in information processing speed, execution efficiency, and analytical depth. As the video creator put it: "If you're not using AI in your trading yet, you're already falling behind."
Related articles
TutorialsCursor + Codex Dual-IDE Collaboration: A Practical Methodology for Open-Source Project Customization
A complete methodology for open-source project customization based on real-world experience, detailing the Cursor+Codex dual-IDE workflow, seven-stage process, MVP validation, and AI source code reading techniques.
TutorialsCursor Multi-Agent in Practice: Building a Full-Stack Next.js Blog in 50 Minutes
Build a full-stack blog in 50 minutes using Cursor IDE's multi-Agent mode with Next.js, Clerk auth, and Supabase. Learn the 4-phase AI Agent workflow and key integration pitfalls.
TutorialsBuilding an AI Software Factory from Scratch: A Cursor Engineer's Hands-On Experience with Multi-Agent Collaboration
Cursor engineer Eric shares practical insights on building an AI software factory: automation levels, guardrail design, parallel Agent management, and scaling to 1000+ Agents for 24/7 development.