Pages:
Author

Topic: BTC-E Nonce Generation (Read 7000 times)

sr. member
Activity: 381
Merit: 255
November 12, 2014, 07:56:44 AM
#24
Yes I did, but we solved it. The problem was: The libraries was not sending the data in binary format, but in a text format. Our dev redid everything manually without using the library and send it as binary. That worked.
legendary
Activity: 1666
Merit: 1057
Marketing manager - GO MP
November 11, 2014, 02:24:01 PM
#23
We are having problem with this exact issue. Does anyone have a more comprehensive tutorial on how to communicate with the BTC-E API without getting the following response every time:

{success=0, error=invalid nonce parameter; on key:0, you sent:'', you should send:1}

You've seen that?
https://bitcointalksearch.org/topic/api-fail-part-ii-btc-e-faceplant-122006
sr. member
Activity: 381
Merit: 255
November 10, 2014, 12:45:36 PM
#22
We are having problem with this exact issue. Does anyone have a more comprehensive tutorial on how to communicate with the BTC-E API without getting the following response every time:

{success=0, error=invalid nonce parameter; on key:0, you sent:'', you should send:1}
member
Activity: 205
Merit: 10
Upfiring Team Member
January 29, 2014, 07:08:08 PM
#21
I fixed nonce issue - it was format issue, but the Sign Key issue exists.
legendary
Activity: 965
Merit: 1000
January 28, 2014, 06:03:54 PM
#20
Did you just try to print the http header you send to btc-e? Looks like the nonce is missing alltogether?
legendary
Activity: 1666
Merit: 1057
Marketing manager - GO MP
January 28, 2014, 05:45:19 PM
#19
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.
member
Activity: 205
Merit: 10
Upfiring Team Member
January 28, 2014, 05:26:53 PM
#18
I have a problem with nonce too, SHA512 encryption looks ok,I have checked on below calc:

http://hash.online-convert.com/sha512-generator

I received this response from BTCE:

Code:
: Response : "{"success":0,"error":"invalid nonce parameter; on key:0, you sent:"}" : String

Could you please take a look into my VBA code?

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



member
Activity: 107
Merit: 10
October 13, 2013, 12:18:06 AM
#17
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.
legendary
Activity: 965
Merit: 1000
October 12, 2013, 04:40:37 PM
#16
I thought key is your API key here?
member
Activity: 107
Merit: 10
October 12, 2013, 03:59:32 PM
#15
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...
sr. member
Activity: 602
Merit: 254
🔰FERRUM NETWORK🔰
June 23, 2013, 03:47:13 PM
#14
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.

legendary
Activity: 965
Merit: 1000
June 20, 2013, 09:30:20 AM
#13
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?
hero member
Activity: 532
Merit: 500
June 20, 2013, 01:07:50 AM
#12
Im not quite sure what your making, is it a tradebot?
full member
Activity: 228
Merit: 100
June 17, 2013, 02:50:39 PM
#11
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.
legendary
Activity: 1666
Merit: 1057
Marketing manager - GO MP
June 17, 2013, 02:48:54 PM
#10
I am using the unix time in seconds minus a constant to make if fit into 32 bit.
full member
Activity: 228
Merit: 100
June 17, 2013, 02:46:46 PM
#9
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.
sr. member
Activity: 287
Merit: 250
May 18, 2013, 05:34:55 PM
#8
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.
newbie
Activity: 33
Merit: 0
May 18, 2013, 04:08:30 PM
#7
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 :-).
legendary
Activity: 965
Merit: 1000
May 18, 2013, 03:51:12 PM
#6
I think the nonce is not really tied to the time? You could just count it up at each request?
newbie
Activity: 33
Merit: 0
May 18, 2013, 03:34:02 PM
#5
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.

      
Pages:
Jump to: