Beispiel #1
0
 public function testSetAction()
 {
     $this->tradeData->setAction(TradeData::ACTION_BUY);
     $this->assertEquals(TradeData::ACTION_BUY, $this->tradeData->getAction());
     $this->tradeData->setAction('sell');
     $this->assertEquals(TradeData::ACTION_SELL, $this->tradeData->getAction());
     $this->tradeData->setAction('buY');
     $this->assertEquals(TradeData::ACTION_BUY, $this->tradeData->getAction());
     $this->setExpectedException('Exception', 'Action must be B or S');
     $this->tradeData->setAction('ccc');
 }
 public function getTradeDataCollectionForJob(Job $job)
 {
     $sql = "SELECT\n                  rq.id as id,\n                  s.id as security_id,\n                  sca.id as account_id,\n                  sca.account_number as account_number,\n                  st.name as security_type,\n                  rq.status as action,\n                  p.quantity as position_quantity,\n                  s.symbol as symbol,\n                  SUM(rq.quantity) as quantity,\n                  SUM(rq.amount) as amount,\n                  IF(p.quantity = SUM(rq.quantity) OR (rq.status = '" . QueueItem::STATUS_SELL . "' AND rq.lot_id IS NULL), 'AS', 'S') as quantity_type\n                FROM " . $this->table . " rq\n                  LEFT JOIN " . self::TABLE_SECURITY . " s on s.id = rq.security_id\n                  LEFT JOIN " . self::TABLE_SYSTEM_ACCOUNT . " sca ON sca.id = rq.system_client_account_id\n                  LEFT JOIN " . self::TABLE_SECURITY_TYPE . " st ON st.id = s.security_type_id\n                  LEFT JOIN " . self::TABLE_LOT . " l ON l.id = rq.lot_id\n                  LEFT JOIN " . self::TABLE_POSITION . " p ON p.id = l.position_id\n                  LEFT JOIN " . self::TABLE_REBALANCER_ACTION . " ra On ra.id = rq.rebalancer_action_id\n                WHERE ra.job_id = :jobId\n                GROUP BY sca.id, s.id\n                ORDER BY rq.id";
     $paramaters = array('jobId' => $job->getId());
     $results = $this->db->query($sql, $paramaters);
     $tradeDataCollection = new ArrayCollection();
     foreach ($results as $result) {
         $tradeData = new TradeData();
         $tradeData->loadFromArray($result);
         if ($tradeData->getAction() === TradeData::ACTION_SELL) {
             $vsps = $this->findVSPForTradeData($tradeData);
             $tradeData->setVsps($vsps);
         }
         $tradeData->setJobId($job->getId());
         $tradeDataCollection->add($tradeData);
     }
     return $tradeDataCollection;
 }