billyma128 / binance-position-tracking-bot

Enabling real-time monitoring and analysis of Binance Futures trader's activities, complimented with Telegram notifications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Binance Futures Position Tracking Bot

The Binance Futures Position Tracking Bot is a Python script that utilizes the Binance API to monitor and record the trading activities of a specific trader on Binance Futures in real-time.

When the targeted trader opens a new position or closes an existing one, the script automatically detects these changes and sends an update notification via Telegram. This functionality enables users to follow the real-time trading activities of the targeted trader with detailed information about the latest positions including the estimated position, leverage, estimated entry size (in USDT), entry price, and profit and loss (PnL).

Features

  • Real-time monitoring and recording of a specific trader's trading positions on Binance Futures through the Binance API.
  • Notifications via Telegram when a new position is opened or an existing one is closed.
  • Detailed updates on each position, including estimated position, leverage, estimated entry size (in USDT), entry price (in USDT), profit and loss (PnL, in USDT), and update time.
  • Efficient handling and analysis of tracked data using pandas DataFrame.
  • Binance's API does not provide the value of positions in USDT. However, this script is designed to calculate the actual amount of USDT invested in a position, without considering leverage.
  • Customizable setup for the Telegram bot token and chat ID, facilitated by the setup.py script.
  • Continuous tracking and messaging system with 5-minute intervals for real-time data updates.
  • Ability to track multiple accounts simultaneously. Each message includes the username, allowing for easy identification of individual user's trading positions.
  • Error handling with retry mechanisms for potential connection failures.

Setup

  • Before running the main script (main.py), configure your Telegram bot token and chat ID using the setup.py script. You will be prompted to provide your Telegram bot token and chat ID, which will be stored in a config.ini file for the main script to reference.

Installation and Usage

  1. Download the project code.
git clone https://github.com/hgnx/binance-position-tracking-bot.git
  1. Install the required libraries.
pip install -r requirements.txt
  1. Contact @Botfather on Telegram to create a new bot and acquire the bot token.

  2. Get the unique identifier for your group.

    • 4-1. Log in to Telegram Web and navigate to the group where you want to receive notifications.
    • 4-2. Add the bot to the group.
    • 4-3. In the address bar, you'll find the URL that looks like this: "https://web.telegram.org/a/#-XXXXXXXXX". The sequence "-XXXXXXXXX" is your group's unique identifier.
    • 4-4. If your group is classified as a supergroup, prefix the unique identifier with "-100". For example, "-100XXXXXXXXX".
  3. Run the setup script and enter your Telegram bot token and chat ID (the unique identifier of your group).

python setup.py
  1. In main.py, assign the Binance UID (BUID) you want to track to the TARGETED_ACCOUNT_UID variable.

  2. Run the main script.

python main.py

Example

Current positions

alt text

New position

alt text

Closed position

alt text

Updated version

alt text

Future Improvements

Currently, the script only tracks the positions of a single trader's account. It is technically feasible to track multiple accounts, however, identifying user nicknames based on the BUID (Binance UID) presents a challenge. On the Binance User profile page, the nickname initially displays as "--", and it updates to the actual nickname once the page fully loads.

One simple solution could be to use Selenium to fetch the nicknames, but incorporating this library for this single task might be excessive and not desirable for the implementation. The ability to fetch and associate nicknames is important for clarity when sending individual position tracking updates via Telegram. Thus, resolving the nickname identification issue could be an improvement for future update, as it would enable a clearer display of position tracking for individual users.

Now you can track multiple accounts simultaneously, and each username is also included in the message.

Disclaimer

This script is for informational purposes only and should not be used as the basis for any financial decisions. I take no responsibility for any personal financial loss. Use this script at your own risk.

About

Enabling real-time monitoring and analysis of Binance Futures trader's activities, complimented with Telegram notifications.


Languages

Language:Python 100.0%