1. Task Description
It is necessary to develop a Python script that generates images with trading results (PnL), visually identical to the design of the Binance Futures application (example attached).
This is NOT overlaying text on a ready-made template. The image must be assembled programmatically "from scratch" (background, shapes, text) to ensure layout flexibility when changing data length.
2. Technical Stack
Language: Python 3.9+
Graphics: Pillow (PIL)
QR Codes: qrcode library
API & Requests: ccxt or requests (to get current prices from Binance)
Fonts: Use the Proxima Nova font family (or a visually identical alternative) to ensure that the numbers and kerning match the original.
3. Backend Logic
The script should operate in calculator mode. Input parameters are provided for the trade, and the script calculates the result.
A. Input Data: The script accepts JSON/Dict. Required fields: Symbol, Side (Long/Short), Leverage, Entry Price. The Last Price field is optional.
B. Algorithm of Actions:
Getting the Price: If Last Price is not provided in the input data, the script should make a request to the public Binance API (fapi) and get the current price (markPrice) for the specified pair.
Considering Precision: The script must take into account the tickSize of the specific pair (for example, for BTCUSDT — 2 decimal places, for PEPEUSDT — 7 decimal places). It is unacceptable to output "10.5000000" where "10.50" should be.
Calculating ROE (PnL %):
For Long: ((Last Price - Entry Price) / Entry Price) * Leverage * 100
For Short: ((Entry Price - Last Price) / Entry Price) * Leverage * 100
Rounding and Formatting: The final percentage is rounded to 2 decimal places.
If > 0: Text color is green (#2EBD85), prefix +.
If < 0: Text color is red (#F6465D), prefix -.
4. Visual Requirements (Frontend)
Background: Dark gradient or texture with a geometric pattern (Binance logo), drawn or taken in high quality.
Header:
Username (dynamic, default SyntrixBot).
Current date and time (UTC or provided).
Body:
Trading pair (e.g., OMGUSDT) and type Perpetual.
Side (Long/Short) — colored badges (green/red).
Leverage (e.g., 125x).
Main number (ROE): Large font, color depends on the sign (+/-).
Prices (Entry / Last) — left-aligned.
Footer:
Referral code (text).
QR code (dynamically generated based on the provided link).
Configuration: All colors (HEX), font paths, margins, and font sizes should be moved to a separate config.py file or constants at the beginning of the script for easy editing.
5. Example Input Data (JSON)
JSON
{
"user_config": {
"username": "SyntrixBot",
"referral_code": "SyntrixRef",
"qr_link": "https://binance.com/ref/..."
},
"trade_data": {
"symbol": "BTCUSDT",
"type": "Perpetual",
"side": "SHORT",
"leverage": 50,
"entry_price": 65000.50,
"last_price": null
}
}
/* Comment: Since last_price is null, the script goes to the exchange,
takes the current price (e.g., 63000.00), calculates the profit for Short
and draws a green card.
*/
6. Deliverables
Source code (.py), structured and commented.
File requirements.txt.
Assets folder with fonts (Proxima) and necessary images (background, default avatar).
The generation function should return a BytesIO object (for sending to Telegram without saving to disk) or save the file locally (toggleable parameter).
7. Acceptance Criteria
I provide the script with parameters of a real trade. The resulting image, when overlaid on the original screenshot from Binance, should match in grid, fonts, and margins. The PnL numbers must be mathematically correct.