globall.dev - Telegram bot studio globall.dev
Crypto exchanger USDT/USD

A currency exchange inside a Telegram Mini App, with live exchange rates

The offline USDT/USD exchange office has moved inside Telegram: the rate is collected from four sources with reservations, applications are counted themselves, there is AML verification of wallets and synchronization with Google Sheets.

Niche: crypto exchanger Type: Mini App + bot Stack: PHP + Telegram Mini App
4 sources
The rate is aggregated with prioritization and fallback - the exchanger does not get up if one API falls
AML verification
Wallet risk assessment (low / medium / high) with a limit of 3 checks per day
Ref. system
Bonuses for invited transactions and discounts on the course depending on the number of referrals
Google Sheets
Users and requests are synchronized into a table in real time
Problem

The exchanger maintained the same exchange rate and manual account

Before the Mini App, USDT/USD exchange was done the old fashioned way. The rate was taken from one source - and as soon as this API went down or gave a crooked number, the exchanger literally got up: the operator did not understand what price to calculate, and the client waited in correspondence. Applications were filled out manually in the chat, the amount in USDT was calculated on a calculator, and the details were asked several times.

Second pain money and trust. In a cryptocurrency exchange, you can’t just “accept the wallet”: you need to understand whether the funds came from a dirty address. Without verification, this is a risk for both the exchanger and the client. And any attempt to grow the flow through referrals rested on the fact that bonuses and discounts were also considered hands.

The request was this: to bring the exchange into a convenient interface inside Telegram, so that the client could choose the direction, see the current rate and total amount, leave a request with details - and the rate, AML check and referral economy would work automatically and did not depend on one service.

Approach

How we broke down the exchanger into parts

An exchanger is not a “bot that writes a course.” The reliability of the figure and the transaction is critical here: an error in the course is a direct loss, and missing a dirty wallet is a more serious risk. Therefore, the scope was divided into separate, isolated blocks:

  1. The course is a separate layer with reservation. One source - single point of failure. We need a chain of several APIs with priority and automatic switching to the next one, plus a cache in the database as the last line.
  2. The calculator and margin are flexible and under the control of the owner. The market rate is subject to a customizable margin (offset for buying and selling), a fixed spread and personal/referral discounts. This is calculated on the server, not by eye.
  3. AML is a required step, not an option. Before the transaction, the client checks the wallet: the risk level and the limit of checks per day, all with a log in the database.
  4. Applications and accounting - Mini App + mirror in Google Sheets. The application is completed in a couple of clicks, and the owner sees the entire flow in the usual table, without going to the admin panel.

This cutting resulted in a product that was understandable to the client in two minutes, and at the same time stable: even if the external exchange rate service is temporarily unavailable, the exchanger continues to work.

Solution

What did the owner of the exchanger receive?

Client opens the Mini App inside Telegram, selects the direction (buy or sell USDT), enters the amount in local currency - and immediately sees the total amount in USDT at the current rate with the margin already taken into account and his personal discount. Then he leaves an application: full name and TRC-20 wallet, all in one form. The interface responds instantly - thanks to the optimistic UI, the application is shown accepted immediately, and goes to the server in the background.

A course that does not depend on one API

Under the hood is an aggregator that polls sources by priority: Rapira → Binance P2P → CoinGecko → CryptoCompare → cache in the database. If the first source is unavailable or has provided a clearly incorrect value, the system moves on to the next one. Therefore, even when the exchange API is down, the exchanger continues to count and accept orders. A customizable margin for buying and selling, a fixed spread and client discounts are applied to the basic rate - the owner manages the economy from the admin panel.

AML verification and referral program

Before a transaction, the client can check the address: the system determines the risk level (low / medium / high), limits it to 3 checks per day and writes the result to the log. The referral program does the math itself: everyone is given a unique code, a bonus is awarded for transactions of invitees (local currency for each exchanged USDT), and for the number of invitations (3+ and 10+) the client receives discount on your own course. On top is a personal discount that the owner can issue manually.

Google Sheets and parallel bot

All users and applications synced to Google Sheets in real time through Service Account - the owner sees the flow in the usual table, and referral bonuses are awarded according to the transaction status directly from Sheets. A regular Telegram bot works in parallel with the Mini App: /start with referral code, profile, current courses and main menu. With each new application, a notification is sent to the admin and support.

Technically

What's under the hood

PHP backend Telegram Mini App (TWA) Telegram Bot MySQL Google Sheets API

Course: Aggregation and Fault Tolerance

4 sources with priority and fallback
Rapira → Binance P2P → CoinGecko → CryptoCompare → cache in the database. The failure of one API does not stop the exchange.
Flexible Margin Calculator
Customizable buy/sell offset, fixed spread and application of discounts directly to the rate.

Transactions, AML and referral economy

Exchange application form
Type (buy/sell USDT), amount in USD, full name, TRC-20 wallet, automatic calculation of the amount in USDT.
History of requests with statuses
Waiting / processing / completed / canceled - with color indication for the client.
AML wallet verification
Risk level low/medium/high, limit of 3 checks per day, logging the result in the database.
Referral system
A unique code, a bonus for transactions of invited people, discounts from 3+ and 10+ referrals, a personal discount from the admin.

Integrations, admin and UX

Google Sheets via Service Account
JWT authorization, real-time synchronization of users and orders, accrual of bonuses based on transaction status in Sheets.
Bot in parallel with Mini App
/start with a referral code, profile, courses, main menu and interaction logging.
Admin panel
Statistics, rate and margin management, personal discounts for users.
Optimistic UI
Instant feedback to the client + background sending to the server (fire-and-forget) - the interface does not slow down.
Notifications to admin and support
Each new application is immediately received by the responsible person - nothing is lost in the flow.
MySQL for all accounting
Users with referral codes and discounts, applications, courses, referrals, AML checks and settings.
Result

The exchanger works and does not depend on one service

Instead of correspondence and a calculator, exchange in a couple of clicks inside Telegram. The rate is aggregated from 4 sources with fallback, there is AML verification and synchronization with Google Sheets - the exchanger does not get up even if one API is down. The client chooses the direction himself, sees the total amount and leaves a request, and the course, wallet check and referral accruals are calculated automatically.

  • The fall of one rate source no longer stops the exchange - there is a chain of reserves and a cache.
  • The AML step is built into the script: the risk level of the wallet is visible before the transaction, with a limit and log.
  • Referral economy and discounts are calculated on their own - without manually counting bonuses.
  • The owner sees the entire flow of applications in Google Sheets and manages the course from the admin panel.
Specific turnover and number of transactions are on the side of the owner of the exchanger; We are ready to add them to the case upon request when statistics accumulate.

Do you need an exchanger or payment Mini App?

Tell us about the directions of exchange, the sources of the course and the referral scheme - we will send you a fixed estimate and launch plan within a day. The sources are yours from day one.

For free. I will answer within an hour during business hours. No spam.

We take on a limited number of projects at the same time - the nearest slot is limited.

IP Geolocation by DB-IP