Example #1
0
 public function get()
 {
     $module = new MarketModule($this->client);
     $em = $this->getEntityManager();
     $countries = $em->getRepository('Erpk\\Common\\Entity\\Country');
     $industries = $em->getRepository('Erpk\\Common\\Entity\\Industry');
     $country = $countries->findOneByCode($this->getParameter('country'));
     $industry = $industries->findOneByCode($this->getParameter('industry'));
     $data = $module->scan($country, $industry, $this->getParameter('quality'), $this->getParameter('page'));
     $data['@nodeName'] = 'offer';
     $vm = new ViewModel($data);
     $vm->setRootNodeName('offers');
     return $vm;
 }
Example #2
0
 protected function scan()
 {
     try {
         $offers = $this->marketModule->scan($this->country, $this->industry, $this->quality);
     } catch (\Exception $e) {
         $this->output->writeln('<error>' . $e->getMessage() . '</error>');
         return;
     }
     $first = true;
     foreach ($offers as $offer) {
         if ($offer->price <= $this->priceLimit && $offer->amount >= $this->minimumAmount) {
             $startTime = microtime(true);
             $this->output->writeln('<info>Found offer: [ID: ' . $offer->id . '][Amount: ' . $offer->amount . ']</info>');
             $amount = $offer->amount;
             while ($this->toBuy > 0 && $amount > 0) {
                 if ($amount < 100000) {
                     if ($amount > $this->toBuy) {
                         $n = $this->toBuy;
                     } else {
                         $n = $amount;
                     }
                 } else {
                     if ($this->toBuy < 100000) {
                         $n = $this->toBuy;
                     } else {
                         $n = 99999;
                     }
                 }
                 $result = $this->marketModule->buy($offer, $n);
                 $msPassed = round((microtime(true) - $startTime) * 1000, 0);
                 $successful = fnmatch('You have successfully bought*', $result);
                 if ($successful) {
                     $amount -= $n;
                     $this->toBuy -= $n;
                 }
                 $this->output->writeln('<info>[' . $msPassed . ' ms passed][' . $result . '][Left: ' . $this->toBuy . ']</info>');
                 if (!$successful) {
                     break;
                 }
             }
         } elseif ($first) {
             $first = false;
             $this->pingLoader();
         }
     }
 }