Loading ...

币安 提币范例代码

Author: 小小梦, Date: 2019-05-16 09:29:37
Tags:


String.prototype.format= function(){
    var args = Array.prototype.slice.call(arguments);
    var count=0;
    return this.replace(/%s/g,function(s,i){
        return args[count++];
    });
}

function WithdrawForBinance (accessKey, currency, address, addressTag, amount) {
    /* Withdraw API desc on Binance API doc
        query string :
            asset=ETH&address=0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b&amount=1&recvWindow=5000&name=test&timestamp=1510903211000
        HMAC SHA256 signature:
            [linux]$ echo -n "asset=ETH&address=0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b&amount=1&recvWindow=5000&timestamp=1510903211000" | 
            openssl dgst -sha256 -hmac "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
            (stdin)= 157fb937ec848b5f802daa4d9f62bea08becbf4f311203bda2bd34cd9853e320
        curl command:
            (HMAC SHA256)
            [linux]$ curl -H "X-MBX-APIKEY: vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A" -X 
            POST 'https://www.binance.com/wapi/v3/withdraw.html?
            asset=ETH&address=0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b&amount=1&recvWindow=5000&name=addressName&timestamp=1510903211000&
            signature=157fb937ec848b5f802daa4d9f62bea08becbf4f311203bda2bd34cd9853e320'
    */
    
    var timeStamp = new Date().getTime()
    var queryString = "asset=%s&address=%s&amount=%s&name=%s&timestamp=%s"
    queryString = queryString.format(currency, address, amount, addressTag, timeStamp)
    
    // sign
    var signature = exchange.HMAC("sha256", "hex", queryString, "{{secretkey}}")
    var uri = "https://www.binance.com/wapi/v3/withdraw.html?" + queryString + "&signature=" + signature
    
    // request
    var ret = HttpQuery(uri, "", "", "X-MBX-APIKEY: " + accessKey, true)
    
    Log(ret)
}




function main() {
    WithdrawForBinance("your accessKey", "ETH", "the address that you want to send", "test", "0.01")
}

More