This project is a Flask-based API for fetching real-time exchange rates from the Bank of China. It retrieves currency data from the BOC's official exchange rate webpage and provides an easy-to-use JSON API endpoint.
- Fetches exchange rates in real-time for 26 supported currencies.
- Data includes foreign exchange buying rate, cash buying rate, foreign exchange selling rate, cash selling rate, and conversion rate.
- Caching with a configurable timeout for optimizing performance.
- CORS enabled for cross-origin requests.
-
Clone the repository:
git clone https://github.com/missuo/boc-rate.git cd boc-rate
-
Install the dependencies:
pip install -r requirements.txt
-
Run the Flask app:
python boc-rate.py
By default, the API runs on
http://0.0.0.0:6666
.
GET /
currency
(required): 3-letter currency code (e.g.,USD
,EUR
).
Code | Currency |
---|---|
AED | UAE Dirham |
AUD | Australian Dollar |
BRL | Brazilian Real |
CAD | Canadian Dollar |
CHF | Swiss Franc |
DKK | Danish Krone |
EUR | Euro |
GBP | British Pound |
HKD | Hong Kong Dollar |
IDR | Indonesian Rupiah |
INR | Indian Rupee |
JPY | Japanese Yen |
KRW | Korean Won |
MOP | Macanese Pataca |
MYR | Malaysian Ringgit |
NOK | Norwegian Krone |
NZD | New Zealand Dollar |
PHP | Philippine Peso |
RUB | Russian Ruble |
SAR | Saudi Riyal |
SEK | Swedish Krona |
SGD | Singapore Dollar |
THB | Thai Baht |
TRY | Turkish Lira |
TWD | New Taiwan Dollar |
USD | US Dollar |
ZAR | South African Rand |
GET http://<server_ip>:6666/?currency=USD
On success:
{
"code": 200,
"message": "success",
"data": [
{
"currencyName": "USD",
"foreignExchangeBuyingRate": "6.8647",
"cashBuyingRate": "6.8301",
"foreignExchangeSellingRate": "6.8997",
"cashSellingRate": "6.9301",
"bocConversionRate": "6.8821",
"releaseTime": "2024-11-01 01:35:27"
}
]
}
- 400: Invalid or unsupported currency code.
- 404: No exchange rate data found for the specified currency.
- 500: Internal server error.
This project is licensed under the Apache-2.0 License © 2024. All Rights Reserved.