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

标签 java bitcoin

我正在使用 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/

相关文章:

java - 将 HashMap 刷新到磁盘到有序集合中的最快方法

python - poloniex 中的 returnTradeHistory 总是返回空列表

javascript - 从种子生成私钥

java - 如何将 FX Controller 与主应用程序连接

java - 在Java中使用接口(interface)作为构造函数参数?

Java EE 6 与 Spring 3 堆栈

java - 如何使用 Eclipse Galileo 配置 Hibernate

bitcoin - 是否有使用 WebAssembly 挖掘比特币的开源解决方案?

c++ - 用cmake构建比特币

c# - 将应用程序中的 KeyPath 与 Bip44 钱包的 Wallet32 Keypath 相匹配