-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
258 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Services\Deals\Strategy; | ||
|
||
use App\Entity\Account; | ||
use App\Services\MarketData\Securities\SecurityTypeEnum; | ||
|
||
class BondStrategy implements DealStrategyInterface | ||
{ | ||
public function __construct(private readonly array $deal, Account $account) | ||
{ | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->deal['bondName']; | ||
} | ||
|
||
public function getSecurityType(): SecurityTypeEnum | ||
{ | ||
return SecurityTypeEnum::Bond; | ||
} | ||
|
||
public function getBuyPrice(): string | ||
{ | ||
return bcdiv(bcmul($this->deal['deal']->getBuyPrice(), $this->deal['bondLotSize'], 4), '100', 4); | ||
} | ||
|
||
public function getSellPrice(): string | ||
{ | ||
return bcdiv(bcmul($this->deal['deal']->getSellPrice(), $this->deal['bondLotSize'], 4), '100', 4); | ||
} | ||
|
||
public function getCurrentPrice(): string | ||
{ | ||
return bcdiv(bcmul($this->deal['bondPrice'], $this->deal['bondLotSize'], 4), '100', 4); | ||
} | ||
|
||
public function getPrevPrice(): string | ||
{ | ||
return bcdiv(bcmul($this->deal['bondPrevPrice'], $this->deal['bondLotSize'], 4), '100', 4); | ||
} | ||
|
||
public function getCommission(string $price, string $quantity): string | ||
{ | ||
return bcmul('0.5', $quantity, 4); | ||
} | ||
|
||
public function getCurrency(): string | ||
{ | ||
return $this->deal['bondCurrency'] ?? 'RUB'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Services\Deals\Strategy; | ||
|
||
use App\Entity\Account; | ||
use App\Entity\Deal; | ||
use App\Services\MarketData\Securities\SecurityTypeEnum; | ||
|
||
interface DealStrategyInterface | ||
{ | ||
/** @param array{ | ||
* deal: Deal, | ||
* shareName?: string, | ||
* bondName?: string, | ||
* futureName?: string, | ||
* sharePrice?: string, | ||
* sharePrevPrice?: string, | ||
* bondPrice?: string, | ||
* bondPrevPrice?: string, | ||
* bondLotSize?: string, | ||
* futurePrice?: string, | ||
* futurePrevPrice?: string, | ||
* futureStepPrice?: string, | ||
* futureLotSize?: string, | ||
* shareCurrency?: string, | ||
* futureCurrency?: string, | ||
* bondCurrency?: string, | ||
* } $deal | ||
*/ | ||
public function __construct(array $deal, Account $account); | ||
|
||
public function getName(): string; | ||
|
||
public function getSecurityType(): SecurityTypeEnum; | ||
|
||
public function getBuyPrice(): string; | ||
|
||
public function getSellPrice(): string; | ||
|
||
public function getCurrentPrice(): string; | ||
|
||
public function getPrevPrice(): string; | ||
|
||
public function getCommission(string $price, string $quantity): string; | ||
|
||
public function getCurrency(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Services\Deals\Strategy; | ||
|
||
use App\Entity\Account; | ||
use App\Services\MarketData\Securities\SecurityTypeEnum; | ||
|
||
class FutureStrategy implements DealStrategyInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function __construct(private readonly array $deal, Account $account) | ||
{ | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->deal['futureName']; | ||
} | ||
|
||
public function getSecurityType(): SecurityTypeEnum | ||
{ | ||
return SecurityTypeEnum::Future; | ||
} | ||
|
||
public function getBuyPrice(): string | ||
{ | ||
if ($this->deal['deal']->getBuyPrice() > $this->deal['futureLotSize']) { | ||
return bcmul($this->deal['deal']->getBuyPrice(), $this->deal['futureStepPrice'], 4); | ||
} | ||
|
||
return bcmul(bcmul($this->deal['deal']->getBuyPrice(), $this->deal['futureStepPrice'], 4), $this->deal['futureLotSize'], 4); | ||
} | ||
|
||
public function getSellPrice(): string | ||
{ | ||
if ($this->deal['deal']->getSellPrice() > $this->deal['futureLotSize']) { | ||
return bcmul($this->deal['deal']->getSellPrice(), $this->deal['futureLotSize'], 4); | ||
} | ||
return bcmul(bcmul($this->deal['deal']->getSellPrice(), $this->deal['futureStepPrice'], 4), $this->deal['futureLotSize'], 4); | ||
} | ||
|
||
public function getCurrentPrice(): string | ||
{ | ||
if ($this->deal['futurePrice'] > $this->deal['futureLotSize']) { | ||
return bcmul($this->deal['futurePrice'], $this->deal['futureStepPrice'], 4); | ||
} | ||
return bcmul(bcmul($this->deal['futurePrice'], $this->deal['futureStepPrice'], 4), $this->deal['futureLotSize'], 4); | ||
} | ||
|
||
public function getPrevPrice(): string | ||
{ | ||
if ($this->deal['futurePrevPrice'] > $this->deal['futureLotSize']) { | ||
return bcmul($this->deal['futurePrevPrice'], $this->deal['futureStepPrice'], 4); | ||
} | ||
|
||
return bcmul(bcmul($this->deal['futurePrevPrice'], $this->deal['futureStepPrice'], 4), $this->deal['futureLotSize'], 4); | ||
} | ||
|
||
public function getCommission(string $price, string $quantity): string | ||
{ | ||
return bcmul('5', $quantity, 4); | ||
} | ||
|
||
public function getCurrency(): string | ||
{ | ||
return $this->deal['futureCurrency'] ?? 'RUB'; | ||
} | ||
} |
Oops, something went wrong.