feature exchange rate update automation

Automated downloading exchange rates from HMRC and updating the database. Added function call to the console and form applications.

Also added a form to show the console output in form application.
This commit is contained in:
Bobbie Hodgetts
2025-06-09 20:56:26 +01:00
committed by GitHub
parent 8e7cd00b74
commit ea0a52b2a0
25 changed files with 1095 additions and 179 deletions
@@ -0,0 +1,191 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Model.Account
{
public enum CurrencyCode
{
AED,
AFN,
ALL,
AMD,
ANG,
AOA,
ARS,
AUD,
AWG,
AZN,
BAM,
BBD,
BDT,
BGN,
BHD,
BIF,
BMD,
BND,
BOB,
BOV,
BRL,
BSD,
BTN,
BWP,
BYN,
BYR,
BZD,
CAD,
CDF,
CHE,
CHF,
CHW,
CLF,
CLP,
CNY,
COP,
COU,
CRC,
CUC,
CUP,
CVE,
CZK,
DJF,
DKK,
DOP,
DZD,
EGP,
ERN,
ETB,
EUR,
FJD,
FKP,
GBP,
GEL,
GHS,
GIP,
GMD,
GNF,
GTQ,
GYD,
HKD,
HNL,
HRK,
HTG,
HUF,
IDR,
ILS,
INR,
IQD,
IRR,
ISK,
JMD,
JOD,
JPY,
KES,
KGS,
KHR,
KMF,
KPW,
KRW,
KWD,
KYD,
KZT,
LAK,
LBP,
LKR,
LRD,
LSL,
LYD,
MAD,
MDL,
MGA,
MKD,
MMK,
MNT,
MOP,
MRO,
MUR,
MVR,
MWK,
MXN,
MXV,
MYR,
MZN,
NAD,
NGN,
NIO,
NOK,
NPR,
NZD,
OMR,
PAB,
PEN,
PGK,
PHP,
PKR,
PLN,
PYG,
QAR,
RON,
RSD,
RUB,
RWF,
SAR,
SBD,
SCR,
SDG,
SEK,
SGD,
SHP,
SLL,
SOS,
SRD,
SSP,
STD,
SVC,
SYP,
SZL,
THB,
TJS,
TMT,
TND,
TOP,
TRY,
TTD,
TWD,
TZS,
UAH,
UGX,
USD,
USN,
UYI,
UYU,
UZS,
VEF,
VND,
VUV,
WST,
XAF,
XAG,
XAU,
XBA,
XBB,
XBC,
XBD,
XCD,
XDR,
XOF,
XPD,
XPF,
XPT,
XSU,
XTS,
XUA,
XXX,
YER,
ZAR,
ZMW,
ZWL
}
}
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Model.Account
{
public class CurrencyExchangeRate
{
public CurrencyExchangeRate(CurrencyCode currencyCode, int exchangeRateSource, DateTime dateTimeStartUtc, DateTime dateTimeEndUtc)
{
this.CurrencyCode = currencyCode;
this.ExchangeRateSource = exchangeRateSource;
if (dateTimeEndUtc > dateTimeStartUtc)
{
this.DateTimeStartUtc = dateTimeStartUtc;
this.DateTimeEndUtc = dateTimeEndUtc;
}
else
{
throw new ArgumentException("Incorrect start and/or end date value(s)");
}
}
public CurrencyCode CurrencyCode { get; private set; }
public int ExchangeRateSource { get; private set; }
public decimal CurrencyUnitsPerGbp { get; private set; }
public DateTime DateTimeStartUk
{
get
{
return new Logic.Utilities.DateTime().ConvertUtcToUk(DateTimeStartUtc);
}
}
public DateTime DateTimeStartUtc { get; private set; }
public DateTime DateTimeEndUk
{
get
{
return new Logic.Utilities.DateTime().ConvertUtcToUk(DateTimeEndUtc);
}
}
public DateTime DateTimeEndUtc { get; private set; }
/// <summary>
/// Checks whether a given datetime falls within the the exchange rate period
/// </summary>
/// <param name="dateTimeToCheck">The date and time to check</param>
/// <returns>True or false</returns>
public bool DateTimeWithinPeriodCheck(DateTime dateTimeToCheck)
{
if (dateTimeToCheck >= DateTimeStartUtc && dateTimeToCheck < DateTimeEndUtc)
{
return true;
}
else
{
return false;
}
}
}
}
@@ -28,7 +28,7 @@ namespace bnhtrade.Core.Model.Credentials
{
return "Data Source=" + DataSource + ";Initial Catalog=" + InitialCatalog + ";Persist Security Info=" + PersistSecurityInfo.ToString()
+ ";User ID=" + UserId + ";Password=" + UserPassword + ";MultipleActiveResultSets=" + MultipleActiveResultSets.ToString()
+ ";Connect Timeout=" + ConnectionTimeout;
+ ";Connect Timeout=" + ConnectionTimeout + ";Encrypt=True;TrustServerCertificate=True";
}
}