Open danyoborg opened 7 years ago
Hi Danyoborg,
This is not a known issue, would you be able to show me the code from your use case? I might be able to help debug what is going wrong, or work out a fix if there is something wrong with the library.
Cheers, Tony
Hi Tony,
Thanks for replying, here is my code:
require_once('btce-api.php');
$BTCeAPI = new BTCeAPI($getkey, $getsecret);
try {
$orders_active = $BTCeAPI->apiQuery('ActiveOrders');
//loop through data here
} catch(BTCeAPIException $e) {
echo $e->getMessage();
}
I simple then fetch this via an ajax call and loop through the data, which refreshes every 5 seconds.
Please let me know if you need anything else?
Thanks
Hi danyoborg
I think I maybe able to see the problem,
Using the message provided: invalid nonce parameter; on key:1499873709, you sent:'1499873709', you should send:1499873710
Comparing this error to my regex: /:([0-9]+),/' This is probably matching the 'on key' section rather than the you should send section.
There is a trigger error as part of this which WARNs but does not throw an exception could you confirm you get an output like this:
Code Issues 1 Pull requests 0 Pulse btce-api.php
<?php /**
@license MIT License - https://github.com/marinu666/PHP-btce-api */ class BTCeAPI {
const DIRECTION_BUY = 'buy'; const DIRECTION_SELL = 'sell'; protected $public_api = 'https://btc-e.com/api/3/';
protected $api_key; protected $api_secret; protected $noonce; protected $RETRY_FLAG = false;
public function __construct($api_key, $api_secret, $base_noonce = false) { $this->api_key = $api_key; $this->api_secret = $api_secret; if($base_noonce === false) { // Try 1? $this->noonce = time(); } else { $this->noonce = $base_noonce; } }
/**
/**
@throws Exception */ public function apiQuery($method, $req = array()) { $req['method'] = $method; $mt = $this->getnoonce(); $req['nonce'] = $mt[1];
// generate the POST data string $post_data = http_build_query($req, '', '&');
// Generate the keyed hash value to post $sign = hash_hmac("sha512", $post_data, $this->api_secret);
// Add to the headers $headers = array( 'Sign: '.$sign, 'Key: '.$this->api_key, );
// Create a CURL Handler for use $ch = null; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; Marinu666 BTCE PHP client; '.php_uname('s').'; PHP/'.phpversion().')'); curl_setopt($ch, CURLOPT_URL, 'https://btc-e.com/tapi/'); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// Send API Request $res = curl_exec($ch);
// Check for failure & Clean-up curl handler if($res === false) { $e = curl_error($ch); curl_close($ch); throw new BTCeAPIFailureException('Could not get reply: '.$e); } else { curl_close($ch); }
// Decode the JSON $result = json_decode($res, true); // is it valid JSON? if(!$result) { throw new BTCeAPIInvalidJSONException('Invalid data received, please make sure connection is working and requested API exists'); }
// Recover from an incorrect noonce if(isset($result['error']) === true) { if(strpos($result['error'], 'nonce') > -1 && $this->RETRY_FLAG === false) { $matches = array(); $k = preg_match('/:([0-9]+),/', $result['error'], $matches); $this->RETRY_FLAG = true; trigger_error("Nonce we sent 12345 is invalid, retrying request with server returned nonce: 12345
If these numbers are the same (i.e. What we sent versus what this error says is the server nonce) I would suspect the error message has been changed by BTC-e and I will code up a fix for the library.
Cheers, Tony
I copied the full string I apologise I am on a phone:
An error like this:
Nonce we sent 12345 is invalid, retrying request with server returned nonce: 12345 If these numbers are the same (i.e. What we sent versus what this error says is the server nonce)
I would suspect the error message has been changed by BTC-e and I will code up a fix for the library. Cheers, Tony
Hi danyoborg,
Could you please use the branch "nonce-test" to test the functional change for your use case.
In the cloned repository: "git fetch --all; git checkout nonce-test" I have updated the nonce checker to look at the server returned value based upon the string which came back in the error code.
If this fixes it for you, I will update the master branch with these changes.
Cheers, Tony
I keep getting the following message (or something very similar)
API Error Message: invalid nonce parameter; on key:1499873709, you sent:'1499873709', you should send:1499873710. Response: Array ( [success] => 0 [error] => invalid nonce parameter; on key:1499873709, you sent:'1499873709', you should send:1499873710 )
Is this a known issue? and is there a simple fix?
Thanks