irufus / gdax-java

Java based wrapper for Coinbase Pro (Formerly known as GDAX API and Coinbase Exchange API)
MIT License
177 stars 131 forks source link

Getting {"message":"request timestamp expired"} on POST message #49

Closed unaor closed 6 years ago

unaor commented 6 years ago

Im using the implementation from this code and i on GET requests i get good responses from the API however, when trying to se POST i get that answer I used the timestamp generation on your code but got and invalid signature response from the API, that's because you are using the getSeconds and they want milis im unable to figure where exactly the problem here is the relevant code

        System.out.println(jsonOrder);
    CloseableHttpClient client = HttpClientBuilder.create().build();
    HttpPost request = new HttpPost(BASE_URL + "/orders");

    org.joda.time.DateTime now = new org.joda.time.DateTime(); // Default time zone.
    DateTime nowUtc = DateTime.now ( DateTimeZone.UTC );

    String timestamp = now.getMillis() + "";

    request.addHeader("accept", "application/json");
    request.addHeader("content-type", "application/json");
    request.addHeader("User-Agent", "gdax-java-client");
    request.addHeader(CB_ACCESS_KEY, API_KEY);
    request.addHeader(CB_ACCESS_SIGN, generateSignedHeader("/orders", "POST", jsonOrder, timestamp));
    request.addHeader(CB_ACCESS_TIMESTAMP, timestamp);
    request.addHeader(CB_ACCESS_PASSPHRASE, PASSPHRASE);

    HttpResponse response = client.execute(request);
    String jsonResponse = EntityUtils.toString(response.getEntity(), "UTF-8");
    client.close();
    return jsonResponse;`

The generateSignedHeader is your implementation and it is working for GET requests

robevansuk commented 6 years ago

I think I saw this on stack overflow recently?? The generate signed header is indeed the one from this lib. However the json order you're passing was not generated from this lib so something has gone wrong in generating that order. I looked when it was on stack overflow and the output for the json appeared to show you had >8 decimal places for the order. Whilst the signature is probably correct when they compare the order size to the signature their side, they're probably truncating the order string to just 8 decimal places. So I'd assume if you fix the order to use max of 8 decimal places and round_up/down as desired the code will probably magically work without any other changes

irufus commented 6 years ago

Closing since this question seems to be answered.