Skip to content

Instantly share code, notes, and snippets.

@kmikiy
Last active May 23, 2021
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@Estagon 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

This comment has been minimized.

Copy link

@willdolezal willdolezal commented Aug 8, 2020

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

@kmikiy

This comment has been minimized.

Copy link
Owner Author

@kmikiy 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

This comment has been minimized.

Copy link

@Estagon Estagon commented Aug 10, 2020

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

@kmikiy

This comment has been minimized.

Copy link
Owner Author

@kmikiy kmikiy commented Aug 10, 2020

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

@Estagon

This comment has been minimized.

Copy link

@Estagon 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

This comment has been minimized.

Copy link

@josehenriqueventura josehenriqueventura commented Aug 20, 2020

I got the same error too.

@diegomanuel

This comment has been minimized.

Copy link

@diegomanuel diegomanuel commented Nov 18, 2020

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