Replymessage unavailable
Deal Statistics System Logic
Objective
Create a complete Deal Statistics (Stats) system that automatically records every completed deal and displays detailed statistics for users.
1. Save Every Completed Deal
Whenever a deal is marked as Completed, save the following information in the database:
- Deal ID
- Buyer Username
- Seller Username
- Escrow Username (if available)
- Deal Amount
- Currency
- Deal Completion Date & Time
- Status (Completed)
---
2. User Stats Command
When the admin or user runs:
"/stats @username"
The bot should display all completed deals where that username is involved (either as Buyer or Seller).
Display:
- Username
- Total Deals
- Total Deal Volume
- Buyer Deals Count
- Seller Deals Count
- First Deal Date
- Latest Deal Date
Example:
Username: @Anil
Total Deals: 28
Buyer Deals: 15
Seller Deals: 13
Total Volume: ₹84,500
First Deal: 10 July 2026
Latest Deal: 30 July 2026
---
3. Last 7 Days Statistics
Show only deals completed in the last 7 days.
Display:
- Buyer Username
- Seller Username
- Deal Amount
- Deal Date
At the bottom display:
- Total Deals (Last 7 Days)
- Total Volume (Last 7 Days)
Example:
Last 7 Days
Buyer: @Rahul
Seller: @Anil
Amount: ₹2,500
Date: 29 Jul 2026
Buyer: @Karan
Seller: @Rohit
Amount: ₹5,000
Date: 27 Jul 2026
Total Deals: 8
Total Volume: ₹24,300
---
4. Last 30 Days Statistics
Exactly the same format as the 7-day statistics, but include only deals from the last 30 days.
Display:
- Buyer Username
- Seller Username
- Deal Amount
- Deal Date
At the bottom:
- Total Deals (Last 30 Days)
- Total Volume (Last 30 Days)
---
5. Lifetime Statistics
Show all completed deals since the bot started.
Display:
- Total Completed Deals
- Total Deal Volume
- Total Buyers
- Total Sellers
---
6. Database Logic
Each completed deal should create one database record.
Example:
Deal ID: 1001
Buyer: @Rahul
Seller: @Anil
Amount: 2500
Currency: INR
Status: Completed
Completed At: 2026-07-30 18:45
The statistics should always be calculated from these saved records.
---
7. Important Rules
- Only count Completed deals.
- Ignore Pending, Cancelled, or Failed deals.
- If a user is Buyer or Seller, include that deal in their stats.
- Sort deals by newest first.
- Automatically update stats whenever a new deal is completed.
- The system should work even with thousands of deals efficiently.
The bot must calculate all statistics automatically from the database without requiring manual updates.