June 19, 2026

GDAX Java Limit Order (HTTP Post)

Trying to send HTTP Post request to GDAX with auth. The ‘GET’ requests work fine and I’m unsure if I am passing the json params correctly as I keep getting Bad Request.

private static JsonObject LimitOrder(String symbol, boolean side, String quantity, String price)
    {
        BigDecimal dPrice = new BigDecimal(price);
        BigDecimal dQuantity = new BigDecimal(quantity);
        String sSide = side?"buy":"sell";
        String param  ="{"size":""+dQuantity.toString()+"","price":""+dPrice.toString()+"","side":""+sSide+"","product_id":""+symbol+"","post_only":true}";


        try
        {
                String timestamp= Instant.now().getEpochSecond()+"";
                String accessSign = getAccess(timestamp,"POST","/orders");
                String apiKey = properties.getProperty("key");
                String passphrase = properties.getProperty("passphrase");

                URL url = new URL("https://" + properties.getProperty("host") + "/orders");
                HttpURLConnection connection = (HttpURLConnection)url.openConnection();
                connection.setDoOutput(true); // Triggers POST.
                connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
                connection.setRequestProperty("CB-ACCESS-KEY", apiKey);
                connection.setRequestProperty("CB-ACCESS-SIGN", accessSign);
                connection.setRequestProperty("CB-ACCESS-PASSPHRASE", passphrase);
                connection.setRequestProperty("CB-ACCESS-TIMESTAMP", timestamp);
                connection.setRequestProperty("accept", "application/json");
                connection.setConnectTimeout(5000);
                connection.setReadTimeout(5000);

        //      System.out.println("WRiting: " + param);
              try (OutputStream output = connection.getOutputStream()) {
                output.write(param.getBytes("UTF-8"));
              }

              String status = connection.getResponseMessage();
                System.out.println("STATUS: "+status);

                BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                String inputLine;
                StringBuffer content = new StringBuffer();
                while ((inputLine = in.readLine()) != null) {
                    content.append(inputLine);
                }
                if(content.length()>0){
                System.out.println(content);
                }else{
                     System.out.println("Empty Response");

                }
                in.close();

                connection.disconnect();
            }catch(Exception e) {
                e.printStackTrace();
            }
        return null;
    }

and the access sign method below:

 private static String getAccess(String timestamp, String method, String path) throws NoSuchAlgorithmException, InvalidKeyException {
        String secret = properties.getProperty("secret");
        String prehash = timestamp+method+path;

        Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
        byte[] secretDecoded = Base64.getDecoder().decode(secret);
        SecretKeySpec secret_key = new SecretKeySpec(secretDecoded, "HmacSHA256");
        sha256_HMAC.init(secret_key);

        return Base64.getEncoder().encodeToString(sha256_HMAC.doFinal(prehash.getBytes()));
    }
Previous Article

How to get unspents for inputs using bitcoinjs-lib?

Next Article

Upgrade from Bitcoin QT 0.8.5 to latest Bitcoin Core 0.15.X

You might be interested in …

Bitcoin’s rise: Swiss push for central bank adoption, boosting credibility and adoption

Bitcoin’s rise: Swiss push for central bank adoption, boosting credibility and adoption

**Damus: The Revolutionary Social Network on Bitcoin’s Lightning Network**

**Excerpt:**

Unleash the power of Damus, the groundbreaking decentralized social network built on the Bitcoin Lightning Network. Dive into our research to uncover its innovative architecture and explore how it empowers users with unprecedented privacy, content control, and network governance. Discover how Damus is transforming social media, giving you the freedom to shape your online presence like never before.

**Read more:** https://[your-academic-journal-url]/damus-a-decentralized-social-network-built-on-the-bitcoin-lightning-network

Read more at: https://thebitcoinstreetjournal.com/damus-a-decentralized-social-network-built-on-the-bitcoin-lightning-network/