Guest User

Bitcoin Exchange BTC-e Guzzle PHP Command Class

a guest
Apr 17th, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace Lmh\Bundle\SpreadTradeBundle\Btce\Command;
  4.  
  5. use BitcoinExchangeRestApi\Command\DynamicCommand;
  6.  
  7. class PrivateCommand extends DynamicCommand
  8. {
  9.  
  10.     protected $nonce;
  11.  
  12.     /**
  13.      * @see http://pastebin.com/QyjS3U9M
  14.      */
  15.     protected function build()
  16.     {
  17.         parent::build();
  18.  
  19.         $apiKey = $this->client->getApiKey();
  20.         $apiSecret = $this->client->getApiSecret();
  21.  
  22.         $this->request->addPostFields(array(
  23.             'method' => $this->getName(),
  24.             'nonce' => $this->getNonce(),
  25.         ));
  26.  
  27.         $postData = $this->request->getPostFields();
  28.         $signature = hash_hmac('sha512', $postData, $apiSecret);
  29.  
  30.         $this->request->addHeader('Sign', $signature);
  31.         $this->request->addHeader('Key', $apiKey);
  32.     }
  33.  
  34.     public function setNonce($nonce)
  35.     {
  36.         $this->nonce = $nonce;
  37.     }
  38.  
  39.     public function getNonce()
  40.     {
  41.         if(is_null($this->nonce)) {
  42.             $this->setNonce(self::generateNonce());
  43.         }
  44.         return $this->nonce;
  45.     }
  46.  
  47.     public static function generateNonce() {
  48.         $mt = explode(' ', microtime());
  49.         return $mt[1];
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment