add exante and ibkr

This commit is contained in:
2023-04-12 15:13:55 +02:00
parent 90952d883e
commit fc1ef6f3ec
17 changed files with 439 additions and 75 deletions
+14 -4
View File
@@ -7,7 +7,7 @@ use Doctrine\ORM\EntityManager;
class Currency
{
public static array $currencies = ["USD","GBP","PLN","EUR"];
public static array $currencies = ["USD","GBP","PLN","EUR","CAD"];
public static array $currenciesCrypto = ["USDT"];
private static string $apiUrl = "https://api.nbp.pl/api/exchangerates/rates/a/:code/:date/?format=json";
private EntityManager $manager;
@@ -19,7 +19,7 @@ class Currency
$this->takeRates();
}
public function getRate(string $currency, \DateTime $dateTime, &$err) : float
public function getRate(string $currency, \DateTime $dateTime) : float
{
$dayOfWeek = $dateTime->format("N");
$minusDay = 1;
@@ -35,12 +35,16 @@ class Currency
return $this->ratesPerDate[$currency][$dateStr];
}
$dateCopy = clone $dateTime;
$limitLoop = 5;
do {
$rate = $this->takePLNOnDate($currency, $dateCopy->format("Y-m-d"));
if (!$rate) {
$dateCopy->modify("-1 day");
}
if ($limitLoop < 1) {
break;
}
$limitLoop--;
}while($rate == 0);
if ($rate) {
@@ -61,7 +65,7 @@ class Currency
private function takePLNOnDate(string $currency, string $dateStr) : float
{
if (!in_array($currency, self::$currencies)) {
if (!self::isCurrencyExists($currency)) {
return 0;
}
$url = strtr(self::$apiUrl,[
@@ -95,4 +99,10 @@ class Currency
}
}
}
public static function isCurrencyExists(string $currency) : bool
{
return in_array($currency, self::$currencies);
}
}