예제 #1
0
 /**
  * Get buy and sell limit
  * Returns max amount which can be sold and bought
  *
  * @param SubclassCollection $subclassCollection
  * @param Account $contextAccount
  * @return float
  */
 public function getBuyAndSellLimit(SubclassCollection $subclassCollection, Account $contextAccount = null)
 {
     $sellAmount = 0;
     $buyAmount = 0;
     if ($subclassCollection->isOutOfBalance()) {
         /** @var Subclass $subclass */
         foreach ($subclassCollection as $subclass) {
             if ($subclass->calcOOB() == 0) {
                 continue;
             }
             $amount = $subclassCollection->getOnePercentAmount() * abs($subclass->calcOOB());
             if ($subclass->calcOOB() > 0) {
                 if ($contextAccount) {
                     $sellAmount += $this->sellSubclass($subclass, $contextAccount, $amount, true);
                 } else {
                     $sellAmount += $this->sellSubclassHousehold($subclass, $amount, true);
                 }
             } elseif ($subclass->calcOOB() < 0) {
                 if ($contextAccount) {
                     $buyAmount += $this->buySubclass($subclass, $contextAccount, $amount, true);
                 } else {
                     $buyAmount += $this->buySubclassHousehold($subclass, $amount, true);
                 }
             }
         }
     }
     $result = min($sellAmount, $buyAmount);
     $this->logger->logInfo("Limit for buy and sell: {$result}.");
     return $result;
 }
예제 #2
0
 public function testGetOnePercentAmount()
 {
     $this->assertEquals(150, $this->subclassCollection->getOnePercentAmount());
 }