diff --git a/README.md b/README.md index 8699254..ccf75b2 100755 --- a/README.md +++ b/README.md @@ -89,13 +89,14 @@ foreach ($portfolioResponse->getPayload()->getPositions() as $position) { // Пример 3. Создание лимитной заявки use Dzhdmitry\TinkoffInvestApi\TinkoffInvest; use Dzhdmitry\TinkoffInvestApi\Schema\Request\LimitOrderRequest; +use Dzhdmitry\TinkoffInvestApi\Schema\Enum\OperationType; // Создать клиент с токеном $client = TinkoffInvest::create('YOUR_TRADE_TOKEN'); -// Сделать запрос на создание лимитной заявки на счете "Тинькофф" +// Сделать запрос на создание лимитной заявки на счете "Тинькофф" (Заявка на покупку 5 лотов USD по цене 75.20) $limitOrderResponse = $client->orders()->postLimitOrder( 'BBG0013HGFT4', - new LimitOrderRequest(5, 'Buy', 75.20) + new LimitOrderRequest(5, OperationType::BUY, 75.20) ); $order = $limitOrderResponse->getPayload(); diff --git a/src/TinkoffInvest.php b/src/TinkoffInvest.php index 7254197..6d23944 100644 --- a/src/TinkoffInvest.php +++ b/src/TinkoffInvest.php @@ -8,8 +8,6 @@ use Dzhdmitry\TinkoffInvestApi\Api\Portfolio; use Dzhdmitry\TinkoffInvestApi\Api\Sandbox; use Dzhdmitry\TinkoffInvestApi\Api\User; -use Dzhdmitry\TinkoffInvestApi\Schema\Payload as Types; -use Dzhdmitry\TinkoffInvestApi\Schema\Response\OrdersResponse; use GuzzleHttp\Client; class TinkoffInvest @@ -21,6 +19,36 @@ class TinkoffInvest */ private RestClient $client; + /** + * @var Market|null + */ + private ?Market $market = null; + + /** + * @var Operations|null + */ + private ?Operations $operations = null; + + /** + * @var Orders|null + */ + private ?Orders $orders = null; + + /** + * @var Portfolio|null + */ + private ?Portfolio $portfolio = null; + + /** + * @var Sandbox|null + */ + private ?Sandbox $sandbox = null; + + /** + * @var User|null + */ + private ?User $user = null; + /** * @param RestClient $client */ @@ -50,7 +78,11 @@ public static function create(string $token): TinkoffInvest */ public function market(): Market { - return new Market($this->client); + if ($this->market === null) { + $this->market = new Market($this->client); + } + + return $this->market; } /** @@ -58,7 +90,11 @@ public function market(): Market */ public function operations(): Operations { - return new Operations($this->client); + if ($this->operations === null) { + $this->operations = new Operations($this->client); + } + + return $this->operations; } /** @@ -66,7 +102,11 @@ public function operations(): Operations */ public function orders(): Orders { - return new Orders($this->client); + if ($this->orders === null) { + $this->orders = new Orders($this->client); + } + + return $this->orders; } /** @@ -74,7 +114,11 @@ public function orders(): Orders */ public function portfolio(): Portfolio { - return new Portfolio($this->client); + if ($this->portfolio === null) { + $this->portfolio = new Portfolio($this->client); + } + + return $this->portfolio; } /** @@ -82,7 +126,11 @@ public function portfolio(): Portfolio */ public function sandbox(): Sandbox { - return new Sandbox($this->client); + if ($this->sandbox === null) { + $this->sandbox = new Sandbox($this->client); + } + + return $this->sandbox; } /** @@ -90,7 +138,11 @@ public function sandbox(): Sandbox */ public function user(): User { - return new User($this->client); + if ($this->user === null) { + $this->user = new User($this->client); + } + + return $this->user; } /**