Monitors AUD/CNY and GBP/CNY exchange rates and sends a Telegram alert when the current price moves into historically extreme territory (top or bottom of the last 3 years of monthly averages).
- Fetches 3 years of daily price history for each currency pair via yfinance.
- Calculates the average closing price for every calendar month and sorts those values.
- Compares today's price against the sorted monthly averages:
- Price ≥ all-time monthly max → ALERT (consider selling)
- Price ≥ 3rd-highest monthly avg → NOTICE (upper range)
- Price ≤ all-time monthly min → ALERT (consider buying)
- Price ≤ 3rd-lowest monthly avg → NOTICE (lower range)
- Sends any triggered message to a Telegram chat, then exits.
- Python 3.10+
- A Telegram bot token and chat ID (see setup below)
git clone https://github.com/your-user/CurrencyNotification.git
cd CurrencyNotificationpython -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activatepip install -r requirements.txtCopy the example env file and fill in your Telegram details:
cp .env.example .envEdit .env:
TELEGRAM_TOKEN=123456789:ABCDefGhIJKlmNoPQRsTUVwxyZ
TELEGRAM_CHAT_ID=987654321
- TELEGRAM_TOKEN – get this from @BotFather after creating a bot.
- TELEGRAM_CHAT_ID – your personal or group chat ID. You can retrieve it by messaging @userinfobot.
If
.envis missing or the values are empty the script still runs and prints alerts to stdout instead of sending them.
python main.pyExample output:
CurrencyNotification starting ...
Checking AUD2CNY (AUDCNY=X) ...
Current price : 4.7123
Historical max avg : 5.1042
3rd-highest avg : 4.9876
Historical min avg : 4.3201
3rd-lowest avg : 4.4512
No alert: price is within the normal historical range.
Checking GBP2CNY (GBPCNY=X) ...
Current price : 9.2340
Historical max avg : 9.1800
...
[Telegram sent] [GBP2CNY] ALERT: price 9.2340 >= historical MAX monthly avg 9.1800. Consider selling.
All checks complete. Exiting.
Open main.py and add entries to the CURRENCIES dict. The keys are display names and the values are Yahoo Finance ticker symbols:
CURRENCIES: dict[str, str] = {
"AUD2CNY": "AUDCNY=X",
"GBP2CNY": "GBPCNY=X",
"EUR2CNY": "EURCNY=X", # example addition
}Railway runs the script on a schedule with no server to manage. The repo already includes a railway.toml that runs the check at 09:00 UTC, Monday through Thursday.
-
Push this repo to GitHub.
-
Go to railway.com → New Project → Deploy from GitHub repo → select this repo.
-
Once the service is created, open its Variables tab and add:
Key Value TELEGRAM_TOKENyour bot token TELEGRAM_CHAT_IDyour chat ID -
Railway will detect
railway.tomlautomatically. The service type will be Cron and it will runpython main.pyevery day at 09:00 UTC.
To change the schedule, edit cronSchedule in railway.toml using standard cron syntax — for example "0 1 * * 1-4" for 01:00 UTC Monday–Thursday.
The script calls
sys.exit(0)when finished, which is required for Railway cron jobs to register a successful run.
If you prefer to run it on your own machine instead:
crontab -eAdd:
0 9 * * * /path/to/.venv/bin/python /path/to/CurrencyNotification/main.py