Skip to content

Commit

Permalink
Уменьшено потребление памяти
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhdmitry committed Apr 7, 2021
1 parent 9ad9663 commit 3507acc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
68 changes: 60 additions & 8 deletions src/TinkoffInvest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -50,47 +78,71 @@ 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;
}

/**
* @return Operations
*/
public function operations(): Operations
{
return new Operations($this->client);
if ($this->operations === null) {
$this->operations = new Operations($this->client);
}

return $this->operations;
}

/**
* @return Orders
*/
public function orders(): Orders
{
return new Orders($this->client);
if ($this->orders === null) {
$this->orders = new Orders($this->client);
}

return $this->orders;
}

/**
* @return Portfolio
*/
public function portfolio(): Portfolio
{
return new Portfolio($this->client);
if ($this->portfolio === null) {
$this->portfolio = new Portfolio($this->client);
}

return $this->portfolio;
}

/**
* @return Sandbox
*/
public function sandbox(): Sandbox
{
return new Sandbox($this->client);
if ($this->sandbox === null) {
$this->sandbox = new Sandbox($this->client);
}

return $this->sandbox;
}

/**
* @return User
*/
public function user(): User
{
return new User($this->client);
if ($this->user === null) {
$this->user = new User($this->client);
}

return $this->user;
}

/**
Expand Down

0 comments on commit 3507acc

Please sign in to comment.