Dirk83 (OP)
Newbie
Offline
Activity: 33
Merit: 0
|
|
May 18, 2013, 03:16:47 PM |
|
Hi,
I am testing code for the BTC-E trading platform, however, it seems like it can only process one API request per second, if I do more it gives an invalid nonce parameter error back.
I use PHP, this is the code to generate the nonce:
$mt = explode(' ', microtime()); $req['nonce'] = $mt[1];
If I try a more complex nonce, like:
$req['nonce'] = $mt[1].substr($mt[0], 2, 6);
I also get an invalid nonce parameter error back.
Anyone ran into the same problem? How to solve it?
Thanks, Dirk
|
|
|
|
|
|
|
|
|
"Bitcoin: the cutting edge of begging technology." -- Giraffe.BTC
|
|
|
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
|
|
|
|
Terk
|
|
May 18, 2013, 03:27:41 PM |
|
I am testing code for the BTC-E trading platform, however, it seems like it can only process one API request per second, if I do more it gives an invalid nonce parameter error back. It can only process one API request per unique nonce and your nonce is number of seconds since the Unix epoch, so you are changing your nonce only once per second. You are skipping the microseconds part of microtime() return. Please read: http://php.net/manual/en/function.microtime.php, or the quickest shortcut would be $req['nonce'] = (int) 10000*microtime(true);
|
|
|
|
Dirk83 (OP)
Newbie
Offline
Activity: 33
Merit: 0
|
|
May 18, 2013, 03:47:30 PM |
|
I am testing code for the BTC-E trading platform, however, it seems like it can only process one API request per second, if I do more it gives an invalid nonce parameter error back. It can only process one API request per unique nonce and your nonce is number of seconds since the Unix epoch, so you are changing your nonce only once per second. You are skipping the microseconds part of microtime() return. Please read: http://php.net/manual/en/function.microtime.php, or the quickest shortcut would be $req['nonce'] = (int) 10000*microtime(true); I already tried generating a more complex nonce, but it didn't work. Apparently it needs a nonce of exactly 10 numbers (this is mentioned nowhere however), which I now generate partly from the seconds and from the microseconds part: $mt = explode(' ', microtime()); $req['nonce'] = substr($mt[1],-4).substr($mt[0], 2, 6); Issue solved now, thanks for the reply.
|
|
|
|
Terk
|
|
May 18, 2013, 04:38:37 PM |
|
$mt = explode(' ', microtime()); $req['nonce'] = substr($mt[1],-4).substr($mt[0], 2, 6);
Just make sure that they don't require ever-increasing nonce (but they probably do), because your method will create numbers starting back from 0 after couple of hours. What you have now is a number which increases for 10000 seconds but then starts back from 0. You also don't ensure that you won't generate a nonce that has already been used in the past, as it's possible you'll get a colliding number one day. This is a very dirty hack what you have now.
|
|
|
|
Dirk83 (OP)
Newbie
Offline
Activity: 33
Merit: 0
|
|
May 18, 2013, 07:34:02 PM |
|
Thanks, I ran into that I think, or it could be something else, it isn't working anymore.
I now use this, that should work for at least a while (if you have a better way I'd gladly hear so, but I think it is limited since you have only 10 digits and you want some accuracy on the milli or microsecond level, the best I can do probably is to add 110000000 to it):
$req['nonce'] = substr($mt[1],-7).substr($mt[0], 2, 3);
I get this error message back:
invalid nonce parameter; 0 8905540614
I don know why it gives a zero first, but the 8905540614 is the nonce I send. It's kinda weird, because it is 10 digits and it's ever-increasing (I reset the keys), so something else might still be causing it.
|
|
|
|
daybyter
Legendary
Offline
Activity: 965
Merit: 1000
|
|
May 18, 2013, 07:51:12 PM |
|
I think the nonce is not really tied to the time? You could just count it up at each request?
|
|
|
|
Dirk83 (OP)
Newbie
Offline
Activity: 33
Merit: 0
|
|
May 18, 2013, 08:08:30 PM |
|
I think the nonce is not really tied to the time? You could just count it up at each request?
Possible, though I need to keep a database of the nonce value then, which I currently don't have :-).
|
|
|
|
whydifficult
|
|
May 18, 2013, 09:34:55 PM |
|
but the 8905540614 is the nonce I send. It's kinda weird, because it is 10 digits and it's ever-increasing (I reset the keys), so something else might still be causing it.
This page states that the nonce is capped at 4294967294.
|
Gekko a nodejs bitcoin trading bot! Realtime Bitcoin Globe - visualizing all transactions and blocks Tip jar (BTC): 1KyQdQ9ctjCrGjGRCWSBhPKcj5omy4gv5S
|
|
|
tuneman1980
|
|
June 17, 2013, 06:46:46 PM |
|
No matter what I do I get:
'{"success":0,"error":"invalid nonce parameter; 0 "}'
I've tried all sorts of solutions. Currently, I'm just sending a "1" in the hopes of getting anything other than a "0" to show up in the response.
|
http://cryptocoinstats.com/BTC: 19YQqtEdtuWhT6nk6ArBgMTiKMEjoJ5eww LTC: Li1RLpZm8Rx7txSnQdvZvtLMsd4XDN2vMJ FTC: 6qAU4vtyf9LPW4yV4m4Vx1jm4ZkXJHTFP7
|
|
|
ElectricMucus
Legendary
Offline
Activity: 1666
Merit: 1057
Marketing manager - GO MP
|
|
June 17, 2013, 06:48:54 PM |
|
I am using the unix time in seconds minus a constant to make if fit into 32 bit.
|
|
|
|
tuneman1980
|
|
June 17, 2013, 06:50:39 PM |
|
Currently I'm posting this basic URL: URL := DSFormat( '%s?%s', [' https://btc-e.com/tapi', Join([ WebArg('method', 'getInfo'), WebArg('nonce', 1)], '&', True)]); Along with the API-Key header of course.
|
http://cryptocoinstats.com/BTC: 19YQqtEdtuWhT6nk6ArBgMTiKMEjoJ5eww LTC: Li1RLpZm8Rx7txSnQdvZvtLMsd4XDN2vMJ FTC: 6qAU4vtyf9LPW4yV4m4Vx1jm4ZkXJHTFP7
|
|
|
legitnick
|
|
June 20, 2013, 05:07:50 AM |
|
Im not quite sure what your making, is it a tradebot?
|
|
|
|
daybyter
Legendary
Offline
Activity: 965
Merit: 1000
|
|
June 20, 2013, 01:30:20 PM |
|
Did you try my sources yet? I think, they still work, so you'd just add some debug output to see the data, that it sends to the server?
|
|
|
|
Kevlar
Sr. Member
Offline
Activity: 602
Merit: 254
🔰FERRUM NETWORK🔰
|
|
June 23, 2013, 07:47:13 PM |
|
I usually use the current time in milliseconds /250. This will allow 4 requests per second, and will hit max_int sometime in the year 2030.
|
|
|
|
jwest411
Member
Offline
Activity: 107
Merit: 10
|
|
October 12, 2013, 07:59:32 PM |
|
I did a similar thing to kevlar and legitnick, took the time in tenths of a second and then shave off the leading digits by subtracting some, so if the system time in deciseconds is 1281646886112, I take that and subtract 1280000000000 to get 1646886112, which is less than the maximum, ten digits, and increments every 1/10 seconds.
But my nonce is still not working. I am getting {"success":0,"error":"invalid nonce parameter; on key:3816054893, you sent:1160549562"}. The key is a nonce I sent on a completely different API key, even though I discarded the key. In my utter frustration, I tried opening another BTCE account under another email address I have. But somehow, when I tried using the new key/secret on the new account, it still gave me the same error with the same "key". 1) how is this possible and 2) Does this mean I'm screwed?
On a related note, what exactly is the value of the "key" here? Sometimes it appears to be a higher value I sent in the past. Sometimes it is zero. And sometimes, if I accidentally send the same nonce parameter twice, it is a duplicate of the "you sent" value. So I guess the key is basically an error code?
This had better not happen once I have more $ invested...
|
|
|
|
daybyter
Legendary
Offline
Activity: 965
Merit: 1000
|
|
October 12, 2013, 08:40:37 PM |
|
I thought key is your API key here?
|
|
|
|
jwest411
Member
Offline
Activity: 107
Merit: 10
|
|
October 13, 2013, 04:18:06 AM |
|
update: it turns out that the method I gave before was fine, but I accidentally forgot to change the nonce in one of my methods so it was screwing everything up. I just discarded my old key and got a new one, and now it is working.
@DayBiter In my last post, I was referring to two different types of keys... My API key, and then the "key" i was referring to was the key in the "invalid nonce parameter" error response. That key is generally one of the past nonces you have sent or 0. But it would be nice to have a little more explanation about what the different possible responses are/mean.
|
|
|
|
CoinFarmer
Member
Offline
Activity: 205
Merit: 10
Upfiring Team Member
|
|
January 28, 2014, 09:26:53 PM Last edit: September 04, 2017, 07:40:11 PM by CoinFarmer |
|
I have a problem with nonce too, SHA512 encryption looks ok,I have checked on below calc: http://hash.online-convert.com/sha512-generatorI received this response from BTCE: : Response : "{"success":0,"error":"invalid nonce parameter; on key:0, you sent:"}" : String Could you please take a look into my VBA code? Dim postdata As String Dim Method As String Dim API As String Dim Secret As String Dim URL As String Dim ObjHttp As Object Dim nonce As String Dim Sign As String Dim Response As String
Private Sub Trade() API = "API_KEY" Secret = "SECRET_KEY" URL = "https://btc-e.com/tapi" Method = "getInfo" nonce = DateDiff("s", "1/1/1970", Date) postdata = "method=" & Method & Chr(38) & "nonce=" & nonce Sign = Base64_HMACSHA512(postdata, Secret) Set ObjHttp = New MSXML2.XMLHTTP60 With ObjHttp .Open "POST", URL, False .setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)" .setRequestHeader "Key", API .setRequestHeader "Sign", Sign .send (postdata) Response = .responseText End With End Sub Private Function EncodeBase64(ByRef arrData() As Byte) As String
Dim objXML As MSXML2.DOMDocument60 Dim objNode As MSXML2.IXMLDOMElement Set objXML = New MSXML2.DOMDocument60 Set objNode = objXML.createElement("b64") objNode.DataType = "bin.base64" objNode.nodeTypedValue = arrData EncodeBase64 = objNode.Text Set objNode = Nothing Set objXML = Nothing End Function
Function Base64_HMACSHA512(ByVal sTextToHash As String, ByVal sSharedSecretKey As String)
Dim asc As Object, enc As Object Dim TextToHash() As Byte Dim SharedSecretKey() As Byte Set asc = CreateObject("System.Text.UTF8Encoding") Set enc = CreateObject("System.Security.Cryptography.HMACSHA512")
TextToHash = asc.Getbytes_4(sTextToHash) SharedSecretKey = asc.Getbytes_4(sSharedSecretKey) enc.Key = SharedSecretKey
Dim bytes() As Byte bytes = enc.ComputeHash_2((TextToHash)) Base64_HMACSHA512 = EncodeBase64(bytes) Set asc = Nothing Set enc = Nothing
End Function
|
|
|
|
ElectricMucus
Legendary
Offline
Activity: 1666
Merit: 1057
Marketing manager - GO MP
|
|
January 28, 2014, 09:45:19 PM |
|
yeah google for: btc-e faceplant They still haven't fixed it... your code is probably fine you just have to do this really stupid thing.
|
|
|
|
daybyter
Legendary
Offline
Activity: 965
Merit: 1000
|
|
January 28, 2014, 10:03:54 PM |
|
Did you just try to print the http header you send to btc-e? Looks like the nonce is missing alltogether?
|
|
|
|
|