API Connection with Google Apps Script

Hello everyone

I’m trying to create an API connection between Binance and a Google Sheets Spreadsheet using Google Apps Script in order to retrieve data about my personal account balance.

I tried to follow all the required guidelines on the documentation, sending my apiKey, my signature generated with timestamp and de userSecret, but everytime I keep returning the same error

{ 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.' }

I live in Brazil and i know that United States is on the banned countries list of Binance.

Setting up a quick code to investigate de IP locations that Google Apps Script is using, I found out that they are located on Columbus, Ohio, United States

Google doesn’t allow me to select a static ip for the requests, it randomly uses one of its own dynamic ips

Is there a turnaround for this? Can someone help me?

here is a code snippet from my request

function generateSignature(queryString = '') {
  const props = PropertiesService.getScriptProperties();
  const secret = props.getProperty('binanceSecret');

  const timestamp = new Date().getTime();
  queryString = `timestamp=${timestamp}${queryString}`;

  let signature = Utilities.computeHmacSha256Signature(queryString, secret);
  signature = signature.map(function(byte) {
    return ('0' + (byte & 0xFF).toString(16)).slice(-2);
  }).join('');

  return `timestamp=${timestamp}&signature=${signature}`;
}



function getUserData() {
  const signature = generateSignature();
  const url = `https://api1.binance.com/api/v3/ping?${signature}`; console.log(url);
  const options = {
    'method': 'GET',
    'headers': {
      'X-MBX-APIKEY': getBinanceToken(),
      'Accept': 'application/json',
    },
    'muteHttpExceptions': true
  };
  
  getExternalIpAndLocation();
  getExternalIpAndLocation();
  getExternalIpAndLocation();

  const request = UrlFetchApp.fetch(url, options);
  const data = JSON.parse(request.getContentText()); console.log(data);

  return data;
}

Hey,
I suggest using Binance.us services if changing the IP location is not possible. Otherwise, you can create an intermediary app, independent of Google Apps Script, to fetch data from the Binance API. Call this app in the Google Apps Script to obtain the desired results.

1 Like

Is there any instructional video (or any PDF booklet) that explains how to import an individual coin’s current price into an Excel sheet?

Hi, I also live in Brazil and I’m facing the same issue in my project. Were you able to find a workaround for this, or did you switch to a completely different approach? Perhaps other platforms? I’m open to suggestions for alternatives that could help me develop better solutions for wallet management and analytical capabilities for investment decisions.

It’s somewhat surprising that there isn’t an official technical solution from the exchange for this situation. Or maybe I’m just not well informed.


Oi, também moro no Brasil e estou com o mesmo problema em meu projeto. Você conseguiu contornar essa situação ou partiu para alguma outra abordagem totalmente diferente? Outras plataformas talvez? Aceito sugestões de alternativas para poder desenvolver soluções mais adequadas as minhas necessidades de gerenciamento da carteira e capacidade analíticas para decisões de investimento.

É um pouco impressionante que não exista uma solução técnica oficial por parte da corretora para essa situação. Ou talvez eu apenas esteja desinformado mesmo.

Actually I followed the advice from the first comment and created an intermediary app hosted on a platform where I can choose the region of the server (In order to guarantee that the IP used to make the request is from south america)

I built an intermediary API hosted on Vercel using NodeJs. In the start I used it just to be called from apps script and then call binance, but later I got used to it and then moved all the project logic to this app, that now uses the Google Sheets API to insert data on the spreadsheet, without being held down by apps script quotas like 6 minutes execution time and 20k requests/day,

1 Like

Thank you, I followed your suggestion and finally managed to get traction on my project. Other platforms I’ve tested didn’t allow me to choose the server region on the cheaper or free plans. Vercel stands out by offering this option right from the start on the free plan. It’s excellent for those still in the experimental phase of the project and need to develop proof of concepts before committing to the full development of the product.