Skip to content

Instantly share code, notes, and snippets.

@kmikiy
Last active June 16, 2022 12:17
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kmikiy/dd1f2106d47c30cfd5905e070b111b51 to your computer and use it in GitHub Desktop.
Save kmikiy/dd1f2106d47c30cfd5905e070b111b51 to your computer and use it in GitHub Desktop.
Google Sheets Apps Script for fetching latest crypto price from Binance
function BINANCE_PRICE(coinsymbol, pair) {
var url = "https://api.binance.com/api/v3/ticker/price?symbol="+coinsymbol.toUpperCase()+pair.toUpperCase()
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
var json = response.getContentText();
var data = JSON.parse(json);
return data.price
}
/*
USAGE example
Enter:
=BINANCE_PRICE("LTC", "BTC")
in a cell to get the last trade price of LTC/BTC on binance
*/
@Estagon
Copy link

Estagon commented Aug 7, 2020

Hello, does this still work?

When running this through Google Script, I get the following error:

[20-08-06 20:14:14:955 CEST] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><HTML><HEAD><META HTTP-EQUIV="Content-Type"CONTENT="text/html; charset=iso-8859-1"><TITLE>ERROR: The request could not be satisfied</TITLE></HEAD><BODY><H1>403 ERROR</H1><H2>The request could not be satisfied.</H2><HR noshade size="1px">Request blocked. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.<BR clear="all">If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.<BR clear="all"><HR noshade size="1px"><PRE>Generated by cloudfront (CloudFront) Request ID: -m-__LPRs7J_orooCPROW2R4JjqiaQGauojl7fEoi2JxDXeIDbwJOQ==</PRE><ADDRESS></ADDRESS></BODY></HTML>

I've made a post on StackExchange, but no positive response yet.

Thank you so much!

@willdolezal
Copy link

The Cryptopia API is no longer active. Removing lines 10-16 should resolve this error.

@kmikiy
Copy link
Author

kmikiy commented Aug 10, 2020

@willdolezal is correct. Cryptopia is no longer active. I have removed it from the gist. Use =BINANCE_PRICE("LTC", "BTC") from now on.

@Estagon
Copy link

Estagon commented Aug 10, 2020

It doesn't work for me through Google Script.
Still receiving the same error from Cloudfront.

@kmikiy
Copy link
Author

kmikiy commented Aug 10, 2020

I removed the unnecessary code, have you also tried removing the code that's no longer required?

@Estagon
Copy link

Estagon commented Aug 10, 2020

Yes, I'm only using the BINANCE_PRICE function. For some reason my access is blocked...
I will try from another computer and let you know.

@josehenriqueventura
Copy link

I got the same error too.

@diegomanuel
Copy link

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