gpt4 book ai didi

java - Bitfinex API 错误消息 "Key symbol was not present."

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:23:19 28 4
gpt4 key购买 nike

我正在使用 Bitfinex API,API 的版本是 1。但是我有一个无法解决的问题。当我使用“/v1/order/new”时,服务器发送消息“Key symbol was not present”。我找不到问题出在哪一点。参数设置如下。请指教。

========================================

/**
Create Header, Param
*/
JSONObject json = new JSONObject();
json.put("request", targetURL);
json.put("nonce", Long.toString(getNonce()));
String payload = json.toString();
String payload_base64 = Base64.getEncoder().encodeToString(payload.getBytes());
String payload_sha384hmac = hmacDigest(payload_base64, apiKeySecret, ALGORITHM_HMACSHA384);

HttpTask http = new HttpTask(URL, Method.POST);
http.addHeader("X-BFX-APIKEY", apiKey);
http.addHeader("X-BFX-PAYLOAD", payload_base64);
http.addHeader("X-BFX-SIGNATURE", payload_sha384hmac);

http.setContentType("x-www-urlencoded");
http.setAcceptType("application/xml");

http.addParam("symbol", "btcusd");
http.addParam("amount", "0.01");
http.addParam("price", "0.01");
http.addParam("side", "buy");
http.addParam("type", "exchange market");
http.addParam("is_hidden", "false");
http.addParam("is_postonly", "true");
http.addParam("use_all_available", "0");
http.addParam("exchange", "bitfinex");
http.addParam("ocoorder", "false");
http.addParam("buy_price_oco", "0");


/**
Parsing Param
*/
StringBuilder sb = new StringBuilder();
Set<String> key = m_params.keySet();
int totalCount = key.size();
if (totalCount > 0) {
int index = 0;
for (Iterator<String> iterator = key.iterator(); iterator.hasNext();) {
String keyValue = (String) iterator.next();
String valueValue = (String) m_params.get(keyValue);
sb.append(String.format("%s=%s", keyValue, valueValue));
if (index < totalCount - 1) {
sb.append("&");
}
index++;
}

query = sb.toString();
}

/**
send Param
*/
if (!query.isEmpty()) {
DataOutputStream wr;
try {
wr = new DataOutputStream(m_connection.getOutputStream());
wr.writeBytes(query);
wr.flush();
wr.close();
} catch (IOException e) {
e.printStackTrace();
}
}

最佳答案

您需要将所有参数放入有效载荷对象中。

这是我在 JAVASCRIPT 上的例子:

auth_v1_request(path, params){

return new Promise((resolve, reject) => {

// console.log(this.account);

const apiKey = this.account.api_key;
const apiSecret = this.account.api_secret;

const apiPath = '/' + path;

const nonce = (Date.now() * 1000).toString();

const completeURL = `${ CONFIG.BITFINEX.API_URL }${apiPath}`;

params.nonce = nonce;
params.request = apiPath;

const payload = new Buffer(JSON.stringify(params))
.toString('base64');

const signature = crypto
.createHmac('sha384', apiSecret)
.update(payload)
.digest('hex');

const options = {
url: completeURL,
headers: {
'X-BFX-APIKEY': apiKey,
'X-BFX-PAYLOAD': payload,
'X-BFX-SIGNATURE': signature
},
body: JSON.stringify(params),
json: true
};

request.post(options, (error, response, res_body) => {

console.log(error);
console.log(res_body);

if(error) {
reject(error);
}
else {
let parsed;
try {
parsed = res_body;
if(parsed.message){
reject(parsed);
}
else {
resolve(parsed);
}
}
catch(err) {
reject(err);
}
}

})

});


}

关于java - Bitfinex API 错误消息 "Key symbol was not present.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49527857/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com