Robô Trader de Cripto 100% Automático na Binance - Código Python Explicado
Introduction to Trading Bot Development
Overview of the Trading Bot
- The speaker introduces himself as Freitas, a computer engineer discussing AI, investments, and marketing.
- He mentions implementing a complete trading bot that buys and sells stocks based on previously discussed deep learning strategies.
- The bot operates in the cryptocurrency market using Binance for quick integration and 24/7 trading capabilities.
Important Disclaimer
- A disclaimer is provided about the volatility of crypto trading; users are advised to proceed at their own risk.
- Viewers are encouraged to subscribe and engage with suggestions as the speaker plans to refine the trading strategies over time.
Initial Strategy for Trading Bot
Key Indicators Used
- The initial strategy involves two moving averages: a 7-period (fast) moving average in yellow and a 40-period (slow) moving average in purple.
- Buy signals occur when the fast average crosses above the slow average, while sell signals happen when it crosses below.
Performance Insights
- An example shows potential profits of 10% within a day by following this strategy, highlighting its conservative nature aimed at minimizing losses.
- Continuous market monitoring is essential due to crypto's volatility; otherwise, traders may incur losses during downturns.
Operational Mechanics of the Bot
Real-Time Trading Execution
- The bot operates continuously to protect against market drops while capitalizing on upward trends.
- Current trades involve Solana; if conditions are met (fast MA > slow MA), it executes buy orders automatically.
Code Implementation Details
- The speaker advises starting with smaller amounts for new users to build confidence before increasing investment levels.
Binance Trader Bot Overview
Class Structure and Initialization
- The main class is the Binance Trader Bot, which starts with an undefined decision variable to track the last action taken.
- The constructor initializes necessary variables for the bot's operation, including API keys for client access.
- A crucial function updates account data before any trading actions, retrieving current balances and positions (bought or sold).
Data Retrieval and Processing
- The bot fetches asset data using the Binance P client library, identifying stock codes and current positions based on balance thresholds.
- It employs a method to retrieve price data at 15-minute intervals, focusing on closing prices for strategy execution.
Trading Strategy Implementation
- The moving average trade strategy uses a customizable window of 7 and 40 intervals to determine buy/sell signals based on fast and slow averages.
- An if/else structure checks if the fast average exceeds the slow one to signal a buy; otherwise, it indicates a sell.
Trade Execution Insights
- During recording, a sale was executed successfully; tracking profit from trades is essential for performance evaluation.
- Future improvements are planned to enhance entry/exit timing in trades based on technical indicators like MACD.
Logging and Error Handling
- Orders are executed via Binance API calls; successful transactions log details while errors are also recorded for troubleshooting.
- A simple logging function captures transaction messages, ensuring clarity in operations performed by the bot.
Selling Mechanism Details
- The selling function mirrors buying but adjusts quantities based on actual holdings rather than initial purchase amounts due to API constraints.
Robot Strategy Execution
Overview of the Robot's Functionality
- The robot automates the execution of trading strategies, updating data and printing current positions and balances.
- It utilizes a simple trade decision strategy as its final decision-making process, allowing for the addition of multiple strategies in the future.
- The robot checks if it should buy or sell based on current positions and decisions, executing trades accordingly.
Implementation Process
- To operate the robot, one simply instantiates the main class with configurations and runs an eternal loop that calls the Execute function every minute.