使用Bitfinex API v1调用/v1/order/new报错“Key symbol was not present”求助
Hey there, let's break down this issue clearly—this error is straightforward: your request to the /v1/order/new endpoint is missing the required symbol parameter, which is mandatory for creating any order on Bitfinex API v1.
What's the root cause?
Looking at your code snippet, you're only adding request and nonce to your JSON payload, but you haven't included the symbol key that tells the API which trading pair you want to trade (e.g., btcusd for Bitcoin/USD, ethusd for Ethereum/USD). Bitfinex's v1 API explicitly requires this parameter for order creation, so the server is throwing an error because it can't process the order without knowing the target pair.
How to fix it?
Add the symbol parameter to your JSONObject before generating the payload. Here's how to modify your code:
/** Create Header, Param */ JSONObject json = new JSONObject(); json.put("request", targetURL); json.put("nonce", Long.toString(getNonce())); // Add the required symbol parameter (replace with your target trading pair) json.put("symbol", "btcusd"); String payload = ... // Rest of your payload generation logic
Extra checks to avoid future issues
- Case sensitivity: Make sure the key is lowercase
symbol—Bitfinex's API doesn't recognize uppercase variants likeSymbolorSYMBOL. - Valid symbol format: For API v1, trading pairs are formatted as lowercase strings without separators (e.g.,
ltcusd,xrpusd). Avoid using v2-style symbols liketBTCUSDhere. - Payload integrity: Double-check that your payload generation logic includes all key-value pairs from the
JSONObject, including the newly addedsymbol. Sometimes issues happen if only a subset of the JSON is being sent to the API.
内容的提问来源于stack exchange,提问作者Tim

