.
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Logic\Crypto;
|
||||
|
||||
use App\Helper\Currency;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
|
||||
class MainObject
|
||||
{
|
||||
@@ -16,6 +17,16 @@ class MainObject
|
||||
private int $realValue=0;
|
||||
private float $price=0;
|
||||
private bool $isCrypto = false;
|
||||
private string $transactionType="";
|
||||
private string $marketName="";
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTransactionType(): string
|
||||
{
|
||||
return $this->transactionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
@@ -34,9 +45,9 @@ class MainObject
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRealCurrency(): string
|
||||
public function getRealCurrency(): ?string
|
||||
{
|
||||
return $this->realCurrency;
|
||||
}
|
||||
@@ -110,12 +121,28 @@ class MainObject
|
||||
*/
|
||||
public function setCurrency(string $currency): void
|
||||
{
|
||||
if (!in_array($currency, Currency::$currencies)) {
|
||||
if (!in_array($currency, Currency::$currencies) && !in_array($currency, Currency::$currenciesCrypto)) {
|
||||
$this->isCrypto = true;
|
||||
}
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $transactionType
|
||||
*/
|
||||
public function setTransactionType(string $transactionType): void
|
||||
{
|
||||
$this->transactionType = $transactionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $marketName
|
||||
*/
|
||||
public function setMarketName(string $marketName): void
|
||||
{
|
||||
$this->marketName = $marketName;
|
||||
}
|
||||
|
||||
public function addValue(int $val) : void
|
||||
{
|
||||
$this->value += $val;
|
||||
@@ -129,19 +156,31 @@ class MainObject
|
||||
$this->realValue += $val;
|
||||
}
|
||||
|
||||
public function takePrice() : void
|
||||
public function takePrice(bool $force = false) : void
|
||||
{
|
||||
if ($this->price && !$force) {
|
||||
return;
|
||||
}
|
||||
$real = $this->getRealValue() / 100;
|
||||
$val = $this->getValue();
|
||||
if ($this->isCrypto) {
|
||||
$val = $this->getValueCrypto();
|
||||
}
|
||||
$price = round($real/$val,8);
|
||||
// if ($this->isCrypto) {
|
||||
// $price *= self::_CRYPTO_DIVIDER;
|
||||
// } else {
|
||||
// $price *= 100;
|
||||
// }
|
||||
// if ($this->isCrypto) {
|
||||
// $price *= self::_CRYPTO_DIVIDER;
|
||||
// } else {
|
||||
// $price *= 100;
|
||||
// }
|
||||
$this->price = $price;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float|int $price
|
||||
*/
|
||||
public function setPrice($price): void
|
||||
{
|
||||
$this->price = $price;
|
||||
}
|
||||
|
||||
@@ -166,4 +205,67 @@ class MainObject
|
||||
$this->value = intval($this->value/self::_CRYPTO_DIVIDER*100);
|
||||
}
|
||||
}
|
||||
|
||||
public function trySetCurrencies() : void
|
||||
{
|
||||
if ($this->marketName) {
|
||||
if (strlen($this->marketName) === 6) {
|
||||
$cur1 = substr($this->marketName,0,3);
|
||||
$cur2 = substr($this->marketName,3);
|
||||
if ($this->transactionType === "BUY") {
|
||||
$this->setCurrency($cur1);
|
||||
$this->setRealCurrency($cur2);
|
||||
// $this->setPrice(-$this->getPrice());
|
||||
} else {
|
||||
$this->setCurrency($cur2);
|
||||
$this->setRealCurrency($cur1);
|
||||
}
|
||||
} else {
|
||||
$cryptoFiat = ["USDT"];
|
||||
foreach ($cryptoFiat as $item) {
|
||||
$currReal = strpos($this->marketName, $item);
|
||||
if ($currReal === false) {
|
||||
continue;
|
||||
}
|
||||
if ($currReal > 0) {
|
||||
$cur1 = substr($this->marketName, 0,strlen($this->marketName) - strlen($item));
|
||||
$cur2 = $item;
|
||||
} else {
|
||||
$cur1 = $item;
|
||||
$cur2 = substr($this->marketName, 0, strlen($this->marketName) - strlen($item));
|
||||
}
|
||||
if ($this->transactionType === "BUY") {
|
||||
$this->setCurrency($cur1);
|
||||
$this->setRealCurrency($cur2);
|
||||
// $this->setPrice(-$this->getPrice());
|
||||
} else {
|
||||
$this->setCurrency($cur2);
|
||||
$this->setRealCurrency($cur1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($this->getRealCurrency() === "USDT") {
|
||||
$this->setRealValue(-intval($this->getRealValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function currencyConversion() : void
|
||||
{
|
||||
if ($this->realCurrency === "PLN" || (!in_array($this->realCurrency, Currency::$currencies) && !in_array($this->realCurrency, Currency::$currenciesCrypto))) {
|
||||
return;
|
||||
}
|
||||
$eur = 4.5755;
|
||||
if ($this->realCurrency === "EUR") {
|
||||
$this->setRealValue(intval(round($this->getRealValue() * $eur)));
|
||||
$this->setRealCurrency("PLN");
|
||||
$this->takePrice(true);
|
||||
}
|
||||
// if ($this->realCurrency === "USDT") {
|
||||
// dd($this);
|
||||
// $this->setRealValue(intval(round($this->getRealValue() * ($eur/$this->getPrice()))));
|
||||
// $this->setRealCurrency("PLN");
|
||||
// $this->takePrice(true);
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user