adhipatya3552/Trading_Bot
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Repository files navigation
# Binance Futures Testnet Trading Bot ## π Overview This project is a simple Python-based trading bot built for the Binance Futures Testnet (USDT-M). The main purpose of this application is to place Market and Limit orders using a clean and structured approach. The bot takes input from the command line, validates it, and places an order using Binance APIs. It also handles common issues like minimum order size and invalid price ranges by automatically adjusting values when required. All activities are logged into a file for better tracking and debugging. --- ## π Features * Supports **Market Orders** and **Limit Orders** * Allows both **BUY** and **SELL** operations * CLI-based input using `argparse` * Automatic handling of Binance constraints: * Minimum notional value (β₯ 100 USDT) * Valid price range for limit orders * Logging of API requests, responses, and errors * Clean and modular code structure * Basic error handling for invalid inputs and API failures --- ## π Project Structure ``` trading_bot/ β βββ bot/ β βββ client.py # Binance API client setup β βββ orders.py # Order execution logic β βββ validators.py # Input validation β βββ logging_config.py # Logging setup β βββ cli.py # Command-line interface βββ .env # API credentials (not shared) βββ requirements.txt βββ README.md βββ trading.log # Log file (generated after running) ``` --- ## βοΈ Setup Instructions ### 1. Clone the Repository ``` git clone <your-repo-link> cd trading_bot ``` --- ### 2. Create Virtual Environment (Recommended) ``` python -m venv venv ``` Activate it: **Windows:** ``` venv\Scripts\activate ``` **Mac/Linux:** ``` source venv/bin/activate ``` --- ### 3. Install Dependencies ``` pip install -r requirements.txt ``` --- ### 4. Setup Environment Variables Create a `.env` file in the root directory: ``` API_KEY=your_testnet_api_key API_SECRET=your_testnet_secret_key ``` Make sure these keys are generated from Binance Futures Testnet. --- ### 5. Testnet API URL The application uses the Binance Futures Testnet: ``` https://testnet.binancefuture.com ``` --- ##βΆοΈ How to Run ### β Market Order Example ``` python cli.py --symbol BTCUSDT --side BUY --type MARKET --quantity 0.002 ``` --- ### β Limit Order Example ``` python cli.py --symbol BTCUSDT --side SELL --type LIMIT --quantity 0.002 --price 60000 ``` Even if the input values are not perfect, the bot will automatically adjust them based on market conditions. --- ## π Output Explanation After running a command, the bot shows: * Order Summary (input values) * Market adjustment message (if any) * Order Response: * Order ID * Status * Executed Quantity * Average Price Note: If the status is `NEW`, it means the order is placed but not executed yet. --- ## π Logging All logs are stored in: ``` trading.log ``` Logs include: * Order requests * API responses * Adjustments (price/quantity) * Errors This helps in debugging and understanding system behavior. --- ##β οΈ Error Handling The bot handles: * Invalid BUY/SELL inputs * Missing price for LIMIT orders * Binance API errors * Minimum order size issues * Price range violations Instead of failing, the bot tries to correct inputs automatically whenever possible. --- ## π§ͺ Testing The following tests were performed: * One Market Order (BUY) β successfully placed * One Limit Order (SELL) β successfully placed Both orders were logged in `trading.log`. --- ## π Assumptions * User has a valid Binance Futures Testnet account * API keys are correct and active * Internet connection is stable * Trading symbol exists on Binance --- ## π§ Future Improvements * Add Stop-Limit or advanced order types * Improve CLI with interactive prompts * Add a simple UI (Streamlit or web-based) * Real-time price display before placing order --- ## π¨βπ» Author This project was developed as part of an internship application task for a Python Developer role. --- Note: On Binance Testnet, some orders may show status as "NEW" instead of "FILLED". This means the order is successfully placed but not yet executed due to testnet behavior or market conditions.