public function findById($id)
 {
     $sql = "SELECT rq.*, ra.job_id FROM " . self::TABLE_REBALANCER_QUEUE . " rq\n                  LEFT JOIN " . self::TABLE_REBALANCER_ACTION . " ra On ra.id = rq.rebalancer_action_id\n                  WHERE rq.id = :id\n                  ";
     $result = $this->db->queryOne($sql, array('id' => $id));
     if (empty($result)) {
         return null;
     }
     /** @var QueueItem $item */
     $item = $this->bindObject($result);
     if (isset($result['security_id'])) {
         $security = new Security();
         $security->setId($result['security_id']);
         $item->setSecurity($security);
     }
     if (isset($result['system_client_account_id'])) {
         $account = new Account();
         $account->setId($result['system_client_account_id']);
         $item->setAccount($account);
     }
     if (isset($result['lot_id'])) {
         $lot = new Lot();
         $lot->setId($result['lot_id']);
         $item->setLot($lot);
     }
     return $item;
 }
Пример #2
0
 public function testSetSecurities()
 {
     $securityCollection = new SecurityCollection();
     $security = new Security();
     $security->setId(96);
     $securityCollection->add($security);
     $this->portfolio->setSecurities($securityCollection);
     $securities = $this->portfolio->getSecurities();
     $this->assertCount(1, $securities);
     $this->assertEquals(96, $securities->get(96)->getId());
 }
Пример #3
0
 protected function bindSubclassCollection(array $data, SecurityCollection $securityCollection)
 {
     $subclassCollection = new SubclassCollection();
     foreach ($data as $values) {
         $subclass = new Subclass();
         $subclass->loadFromArray($values);
         /** @var Security $security */
         $security = $securityCollection->get($values['security_id']);
         $security->setSubclass($subclass);
         $subclass->setSecurity($security);
         if (isset($values['muni_substitution_id']) && $values['muni_substitution_id']) {
             $sql = "SELECT sp.price FROM " . self::TABLE_SECURITY_PRICE . " sp\n                        WHERE sp.is_current = true AND sp.security_id = :security_id\n                          ORDER BY sp.datetime DESC\n                          LIMIT 1\n                        ";
             $parameters = array('security_id' => $values['muni_substitution_id']);
             $securityPriceData = $this->db->query($sql, $parameters);
             $muni = new Security();
             $muni->setId($values['muni_substitution_id']);
             $muni->setSubclass($subclass);
             $muni->setIsPreferredBuy(true);
             $muni->setName($values['muni_name']);
             $muni->setSymbol($values['muni_symbol']);
             $muni->setPrice($securityPriceData[0]['price']);
             $subclass->setMuniSecurity($muni);
         }
         $subclassCollection->add($subclass);
     }
     return $subclassCollection;
 }
Пример #4
0
 public function testSellAllSecurities()
 {
     $security1 = new Security();
     $security1->setId(15);
     $security1->setQty(200);
     $security2 = new Security();
     $security2->setId(20);
     $security2->setQty(400);
     $securityCollection = new SecurityCollection();
     $securityCollection->add($security1);
     $securityCollection->add($security2);
     $this->account->setSecurities($securityCollection);
     $this->account->sellAllSecurities();
     $qty = 0;
     foreach ($this->account->getSecurities() as $security) {
         $qty += $security->getQty();
     }
     $this->assertEquals(0, $qty);
 }
Пример #5
0
 public function testSetTaxLossHarvesting()
 {
     $taxLossHarvesting = new Security();
     $taxLossHarvesting->setId(12);
     $this->subclass->setTaxLossHarvesting($taxLossHarvesting);
     $this->assertEquals(12, $this->subclass->getTaxLossHarvesting()->getId());
 }