Beispiel #1
0
 protected function loop()
 {
     $this->output->writeln('Starting...');
     while (true) {
         try {
             $offers = $this->exchangeModule->scan($this->buy);
             $this->pingLoader();
             $accounts = array(ExchangeModule::CURRENCY => $offers->getCurrencyAmount(), ExchangeModule::GOLD => $offers->getGoldAmount());
             foreach ($offers as $offer) {
                 if ($offer->rate <= $this->priceLimit) {
                     $this->output->writeln("[ID: {$offer->id}][Amount: {$offer->amount}]" . "[Rate: {$offer->rate}][{$offer->sellerId}:{$offer->sellerName}]");
                     $toBuy = $offer->amount;
                     if ($this->buy == ExchangeModule::GOLD && $toBuy > 10) {
                         $toBuy = 10;
                     }
                     if ($toBuy * $offer->rate > $accounts[$this->sell]) {
                         $toBuy = round($accounts[$this->sell] / $offer->rate, 2) - 0.01;
                     }
                     if ($toBuy > 0) {
                         $this->buy($offer, $toBuy);
                     }
                 }
             }
         } catch (\Exception $e) {
             if ($this->output->isVerbose()) {
                 $this->output->writeln('<error>' . $e->getMessage() . '</error>');
             }
         }
         usleep($this->scanInterval * 1000000);
     }
 }
Beispiel #2
0
 public function get()
 {
     switch ($this->getParameter('mode')) {
         case 'cc':
             $buy = ExchangeModule::CURRENCY;
             break;
         case 'gold':
         default:
             $buy = ExchangeModule::GOLD;
             break;
     }
     $module = new ExchangeModule($this->client);
     $offers = $module->scan($buy, $this->getParameter('page'));
     $data = array('paginator' => $offers->getPaginator()->toArray(), 'offers' => $offers->getArrayCopy());
     $data['offers']['@nodeName'] = 'offer';
     $vm = new ViewModel($data);
     $vm->setRootNodeName('offers');
     return $vm;
 }