Binance 400响应和检测到的参数的重复值

时间:2019-02-23 11:08:21

标签: php api binance

仍然试图让我了解API和连接。

我正在尝试向Binance发出购买订单,但一直收到400条回复。我知道这对其他一些人来说是个问题,但我似乎无法怀疑我要去哪里。所以希望有人可以帮助我。

这只是POST的问题,所有GET请求都可以正常工作,因此对于签名和时间戳...或者至少我正在为我的帐户获取回复,所以我认为是这样。

第一个CURL仅用于serverTime,但是第二个CURL用于买卖订单。

这是我现在得到的答复...

  

“对象([代码] => -1102 [msg] =>强制参数'side'不是   已发送,为空/空或格式错误。 )”

如果我手动在字符串中键入,它就可以正常工作,但是由于一个或另一个原因,当我传递$ qs时,会出现上述错误。我在屏幕上回显了$ qs并复制了该内容,而不是传递$ qs,当我放入新时间戳时它可以工作。我很沮丧...

  

“ symbol = TRXUSDC&side = SELL&type = LIMIT&timeInForce = GTC&quantity = 63000.00000000&price = 0.02550000&recvWindow = 1000000&timestamp = 1550922237310”

有什么建议吗?

$header = array('X-MBX-APIKEY:' . KEY);
$url = BINANCE . 'api/v1/time';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_ENCODING, "");
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_URL,$url);
$response = curl_exec($curl);

if (FALSE === $response){
        echo curl_error($curl), curl_errno($curl);
    }
$serverTime = json_decode($response);
curl_close($curl);

$url = BINANCE . "api/v3/order";
$signature = NULL;
$queryString = NULL;

$query = array(
    "symbol" => "TRXUSDC",
    "side" => "SELL",
    "type" => "LIMIT",
    "timeInForce" => "GTC", 
    "quantity" => number_format(63000.00000000,8,'.',''),
    "price" => number_format(0.02550000,8,'.',''), 
    "recvWindow" => 1000000,
    "timestamp" => $serverTime->serverTime);

$qs = htmlentities(http_build_query(array_unique($query)));
$query['signature'] = hash_hmac('SHA256', $qs, SECRET );
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_ENCODING, "application/x-www-form-urlencoded");
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl,CURLOPT_FAILONERROR,FALSE);
curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS,$qs);
curl_setopt($curl, CURLOPT_URL, $url);
$response = curl_exec($curl);
if (FALSE === $response){
    echo curl_error($curl).':'.curl_errno($curl);
}
$obj = json_decode($response);
curl_close($curl);

2 个答案:

答案 0 :(得分:0)

我尝试了这段代码,然后使用var_dump $ qs

symbol=BTCUSDT&side=BUY&...

所以我认为您必须删除放大器;

答案 1 :(得分:0)

基于币安现货 api 文档:

建议使用5000以下的小recvWindow!最大不能超过 60,000!

所以编辑您的查询参数:

"symbol=TRXUSDC&side=SELL&type=LIMIT&timeInForce=GTC&quantity=63000.00000000&price=0.02550000&recvWindow=60000&timestamp=1550922237310"

您也可以检查您的其他查询参数和交换信息,您可以使用我们为您的交易品种提供的 https://api.binance.com/api/v3/exchangeInfo 获取这些信息:

{
  "symbol": "TRXUSDC",
  "status": "TRADING",
  "baseAsset": "TRX",
  "baseAssetPrecision": 8,
  "quoteAsset": "USDC",
  "quotePrecision": 8,
  "quoteAssetPrecision": 8,
  "baseCommissionPrecision": 8,
  "quoteCommissionPrecision": 8,
  "orderTypes": [
    "LIMIT",
    "LIMIT_MAKER",
    "MARKET",
    "STOP_LOSS_LIMIT",
    "TAKE_PROFIT_LIMIT"
  ],
  "icebergAllowed": true,
  "ocoAllowed": true,
  "quoteOrderQtyMarketAllowed": true,
  "isSpotTradingAllowed": true,
  "isMarginTradingAllowed": false,
  "filters": [
    {
      "filterType": "PRICE_FILTER",
      "minPrice": "0.00001000",
      "maxPrice": "1000.00000000",
      "tickSize": "0.00001000"
    },
    {
      "filterType": "PERCENT_PRICE",
      "multiplierUp": "5",
      "multiplierDown": "0.2",
      "avgPriceMins": 5
    },
    {
      "filterType": "LOT_SIZE",
      "minQty": "0.10000000",
      "maxQty": "9000000.00000000",
      "stepSize": "0.10000000"
    },
    {
      "filterType": "MIN_NOTIONAL",
      "minNotional": "10.00000000",
      "applyToMarket": true,
      "avgPriceMins": 5
    },
    {
      "filterType": "ICEBERG_PARTS",
      "limit": 10
    },
    {
      "filterType": "MARKET_LOT_SIZE",
      "minQty": "0.00000000",
      "maxQty": "659177.02430556",
      "stepSize": "0.00000000"
    },
    {
      "filterType": "MAX_NUM_ORDERS",
      "maxNumOrders": 200
    },
    {
      "filterType": "MAX_NUM_ALGO_ORDERS",
      "maxNumAlgoOrders": 5
    }
  ],
  "permissions": [
    "SPOT"
  ]
}

出于其他可能的原因,请查看链接 https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md

中的 Spot api 文档