TradeOgre API下单报错Invalid market,请求技术支持
解决TradeOgre API创建订单时的"Invalid market"错误及Bash调用实现
问题背景
调用TradeOgre API创建买单时,持续返回错误:
{"success":false,"error":"Invalid market"}
已尝试添加/去除参数双引号、调换参数顺序等操作,问题仍未解决。需实现Bash环境下的正常调用,原参考PHP代码如下:
$authBasic = base64_encode(APIKEY.":".APISECRET); $data = array( 'market' => 'BTC-USDT', 'quantity ' => '1', 'price ' => '1', ); $json = json_encode($data); $url = 'https://tradeogre.com/api/v1/order/buy'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', "Authorization: Basic $authBasic", 'Content-Length: ' . strlen($json) )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if(curl_errno($ch)) { echo 'Error: ' . curl_error($ch); } else { echo $response; } curl_close($ch); // echo $data; $authBasic = base64_encode(APIKEY.":".APISECRET); $data = array( 'market' => 'BTC-USDT', 'quantity ' => '1', 'price ' => '1', ); $json = json_encode($data); $url = 'https://tradeogre.com/api/v1/order/buy'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', "Authorization: Basic $authBasic", 'Content-Length: ' . strlen($json) )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if(curl_errno($ch)) { echo 'Error: ' . curl_error($ch); } else { echo $response; } curl_close($ch); // echo $data;
问题排查
结合TradeOgre API官方文档核心内容,排查出以下关键问题:
- 参数键名存在多余空格:原PHP代码中
quantity和price的键名末尾带有多余空格,导致JSON序列化后的键为"quantity "和"price ",不符合API要求的标准键名(应为quantity、price),这会导致API无法正确解析参数,进而触发错误。 - 交易对有效性验证:需确认
BTC-USDT是平台实际支持的交易对,可通过API查询所有可用交易对进行验证。
Bash环境下的正确调用实现
1. 验证交易对是否存在
先调用市场列表接口确认目标交易对有效:
curl "https://tradeogre.com/api/v1/markets"
返回结果中若包含"BTC-USDT"字段,则说明该交易对可用。
2. 创建买单的Bash命令
替换以下代码中的your_api_key_here和your_api_secret_here为你的实际密钥,执行即可创建订单:
# 设置API密钥与秘钥 APIKEY="your_api_key_here" APISECRET="your_api_secret_here" # 生成Basic Auth所需的Base64编码 AUTH_BASIC=$(echo -n "$APIKEY:$APISECRET" | base64) # 构造符合要求的JSON请求体(键名无空格,交易对格式正确) JSON_DATA='{"market": "BTC-USDT", "quantity": "1", "price": "1"}' # 发送POST请求创建买单 curl -X POST "https://tradeogre.com/api/v1/order/buy" \ -H "Content-Type: application/json" \ -H "Authorization: Basic $AUTH_BASIC" \ -d "$JSON_DATA"
注意事项
- 确保API密钥和秘钥无多余空格,Base64编码时使用
echo -n避免添加换行符。 - 若仍返回
Invalid market,需检查交易对格式是否与平台一致(以市场列表接口返回的格式为准)。
内容的提问来源于stack exchange,提问作者To Hai
相关产品推荐
相关产品推荐

