"It's a pain to check the exchange rate every time..." "I want to know the rate in real time..."
I'm sure there are many people who have such concerns.
In fact, if you use Python and API,A convenient BOT that automatically obtains exchange ratescan be easily created.
In this article,Explanations are provided in easy-to-understand Japanese with accompanying code so that even beginners can learn with confidence.I will.
Also,How the API works, how to execute it periodically, how to deal with errors, and examples of its useIt covers everything from...
For those who want to try automatic foreign exchange acquisition,Those who want to take a step forward in automation with PythonThis is a must-read for.
- What is an exchange rate BOT? [Exchange rate automatic acquisition BOT]
- How to handle foreign exchange data with Python [Python Foreign Exchange API]
- How to implement an exchange rate acquisition BOT [Python exchange rate automation]
- Automate regular execution of exchange BOT [Python automatic execution method]
- Error handling and log saving techniques [Stable operation of exchange BOT]
- Various uses for exchange rates [How to use exchange rate data]
- Summary: Trying automation with Python [Python exchange BOT learning effect]
What is an exchange rate BOT? [Exchange rate automatic acquisition BOT]
Explanation of the basic functions of Exchange Rate BOT
Conclusion: A BOT is a program that performs specific tasks automatically.
The automatic exchange rate acquisition BOT is a small program with the following functions:
• Get the latest exchange rate information (e.g. USD → JPY) from the Internet
• Collect and record data on a regular basis
• Notify by email or LINE if necessary.
By using these bots,This reduces the effort required for daily information gathering to zero.
Moreover,You can add your favorite features by making it yourself.That is what is attractive about it.
In what situations is it useful?
Conclusion: Useful for anyone interested in currency and assets.
It is very useful in the following cases:
• I am doing foreign currency deposits or FX and am concerned about the exchange rate.
• I am involved in import/export business and need to check the exchange rate every day.
• I want to know my asset status in real time.
• I want to experience automation as part of my programming studies.
In addition, the exchange rate isBank of Japan and Ministry of FinanceHowever, it is attracting attention and is valuable as basic economic data.
👉 Exchange Information: Bank of Japan "Foreign Exchange Market Conditions"

How to handle foreign exchange data with Python [Python Foreign Exchange API]
What is an API? Let's understand it simply.
Bottom line: An API is an entry point for programmatically retrieving external information.
An API is a mechanism for receiving information.
The idea is to make a request from a program such as Python saying, "Please give me the information I need via a URL."
For example, you can access the exchange API as follows:
1 | <a rel="noopener" href="https://api.exchangerate-api.com/v4/latest/USD" title="https://api.exchangerate-api.com/v4/latest/USD" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://s.wordpress.com/mshots/v1/https%3A%2F%2Fapi.exchangerate-api.com%2Fv4%2Flatest%2FUSD?w=160&h=90" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90"></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">https://api.exchangerate-api.com/v4/latest/USD</div><div class="blogcard-snippet external-blogcard-snippet"></div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://api.exchangerate-api.com/v4/latest/USD" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16"></div><div class="blogcard-domain external-blogcard-domain">api.exchangerate-api.com</div></div></div></div></a> |
By reading such a URL from Python,Get current exchange rate dataIt is possible.
The basic steps for using the API are as follows:
1. Check the URL of the API provider
2. Loading URLs with Python
3. View or save the results
Introducing a free-to-use exchange API
Bottom line: If you’re a beginner, a free service like ExchangeRate-API is a great choice.
Below are the main free APIs and their features.
Service Name | Free use | number of currencies | Authentication Key |
ExchangeRate-API | 〇 | Approximately 170 currencies | Not required (simple version) |
Open Exchange Rates | 〇 | Approximately 170 currencies | Registration required |
currencyapi.net | 〇 | Approximately 150 currencies | Registration required |
Here,ExchangeRate-API without registration is used.
👉 Official website: https://www.exchangerate-api.com/
How to implement an exchange rate acquisition BOT [Python exchange rate automation]
Required libraries and preparation steps
Bottom line: the standard 'requests' library is all you need.
The preparations are as follows:
• Install Python (https://www.python.org/)
• Check the "requests" library (no installation required)
1 | pip install requests |
Basically, requests areOften included as standardSo you can use it with confidence.
Let's write some actual code
Bottom line: the code is simple, about 20 lines.
1 | import requests import datetime url = "https://api.exchangerate-api.com/v4/latest/USD" res = requests.get(url) data = res.json() rate = data[ "rates" ][ "JPY" ] time = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S" ) print (f "{time}|1USD = {rate}JPY" ) |
If you run this code, you will see something like this:
1 | 2025-06-04 12:00:00|1USD = 154.73JPY |
Just run it to get the latest rates.
Automate regular execution of exchange BOT [Python automatic execution method]
How to use the Task Scheduler (Windows)
Conclusion: If you want to run something at a certain time every day, use a scheduler.
procedure:
1. Save it as a .py file (e.g. fx_bot.py)
2. Open the Windows Task Scheduler
3. Create a basic task → Set execution time
4. Specify python fx_bot.py as the executable file.
Now,The bot runs automatically every day.
How to use cron (Mac/Linux)
Conclusion: In UNIX systems, it is executed periodically using "cron".
Below is an example that runs the BOT every day at 9am.
1 | crontab -e |
1 | 0 9 * * * /usr/bin/python3 /home/user/fx_bot.py |
The key is to not make a mistake in the file path.is.
Error handling and log saving techniques [Stable operation of exchange BOT]
How to deal with internet connection loss
Conclusion: The ideal code is one that doesn't stop even when an error occurs.
1 | try : res = requests.get(url, timeout = 10 ) data = res.json() print (f "{time}|1USD = {data['rates']['JPY']}JPY" ) except Exception as e: print ( "Failed to get:" , e) |
This will protect you from internet outages and API outages.A tolerable botIt will be.
Record the situation in a log file
Bottom line: Record the results of each run so you can look back on them later.
1 | with open ( "log.txt" , "a" ) as f: f.write(f "{time}|1USD = {rate}JPY\n" ) |
This way, you can easily get historical exchange data.Automatically accumulatescan.
It is also easy to load the data into Excel or other programs for analysis.
Various uses for exchange rates [How to use exchange rate data]
Can also be developed into a notification BOT or LINE integration
Bottom line: it would be even better if you could tell them the rate you got.
The following developments are possible:
• Email notification when the rate exceeds 150 yen
• Send to your smartphone using LINE Notify
• Easily connect to Discord, Slack, etc.
👉Related articles:I tried making a "spam mail detector" using Python
Examples of file saving and graphing applications
Bottom line: Collecting data over a long period of time and graphing it will help you see trends.
1 | import matplotlib.pyplot as plt # Plot after reading data from log (example) plt.plot(dates, rates) plt.title("USD to JPY") plt.xlabel("Date") plt.ylabel("Rate") plt.grid(True) plt.show() |
This means:Visually see the exchange rate trendsIt will look like this.
It is also ideal for learning and analysis.
Summary: Trying automation with Python [Python exchange BOT learning effect]
• With Python and APIs,You can easily create practical automation tools.
• To get exchange rates,A theme that even beginners can easily see results onis
• Notification function, graphing, log storage, etc.Examples of applications that broaden the scope of learningThere is also a lot
"I want to learn Python, but I don't know what to make."
If you are one of those people, please give this BOT creation a try.
While learning,Makes your daily work easier.
This is the beauty of programming.