Skip to content

Commit

Permalink
Added skipping data updates if they have already been updated by anot…
Browse files Browse the repository at this point in the history
…her service.
  • Loading branch information
simba77 committed Jul 17, 2024
1 parent f302dff commit e32a375
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/Command/GetBondsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Entity\Bond;
use App\Services\AccountCalculator;
use App\Services\MarketData\Securities\MoexBondsProvider;
use Carbon\Carbon;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -39,6 +40,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($bonds as $item) {
$bond = $bondRepository->findOneBy(['ticker' => $item->getTicker()]);
if ($bond) {
$updatePeriodStart = Carbon::now()->subMinutes(5);
$updated = $bond->updatedAt();

// If the share has been updated by another service, skip this update
if($updatePeriodStart->diffInMinutes($updated) < 5) {
continue;
}

if (empty($item->getPrice())) {
continue;
}
Expand Down
11 changes: 11 additions & 0 deletions src/Command/GetFuturesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Entity\Future;
use App\Services\AccountCalculator;
use App\Services\MarketData\Securities\MoexFuturesProvider;
use Carbon\Carbon;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -37,6 +38,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($futures as $item) {
$future = $futureRepository->findOneBy(['ticker' => $item->getTicker()]);
if ($future) {

$updatePeriodStart = Carbon::now()->subMinutes(5);
$updated = $future->updatedAt();

// If the share has been updated by another service, skip this update
if($updatePeriodStart->diffInMinutes($updated) < 5) {
continue;
}


if (empty($item->getPrice())) {
continue;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Command/GetMoexSharesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Entity\Share;
use App\Services\AccountCalculator;
use App\Services\MarketData\Securities\MoexSharesProvider;
use Carbon\Carbon;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -37,6 +38,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($shares as $item) {
$share = $shareRepository->findOneBy(['ticker' => $item->getTicker()]);
if ($share) {

$updatePeriodStart = Carbon::now()->subMinutes(5);
$updated = $share->updatedAt();

// If the share has been updated by another service, skip this update
if($updatePeriodStart->diffInMinutes($updated) < 5) {
continue;
}

if (empty($item->getPrice())) {
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Command/ScheduleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// Tasks
$scheduler->php($rootDir . '/bin/console accounts:save-stat')->everyMinute(30);
$scheduler->php($rootDir . '/bin/console securities:get-moex-bonds')->everyMinute(5);
$scheduler->php($rootDir . '/bin/console securities:get-moex-bonds')->everyMinute(15);
$scheduler->php($rootDir . '/bin/console currency:get-rates')->everyMinute();
$scheduler->php($rootDir . '/bin/console securities:get-moex-futures')->everyMinute(5);
$scheduler->php($rootDir . '/bin/console securities:get-moex-shares')->everyMinute(5);
$scheduler->php($rootDir . '/bin/console securities:get-moex-futures')->everyMinute(15);
$scheduler->php($rootDir . '/bin/console securities:get-moex-shares')->everyMinute(15);
// $scheduler->php($rootDir . '/bin/console securities:get-spb-shares')->everyMinute(5);
$scheduler->php($rootDir . '/bin/console securities:get-tinvest-shares')->daily(22);
$scheduler->php($rootDir . '/bin/console securities:get-market-data')->everyMinute(2);
Expand Down

0 comments on commit e32a375

Please sign in to comment.