title: API Call Authentication in Python ( Working PHP example )
body: <p>I'm trying to write a script to communicate with an online exchange.<br>
  'Public' requests are sent to : <a href="https://yobit.net/api/3/" rel="nofollow noreferrer">https://yobit.net/api/3/</a><br>
  'Trade' requests are sent to: <a href="https://yobit.net/tapi/" rel="nofollow noreferrer">https://yobit.net/tapi/</a></p>
  
  <p>My public requests work great. My 'private calls' however return a 404 error.
  My keys are 100% correct.<br>
  I currently produce the following URL:    <strong><a href="https://yobit.net/tapi/activeorders/ltc_btc/&amp;apikey=MY_APIKEY_HERE&amp;nonce=1456192036" rel="nofollow noreferrer">https://yobit.net/tapi/activeorders/ltc_btc/&amp;apikey=MY_APIKEY_HERE&amp;nonce=1456192036</a></strong></p>
  
  <p>Did I missinterpret the documentation? Perhaps a false URL structure? </p>
  
  <p><strong>Documentation</strong> Link ---> <a href="https://yobit.net/en/api/" rel="nofollow noreferrer">here</a><br>
  Each Trade API request should pass authentication.
  Authentication is fulfilled by sending the following HTTP-titles:
  Key - API-key, example: FAF816D16FFDFBD1D46EEF5D5B10D8A2
  Sign - digital signature, POST-parameters (?param0=val0 &amp; ...&amp; nonce=1) signed by secret key through HMAC-SHA512
  Parameter nonce (1 minimum to 2147483646 maximum) in succeeding request should exceed that in the previous one.
  To null nonce it is necessary to generate new key.</p>
  
  <p><strong>My script</strong></p>
  
  <pre><code>class yobit(object):
  
  def __init__(self, key, secret):
      self.key = key
      self.secret = secret
      self.public = ['info', 'ticker', 'depth', 'trades']
      self.trade = ['activeorders']
  
  
  def query(self, method, values={}):
      if method in self.public:
          url = 'https://yobit.net/api/3/'
      elif method in self.trade:
          url = 'https://yobit.net/tapi/'
      else:
          return 'You're doing it wrong'
  
      urlString = ''
      for i, k in values.iteritems():
          urlString += k+'/'
  
      url += method + '/' + urlString
  
      print url
      if method not in self.public:
          url += '&amp;apikey=' + self.key
          url += '&amp;nonce=' + str(int(time.time()))
          signature = hmac.new(self.secret, url, hashlib.sha512).hexdigest()
          headers = {'apisign': signature}
      else:
          headers = {}
      print url
  
      req = requests.get(url, headers=headers)
      response = json.loads(req.text)
      return response
  </code></pre>
  
  ####### PUBLIC API
  
  <pre><code>def getinfo(self):
      return self.query('info')
  
  def getticker(self, currency):
      return self.query('ticker', {'currency': currency})
  
  def getdepth(self, currency):
      return self.query('depth', {'currency': currency})
  
  def gettrades(self, currency):
      return self.query('trades', {'currency': currency})
  </code></pre>
  
  ##### TRADE API
  
  <pre><code>def getactiveorders(self, pair):
      return self.query('activeorders', {'pair': pair})
  </code></pre>
  
  <p><strong>A working example in PHP</strong><br>
  I believe this to be a working example of PHP, unfortunately I can't read this language. </p>
  
  <pre><code>function yobit_api_query2($method, $req = array())
  {
  $api_key    = '';
  $api_secret = '';
  
  $req['method'] = $method;
  $req['nonce'] = time();
  $post_data = http_build_query($req, '', '&amp;');
  $sign = hash_hmac("sha512", $post_data, $api_secret);
  $headers = array(
      'Sign: '.$sign,
      'Key: '.$api_key,
  );
  
  $ch = null;
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; SMART_API PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
  curl_setopt($ch, CURLOPT_URL, 'https://yobit.net/tapi/');
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_ENCODING , 'gzip');
  $res = curl_exec($ch);
  if($res === false)
  {
      $e = curl_error($ch);
      debuglog($e);
      curl_close($ch);
      return null;
  }
  
  curl_close($ch);
  
  $result = json_decode($res, true);
  if(!$result) debuglog($res);
  
  return $result;
  }
  </code></pre>