A Python script that monitors new Telegram Star Gifts and auto-buys limited gifts based on configurable rules (market-cap threshold, max supply, per-user distribution, cooldowns, etc.).
It uses two Telegram sessions: one for parsing the gift catalog and one for buying/sending gifts.
⚠️ Use responsibly. Respect Telegram’s Terms of Service and local laws. Consider API rate limits (
FloodWait) and avoid abusive behavior.
get_star_gifts().send_star_gift().gift_list).market_cap_like = price × total_amount × 0.015 and compares it to mcap threshold.loguru.pyrogram, loguru (optionally python-dotenv if you prefer .env)Example requirements.txt:
pyrogram==2.2.7
loguru>=0.7.2
python-dotenv>=1.0.1
Install:
python3 -m venv .venv && source .venv/bin/activate
pip install -U pip
pip install -r requirements.txt
The script imports settings from config.py. Create it next to the script and fill in your values.
# config.py — sample configuration
# Number of recipients (1..10)
num_of_users = 3
# Recipient usernames (Telegram @usernames or numeric IDs)
first_username = "user1"
second_username = "user2"
third_username = "user3"
fourth_username = ""
fifth_username = ""
sixth_username = ""
seventh_username = ""
eighth_username = ""
ninth_username = ""
tenth_username = ""
# Delay between individual sends (seconds)
time_sleep = 2.0
# Where to send notifications (username or ID)
acc_for_notification = "me"
# Filtering thresholds
# Gifts pass only if:
# - gift.is_limited == True
# - computed market_cap_like <= mcap
# - gift.total_amount <= max_supply
mcap = 50000 # tune this threshold for your strategy
max_supply = 10000 # maximum allowed total_amount
# Budgeting
stars_for_each = 1000 # total Stars you plan to allocate per gift (split among users)
# Main loop cooldown (seconds) between parsing cycles
parsing_cooldown = 5
# Phone numbers for session login (format Telegram accepts)
tg_number_for_parse_acc = "+48111111111"
tg_number_for_buy_acc = "+48222222222"
You will also set your API credentials inside the script (see below) or switch to environment variables if you prefer.
At the top of the script, set the two app credentials you got from my.telegram.org:
# API keys from https://my.telegram.org/auth
parsing_acc_api_id = 1111111
parsing_acc_api_hash = "11111111"
acc_with_stars_api_id = 111111
acc_with_stars_api_hash = "11111111"
Tip: for better security, load these from environment variables or a
.envfile (e.g., withpython-dotenv).
parsing_acc (parsing account). acc_with_stars), then closes it (to ensure the session is initialized).parsing_cooldown seconds:app.get_star_gifts().gift_list:price × total_amount × 0.015.<= mcap and total_amount <= max_supply, it calculates how many to send from stars_for_each, splits evenly across num_of_users, and calls buy_nft(...).loguru.buy_nft() opens the acc_with_stars client and iterates recipients with time_sleep pauses, calling send_star_gift(...).Save your script (e.g., main.py) and run:
python main.py
On first run, Pyrogram will ask for login codes (per session). Make sure both numbers in config.py can receive Telegram login codes.
time.sleep. If you hit pyrogram.errors.FloodWait, increase time_sleep and parsing_cooldown. For production, consider adding an exponential backoff and catching FloodWait.gift_list): Hard-coded in the script to avoid reprocessing known gifts. You can persist it to disk (e.g., JSON) to keep state across restarts.acc_for_notification with (gift.id, gift.sticker.emoji, market_cap_like) when a qualifying gift appears.phone_number values are correct and you can receive Telegram login codes for both accounts.FloodWait or rate limits:time_sleep and parsing_cooldown. Add jitter or a retry policy.gift.id, gift.price, etc.). If you change providers, keep the same data model.gift_list to gift_seen.json (load on start, atomic save on update).if num_of_users == N branches with a dynamic USERNAMES list.acc_with_stars once and pass the client to buy_nft(...).MIT (feel free to change if needed).
$ claude mcp add gifts \
-- python -m otcore.mcp_server <graph>