Currency Rate Updater

This tool automatically updates your foreign currency exchange rates in Spire. The update uses the Bank of Canada web site and updates your Spire exchange rates. You can easily schedule this task to run daily.

Installation

The install package can be downloaded from here: SpireCurrencyUpdater

You can install this on either your Spire server or a workstation (or both!). If you are planning to schedule the update to run automatically, the server is a better choice. Just run the installer program on your choice of computer.

Configuration

The program installs a configuration file here:

C:\ProgramData\SpireAssists\CurrencyUpdater\settings.json

Here is an example:

{
    "spire_server": "http://localhost:10880",
    "company": "INSPIRE",
    "username": "a",
    "password": "a",
    "currencies": [
        "USD",
        "EUR",
        "GBP",
        "JPY"
    ]
}
  1. Edit the “spire_server” entry to your server name or IP. When installing on a Spire server, http://localhost:10880 will suffice. Use https if using Spire server hostname such as: https://cooperative-snow-5223.spirelan.com:10880 from a workstation.
  2. Edit the “company”, “username” and “password” to use Spire database name, and Spire user\password.
  3. Edit the list of currencies you want to update.

Test

In a command prompt, paste and run the following:

"C:\Program Files\SpireAssists\CurrencyUpdater\CurrencyUpdater.exe" -v

Sample Output

This is a successful output:

C:\Program Files\SpireAssists\CurrencyUpdater\CurrencyUpdater.exe -v

Loading config from: C:\ProgramData\SpireAssists\CurrencyUpdater\settings.json
Getting current exchange rates...
--------------------------------------------------
Raw API value for FXCADUSD: 0.7125
USD: 0.7125
Raw API value for FXCADEUR: 0.6105
EUR: 0.6105
Raw API value for FXCADGBP: 0.5310
GBP: 0.531
Raw API value for FXCADJPY: 107.1811
JPY: 107.1811

Updating Spire exchange rates...
--------------------------------------------------

Sending PUT request to http://localhost:10880/api/v2/companies/INSPIRE/currencies/9
JSON payload: {
  "code": "USD",
  "rate": "1.4035087719298245"
}

Sending PUT request to http://localhost:10880/api/v2/companies/INSPIRE/currencies/11
JSON payload: {
  "code": "EUR",
  "rate": "1.6380016380016378"
}

Sending PUT request to http://localhost:10880/api/v2/companies/INSPIRE/currencies/12
JSON payload: {
  "code": "GBP",
  "rate": "1.8832391713747645"
}
✓ USD: Successfully updated
✓ EUR: Successfully updated
✓ GBP: Successfully updated
✗ JPY: Currency not found

C:\Scripts\CurrencyUpdater>

You can confirm that the process completed. Check Spire for the updated rates. If you want this to be a manual process, you can simply double-click to run CurrencyUpdater.exe as required.

Automating

Included in the package is a batch file to create a scheduled task. Batch file is located here:

C:\Program Files\SpireAssists\CurrencyUpdater\CreateScheduledTask.bat

This will create a scheduled task that will run at midnight every day. You can review and edit this task in the Windows Task Scheduler.

Right click on this batch file and choose “Run as Administrator”

Here is a sample of the batch file that creates the scheduled task that runs every day at midnight and starts it running. You can edit as required.

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set "TASKNAME=CurrencyUpdater"
set "EXE=%~dp0CurrencyUpdater.exe"
set "WD=%~dp0"
set "TIME=00:00"

if not exist "%EXE%" (
    echo ERROR: Expected executable not found at "%EXE%".
    exit /b 1
)

schtasks /Create /TN "%TASKNAME%" /TR "%EXE%" /SC DAILY /ST %TIME% /RU SYSTEM /RL HIGHEST /F

if errorlevel 1 (
    echo Failed to create task "%TASKNAME%".
    exit /b 1
)

for /f "tokens=1,* delims=:" %%A in ('schtasks /Query /TN "%TASKNAME%" /FO LIST /V ^| findstr /C:"Next Run Time"') do (
    set "NEXT=%%B"
)
for /f "tokens=*" %%N in ("!NEXT!") do set "NEXT=%%N"

echo Created task "%TASKNAME%" running from "%WD%".
if defined NEXT echo Next run time: !NEXT!
endlocal

Conclusion

This program only updates the current rate for the currencies. With Spire 3.12 and above it is possible to update the monthly rate tables. This means that backdated transactions will use the rate that was effective on the last day of that month. For this and other advanced features, contact peter@wright-stuff.com