예제 #1
0
 protected function bindCollection(array $data)
 {
     $collection = new SecurityCollection();
     foreach ($data as $values) {
         $element = new Security();
         $element->loadFromArray($values);
         $collection->add($element);
     }
     return $collection;
 }
예제 #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
 /**
  * Get collection of securities mock
  *
  * @param array $data
  * @return SecurityCollection
  */
 private function getMockSecurityCollection(array $data = array())
 {
     $collection = new SecurityCollection();
     foreach ($data as $item) {
         $security = $this->getMockSecurity($item);
         $collection->add($security);
     }
     return $collection;
 }
예제 #4
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;
 }
예제 #5
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);
 }