调用Coinbase Pro(GDAX)API时出现400错误的请求

时间:2019-01-30 07:42:22

标签: java coinbase-api gdax-api

我正在使用coinbase api在沙盒环境中下订单,但一直收到400个错误的请求响应。

这是我的代码段:

public HttpEntity<String> securityHeaders(String endpoint, String method, String jsonBody) {
    HttpHeaders headers = new HttpHeaders();

    String timestamp = String.valueOf(Instant.now().getEpochSecond());
    String resource = endpoint.replace(baseUrl, "");

    headers.add("accept", "application/json");
    headers.add("content-type", "application/json");
    headers.add("CB-ACCESS-KEY", "3e4aaf5d6af2e030bde7f728e5cd08ed");
    headers.add("CB-ACCESS-SIGN", signature.generate(resource, method, jsonBody, timestamp));
    headers.add("CB-ACCESS-TIMESTAMP", timestamp);
    headers.add("CB-ACCESS-PASSPHRASE", "12345678");
    headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36");

    return new HttpEntity<>(jsonBody, headers);
}

public Order placeOrder(Order order) {
    String jsonBody = gson.toJson(order);
    ResponseEntity<Order> response = restTemplate.exchange(baseUrl + "/orders", HttpMethod.POST, 
        securityHeaders("/orders", "POST", jsonBody), new ParameterizedTypeReference<Order>(){});
    Order respOrder = response.getBody();
    return respOrder;
}

这是调试输出:

request=<{"size":"0.01","product_id":"BTC-USD","side":"buy","type":"market"},[accept:"application/json", content-type:"application/json", CB-ACCESS-KEY:"***", CB-ACCESS-SIGN:"***", CB-ACCESS-TIMESTAMP:"1548833321", CB-ACCESS-PASSPHRASE:"***", user-agent:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"]>
23:28:41.233 [main] DEBUG org.springframework.web.client.RestTemplate - HTTP POST https://api-public.sandbox.pro.coinbase.com/orders
23:28:41.241 [main] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*]
23:28:41.243 [main] DEBUG org.springframework.web.client.RestTemplate - Writing [{"size":"0.01","product_id":"BTC-USD","side":"buy","type":"market"}] as "application/json"
23:28:41.898 [main] DEBUG org.springframework.web.client.RestTemplate - Response 400 BAD_REQUEST

我想念什么?

0 个答案:

没有答案