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.
- 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.
- Python 3.9 or higher
- Virtual environment (optional but recommended)
- Internet access for Nobitex and Bitpin APIs
- Telegram account and bot for notifications
-
Clone the Repository:
git clone https://github.com/salamzadeh/BitEx.git cd BitEx -
Create a Virtual Environment (optional):
python -m venv venv source venv/bin/activate # On Linux/Mac venv\Scripts\activate # On Windows
-
Install Dependencies:
pip install python-telegram-bot==20.7 requests
-
Set Up a Telegram Bot:
- Create a Telegram bot via BotFather and obtain the bot token.
- Find the chat ID for your Telegram user or group (use bots like
@GetIDsBot).
-
Configure the Script:
- Open
Arbitrage.pyand update the following:TELEGRAM_BOT_TOKEN = "YOUR_BOT_TOKEN_HERE" # Your Telegram bot token TELEGRAM_CHAT_ID = "YOUR_CHAT_ID_HERE" # Your Telegram chat ID
- Open
-
Run the Script:
python Arbitrage.py
-
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
- API success or errors: e.g.,
- 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
- Console Logs:
-
Stop the Script:
- Press
Ctrl+Cin the terminal to stop.
- Press
- 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_arbitragefunction’s conditionbest_ask_sell_diff > 5000. - Modify Check Frequency: Change
FPS(default: every 60 seconds) in themainfunction.
- 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).
- 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 changingfrom telegram import Bottofrom telegram.bot import Bot.
- Report bugs or suggest features by creating an Issue on GitHub.
- Pull Requests for code improvements or new features are welcome.
This project is licensed under the MIT License.
For questions or support, reach out via [email or GitHub Issues].