Post
Topic
Board Exchanges
Re: Poloniex tradingApi, from JAVA
by
sebbes
on 24/04/2015, 08:35:20 UTC
I have exactly the same problem with http post call in JavaScript.  It has to be the hash method as I can change the hash string and it doesn't care when I send it.  Get the invalid command return on all private post calls, even after Poloniex guy sent me a sample call for the post call.  I am stumped as well at this point, but will post if I figure it out.

Best of Luck!

The hash method works, I successfully connect to Poloniex. You need to add an HTTP header with your public API key and another one with the the encrypted  query args; the query args (plain as in not encrypted) you also write on the connection outputstream (same for JavaScript, Java, Python etc.).

so in Java that would look like this:

Code:
  ...  
   conn.setRequestProperty("Key", "your public key");

   //build your args query parameter String (needs to include "command", "nonce" ), e.g.
   String queryArgs = "command=cancelOrder&orderNumber=12345"
   //encrypt the queryArgs using HmacSHA512. In java that looks something like this
   Mac shaMac = Mac.getInstance("HmacSHA512") //with try/catch for NoSuchAlgorithmException
   SecretKeySpec  keySpec = new SecretKeySpec(.getBytes(), "HmacSHA512");

   shaMac.init(keySpec);
   final byte[] macData = shaMac.doFinal(queryArgs.getBytes());
   String result = Hex.encodeHexString(macData); //again with try/catch for InvalidKeyException
   //this result you add as header param
   conn.setRequestProperty("Sign", result);
   //and the queryArgs themselves you write onto the connection's outputstream
   OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
   out.write(queryArgs);
    ...

But without posting your code it is impossible to assist!

Regards,
Sebastian