简体   繁体   中英

Binance api php

I'm trying to integrate a binance api with php. I want to spend my spot wallets and earnings. I can't find the url I need for it and I can't get the endpoint either.

Additional question: For what do I need the timestamp?

    $secret = "mySecretKey";
    $key = "myApiKey";
    
    $s_time = "timestamp=".time()*1000;
    
    $sign=hash_hmac('SHA256', $s_time, $secret);
        
 
    $url = "https://api.binance.com/api/v1/balances?".$s_time.'&signature='.$sign;

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MBX-APIKEY:'.$key));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    
    $result = curl_exec($ch);
    
    $result = json_decode($result, true);
    
    echo '<pre>';
    var_dump($result);
    echo '</pre>';
    
  curl_close($ch);

I've tried many urls and looked at the binance documentation for a long time but I just can't find it.

Thanks for your help!

The only link I found in their API documentation is

Query Sub-account Assets (For Master Account)

GET /sapi/v3/sub-account/assets (HMAC SHA256) 

Response:

{
    "balances":[
        {
            "asset":"ADA",
            "free":10000,
            "locked":0
        },
        {
            "asset":"BNB",
            "free":10003,
            "locked":0
        },
        {
            "asset":"BTC",
            "free":11467.6399,
            "locked":0
        },
        {
            "asset":"ETH",
            "free":10004.995,
            "locked":0
        },
        {
            "asset":"USDT",
            "free":11652.14213,
            "locked":0
        }
    ]
}

I do not know exactly what you want to do but if you want an overview of your spot balances the right endpoint is:

GET /api/v3/account (HMAC SHA256), link to more info: https://binance-docs.github.io/apidocs/spot/en/#account-information-user_data

response:

{
  "makerCommission": 15,
  "takerCommission": 15,
  "buyerCommission": 0,
  "sellerCommission": 0,
  "commissionRates": {
    "maker": "0.00150000",
    "taker": "0.00150000",
    "buyer": "0.00000000",
    "seller": "0.00000000"
  },
  "canTrade": true,
  "canWithdraw": true,
  "canDeposit": true,
  "brokered": false,
  "requireSelfTradePrevention": false,
  "updateTime": 123456789,
  "accountType": "SPOT",
  "balances": [
    {
      "asset": "BTC",
      "free": "4723846.89208129",
      "locked": "0.00000000"
    },
    {
      "asset": "LTC",
      "free": "4763368.68006011",
      "locked": "0.00000000"
    }
  ],
  "permissions": [
    "SPOT"
  ]
}

more about the timestamp you can find here: https://binance-docs.github.io/apidocs/spot/en/#signed-trade-user_data-and-margin-endpoint-security

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM