我是Binance API的新手,在调用Binance保证金借用API时遇到一些困难。我已经参考了他们的API文档,但是不知道如何通过java调用保证金借用API。因此,我想指导或分享给我一个示例代码,以在Java中调用其margin API。
预先感谢
答案 0 :(得分:0)
their website使用的请求具有以下卷曲结构:
curl --location --request GET 'https://www.binance.com/gateway-api/v1/public/margin/vip/spec/list-all' \
--header 'content-type: application/json'
在带有apache http client的Java中,您可以这样做:
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet();
httpGet.setURI(new URI("https://www.binance.com/gateway-api/v1/public/margin/vip/spec/list-all"));
httpGet.setHeader("content-type", "application/json");
CloseableHttpResponse response = httpclient.execute(httpGet);
String responseJson = EntityUtils.toString(response.getEntity());
System.out.println(responseJson);
答案 1 :(得分:0)
根据我对快速浏览文档的了解,您将必须从secretKey作为密钥,并向totalParams作为HMAC操作的值生成HMAC SHA256 signature
,并将API密钥传递到通过X-MBX-APIKEY header
来使用Rest API。
String hmac = HMAC_SHA256("secret_key", "totalParams")
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("api uri here"))
.timeout(Duration.ofMinutes(1))
.header("X-MBX-APIKEY", "api-key here")
.POST(totalParamsHere)
.build()