# Nobitex-Bitpin Arbitrage Checker This project is a Python script that identifies arbitrage opportunities between the Nobitex and Bitpin exchanges for the USDT/IRR trading pair. It compares Nobitex sell orders (asks) with Bitpin sell orders and Nobitex buy orders (bids) with Bitpin buy orders to find profitable opportunities. If an arbitrage opportunity with a price difference greater than 5000 IRR is found, a notification is sent via Telegram. ## Features - **Real-time Data Fetching**: Retrieves orderbook data from Nobitex API and recent trades from Bitpin API. - **Accurate Comparisons**: Compares Nobitex asks with Bitpin sells (to buy on Nobitex and sell on Bitpin) and Nobitex bids with Bitpin buys (to sell on Bitpin and buy on Nobitex). - **Order Aggregation**: Aggregates Nobitex asks to reach a minimum volume of 500 USDT and matches Bitpin volumes if the difference exceeds 5%. - **Telegram Notifications**: Sends a single Telegram message per cycle for the best arbitrage opportunity (price difference > 5000 IRR). - **Robust Error Handling**: Handles network, data, and API errors, allowing the script to continue running. - **Comprehensive Logging**: Prints detailed debug logs for order aggregation and comparisons. ## Prerequisites - Python 3.9 or higher - Virtual environment (optional but recommended) - Internet access for Nobitex and Bitpin APIs - Telegram account and bot for notifications ## Installation 1. **Clone the Repository**: ```bash git clone https://github.com/salamzadeh/BitEx.git cd BitEx ``` 2. **Create a Virtual Environment** (optional): ```bash python -m venv venv source venv/bin/activate # On Linux/Mac venv\Scripts\activate # On Windows ``` 3. **Install Dependencies**: ```bash pip install python-telegram-bot==20.7 requests ``` 4. **Set Up a Telegram Bot**: - Create a Telegram bot via [BotFather](https://t.me/BotFather) and obtain the bot token. - Find the chat ID for your Telegram user or group (use bots like `@GetIDsBot`). 5. **Configure the Script**: - Open `Arbitrage.py` and update the following: ```python TELEGRAM_BOT_TOKEN = "YOUR_BOT_TOKEN_HERE" # Your Telegram bot token TELEGRAM_CHAT_ID = "YOUR_CHAT_ID_HERE" # Your Telegram chat ID ``` ## Usage 1. **Run the Script**: ```bash python Arbitrage.py ``` 2. **Expected Output**: - **Console Logs**: - API success or errors: e.g., `Nobitex API read successfully at ...` - Aggregation details: e.g., `Debug: Aggregated 2 orders: [(873000.0, 127.87), ...], Total Volume: 500.00, Avg Price: 873081.9` - Errors: e.g., `Error at 2025-07-16 14:02:23: Error fetching Nobitex data: ...` - Maximum price differences: e.g., `Max Nobitex Ask - Bitpin Sell Difference: 5218.1 IRR` - **Telegram Notification**: If an arbitrage opportunity with price difference > 5000 IRR is found: ``` βœ… Arbitrage Opportunity Found πŸ“ˆ πŸ’Έ Buy on Nobitex: 873000 IRR, Nobitex Volume: 127.87 USDT πŸ’° Sell on Bitpin: 879000 IRR, Volume: 100.00 USDT πŸ“Š Average Buy Price: 873081 IRR πŸ“Š Average Sell Price: 878566 IRR πŸ“ Average Volume: 500.00 USDT πŸ“ˆ Price Difference: 5485 IRR ``` 3. **Stop the Script**: - Press `Ctrl+C` in the terminal to stop. ## Advanced Configuration - **Change Minimum Volume**: Modify `MIN_SELL_VOLUME` (default: 500 USDT) in the script. - **Adjust Price Difference Threshold**: Update the 5000 IRR threshold in the `check_arbitrage` function’s condition `best_ask_sell_diff > 5000`. - **Modify Check Frequency**: Change `FPS` (default: every 60 seconds) in the `main` function. ## Debugging and Troubleshooting - Check **console logs** for details on order aggregation and errors. - If errors occur (e.g., network issues or invalid data), the script logs them and continues running. - For support, share console logs, Telegram messages, and library versions (`pip show python-telegram-bot requests`). ## Limitations - Dependent on Nobitex and Bitpin APIs (logs errors and continues if APIs are down). - Requires stable internet connectivity. - Older versions of `python-telegram-bot` (<20.0) may require changing `from telegram import Bot` to `from telegram.bot import Bot`. ## Contributing - Report bugs or suggest features by creating an Issue on GitHub. - Pull Requests for code improvements or new features are welcome. ## License This project is licensed under the [MIT License](LICENSE). ## Contact For questions or support, reach out via [email or GitHub Issues].