Bitcoin Forum
June 20, 2024, 10:08:34 PM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Issue Connecting To MtGOX API v2  (Read 866 times)
IIzzII (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
April 26, 2013, 08:05:39 PM
Last edit: April 26, 2013, 08:16:30 PM by IIzzII
 #1

Greetings all. I am having issues connecting to the MtGOX API v2. I keep getting the following error:

"login_error_missing_nonce"

This error is reported in this thread here:
https://bitcointalk.org/index.php?topic=164404.msg1852502#msg1852502

Eventually being solved here:
https://bitcointalk.org/index.php?topic=164404.msg1853109#msg1853109

I have read and re-read that thread over and over and I can't apply that solution to my code. I am coding in Go and have come up with a basic script to call "money/info". Here is the code:

Code:
func main() {
  // generate data string
  t := time.Now()
  nonce := t.UnixNano() / 1000
  data := fmt.Sprintf("nonce=%d", nonce)

  // create the hash data
  hashData := []byte("BTCUSD/money/info" + "\x00" + data)

  // create the Rest-Sign for the header
  secret, _ := base64.StdEncoding.DecodeString(APISecret)

  s := hmac.New(sha512.New, secret)
  s.Write(hashData)

  hmac := s.Sum(nil)
  restSign := base64.StdEncoding.EncodeToString(hmac)

  // format the data string for the request
  postData := strings.NewReader(data)

  // create the http connection
  client := &http.Client{}
  request, _ := http.NewRequest("POST", "https://data.mtgox.com/api/2/BTCUSD/money/info", postData)

  // add customer headers
  request.Header.Set("User-Agent", "LuckyTime")
  request.Header.Set("Rest-Key", APIKey)
  request.Header.Set("Rest-Sign", restSign)
  request.Header.Set("Accepted-encoding", "GZIP")

  // send out request and print response
  response, _ := client.Do(request)
  defer response.Body.Close()

  body, _ := ioutil.ReadAll(response.Body)
  fmt.Printf("%s\n", body)
}

APIKey and APISecret are global variables that are properly set. I have adjusted the length of the nonce variable as recommended by the linked thread and nothing changes. I am clearly providing the nonce value. I have tried creating a new API key and secret multiple times so it's not that I messed up a nonce value on a specific key. I have no idea why this isn't working. Any help is most appreciated.
frefity
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
May 20, 2013, 04:52:53 PM
 #2

I'm having exactly the same issue, also using Go.

Did you manage to figure it out?

Cheers
frefity
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
May 21, 2013, 08:39:42 PM
 #3

I finally managed to figure it out!

You have to set the "Content-Type" header to "application/x-www-form-urlencoded"

Worked for me at least...
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!