Skip to content

Commit ea3dc8a

Browse files
committed
fix: fix getting price
1 parent bd1c1c1 commit ea3dc8a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Investments/Application/Command/TInvestUpdatePrices.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use App\Investments\Domain\Operations\DealRepositoryInterface;
1111
use App\Investments\Infrastructure\Http\TInvestHttpClient;
1212
use Doctrine\ORM\EntityManagerInterface;
13+
use Metaseller\TinkoffInvestApi2\exceptions\ValidateException;
14+
use Metaseller\TinkoffInvestApi2\helpers\QuotationHelper;
1315
use Symfony\Component\Console\Attribute\AsCommand;
1416
use Symfony\Component\Console\Command\Command;
1517
use Symfony\Component\Console\Input\InputInterface;
@@ -72,9 +74,9 @@ private function updateSharePrices(SymfonyStyle $io): void
7274
continue;
7375
}
7476

75-
$price = sprintf('%s.%s', $item->getPrice()?->getUnits() ?? '0', $item->getPrice()?->getNano() ?? '0');
77+
$price = QuotationHelper::toDecimal($item->getPrice());
7678
if ($price > 0) {
77-
$share->setPrice($price);
79+
$share->setPrice((string) $price);
7880
$this->em->persist($share);
7981
}
8082
$io->success(sprintf('%s: %s - %s', $share->getStockMarket(), $share->getTicker(), $share->getPrice()));
@@ -111,9 +113,9 @@ private function updateBondPrices(SymfonyStyle $io): void
111113
continue;
112114
}
113115

114-
$price = sprintf('%s.%s', $item->getPrice()?->getUnits() ?? '0', $item->getPrice()?->getNano() ?? '0');
116+
$price = QuotationHelper::toDecimal($item->getPrice());
115117
if ($price > 0) {
116-
$bond->setPrice($price);
118+
$bond->setPrice((string) $price);
117119
$this->em->persist($bond);
118120
}
119121
$io->success(sprintf('%s: %s (%s) - %s', $bond->getStockMarket(), $bond->getName(), $bond->getTicker(), $bond->getPrice()));
@@ -123,6 +125,9 @@ private function updateBondPrices(SymfonyStyle $io): void
123125
$io->success('Bond prices updated!');
124126
}
125127

128+
/**
129+
* @throws ValidateException
130+
*/
126131
private function updateFuturePrices(SymfonyStyle $io): void
127132
{
128133
$uids = [];
@@ -149,9 +154,9 @@ private function updateFuturePrices(SymfonyStyle $io): void
149154
continue;
150155
}
151156

152-
$price = sprintf('%s.%s', $item->getPrice()?->getUnits() ?? '0', $item->getPrice()?->getNano() ?? '0');
157+
$price = QuotationHelper::toDecimal($item->getPrice());
153158
if ($price > 0) {
154-
$future->setPrice($price);
159+
$future->setPrice((string) $price);
155160
$this->em->persist($future);
156161
}
157162
$io->success(sprintf('%s: %s (%s) - %s', $future->getStockMarket(), $future->getName(), $future->getTicker(), $future->getPrice()));

0 commit comments

Comments
 (0)