Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Last active January 14, 2023 19:32
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save tanaikech/175067567819577fd8eba9b82eabd1a6 to your computer and use it in GitHub Desktop.
Save tanaikech/175067567819577fd8eba9b82eabd1a6 to your computer and use it in GitHub Desktop.
Binance API for Google Apps Script

Binance API for Google Apps Script

This sample script is for using Binance API by Google Apps Script. This script encryptes "signature" like samples. In this script, "Example 1: As a query string" is used, and it retrieves "All orders (SIGNED)" by "GET".

function main() {
    var key = '#####'; // Please input your key.
    var secret = '#####'; // Please input your secret.
    var api = "/api/v3/allOrders"; // Please input API Endpoint you want.
    var timestamp = Number(new Date().getTime()).toFixed(0);
    var string = "symbol=LTCBTC&timestamp=" + timestamp; // Please input query parameters for the inputterd API.

    var baseUrl = "https://api.binance.com";
    var signature = Utilities.computeHmacSha256Signature(string, secret);
    signature = signature.map(function(e) {
        var v = (e < 0 ? e + 256 : e).toString(16);
        return v.length == 1 ? "0" + v : v;
    }).join("");
    var query = "?" + string + "&signature=" + signature;
    var params = {
        'method': 'get',
        'headers': {'X-MBX-APIKEY': key},
        'muteHttpExceptions': true
    };
    var data = UrlFetchApp.fetch(baseUrl + api + query, params);
    Logger.log(data.getContentText())
}
@axisrow
Copy link

axisrow commented Jan 14, 2023

Информация {
"code": 0,
"msg": "Service unavailable from a restricted location according to 'b. Eligibility' in https://www.binance.com/en/terms. Please contact customer service if you believe you received this message in error."
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment