How to use bittrex API in google sheets - example guide

People love making google sheets. I’ll try to make simple tutorial how to make a script that automatically fetch data from bittrex public API. Goal is to have real time values (ex. prices) automatically updated.

Step 1 Create google document by selecting “Start a new spreadsheet” in Google sheets.


Name your sheet BTC in lower left corner. Following copy-paste code is hardcoded for “BTC”. If you want to update cells in different sheets, change name in the code or change name of the sheet.
sheetname
Step 2 Select Tools-> script editor
menu
Step 3 Add following code

function updateBittrex()
{
var btcneo = UrlFetchApp.fetch("https://bittrex.com/api/v1.1/public/getticker?market=BTC-NEO");
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("BTC");
var j1=JSON.parse(btcneo.getContentText());
sheet.getRange(2, 5).setValue(j1.result.Last);
sheet.getRange(2, 4).setValue(j1.result.Bid);
sheet.getRange(2, 3).setValue(j1.result.Ask);
 }

Step 4. Save your script, .gs is extension for scripts. Default name code gs can be left unchanged, it doesn’t have to be same as document name.
Step 5. Test your function


Options I outlined in red are used to run a function, and to select it respectively. It will be handy when you experiment with new code, to see if it’s working.
Options outlined in blue is for automating the function. You will be offered several triggers, but refreshing every 5 minutes will do just fine. Remember, bittrex will ban your IP if you send a lot of API requests per day (limit was 200000 requests per day, last time i checked).

Ok lets analyze what this simple function do:
It assumes you have sheet named BTC.
It uses public API, so you don’t need to generate or use your bittrex account API key.
After receiving JSON, we break it into small parts, and fill some cells with results.
You can now use values of C2, D2 and E2 in other cell functions, as they are being updated real-time, every 5 minutes.

17 Likes

Thanks for putting this together.

4 Likes

:doge: no problem :doge:
I also have many ideas. Some of them, I implemented, but sheets look so ugly that nobody but me could use them. One of them is arbitrage calculator that warns about opportunities, and NET % gains, after fees. IF I tidy it up, I will share it.

7 Likes

on one of my sheets I imput my buy price and it tells me the price to sell at for different profit and loss percents.

5 Likes

Hi, I like this solution and you’ve done a good job detailing the steps. I wondered if there was a way to get multiple coin stats into the spreadsheet using a function, and if there was a way that function could look at a sheet to know which prices to get. For example, I have a sheet with 10 coin symbols down a column, and I need the cell next to these symbols to populate with the current price of the coin. Any incite would be appreciated. Thanks.

3 Likes

Yes it is possible.
If you want elegant solution, that can read the mnemonic (3 letter combination) , you will need to know about string manipulation , to make different URL.

If you want fast ugly hardcoded but working solution, you can copy paste those 6 lines 10 times in same function body, and then manually edit :
NEO in url to something else
Coordinates of the cell where you want results shown.
Repeat those steps for every coin, as 6 lines of code takes care of single coin.

We can do it together and learn as we go :slight_smile: . I’ll post solution here later.

5 Likes

Fragmaster, thx for reply, good to know I can just repeat that function and make the modifications.

The elegant solution is ideally what I’m going for. I want the script to look to a column, look at the symbols running down that column (my holdings) and display current prices in the adjacent column. It would also need to be able to encounter blank cells in the column (sometimes I may have 6 coins, other time 10, 15, etc) and NOT display anything next to a cell with no symbol in it. Or, alternatively, once it encounters a cell with no symbol in it down that first column, the script could just stop looking.

3 Likes

I totally missed this! Looks great!!

1 Like

Thanks so much for this @Fragmaster. I’ve been trying to figure out how to do this for ages. Do you know if there is a way to also get the volume of the pair in the sheet? thanks

1 Like

very usefull, thank for sharing

1 Like

I would like to know if you have any details on using the API Key and API Secret to download your order and history to google sheets? Like this guy did https://www.youtube.com/watch?v=ewlm_hyOb8U

Anyone know how to do this. I have the basic open or Public stuff just looking for a way to it to download all my orders and all the other stuff. When you do https://bittrex.com/api/v1.1/market/getopenorders?apikey=*******************&market=BTC-LTC&nonce=0

You get a error of {“success”:false,“message”:“APISIGN_NOT_PROVIDED”,“result”:null} because you didn’t include the API Secret wanted to know how to do that. Pls Help

1 Like

Hi ,
Thanks for adding.

But i have a question, can you make a script when bittrex add a new crypto coin?
So i want to get an email if bittrex add a new coin.

Is this possible with the api?

Thanks allready!

Bart

1 Like

I go this to work for USDT-BTC
UrlFetchApp.fetch(“https://bittrex.com/api/v1.1/public/getticker?market=USDT-BTC”);

However, when I use it in another market like BTC-LBC
UrlFetchApp.fetch(“https://bittrex.com/api/v1.1/public/getmarketsummary?market=BTC-LBC

the “result” field values have an extra set of square brackets around them. It seems to keep the JSON.parse fuction from parsing it correctly, and turns the entire array into one value.

Have you experienced this problem, and how does one deal with it? The Bittrex webpage on API calls includes that extra set of brackets in all of the examples. So, they seem to think it should be there. Google sheets doesn’t seem to actually have the full suite of javascript functions available to manipulate it with.

Anyone have insight on this? Thanks

1 Like

Hey, is there a way to list all coins from bittrex and hitbtc to campere them for arbitrage?
with a field, that gives you the different in % from these exchanges?

thanks for answering

1 Like

Thanks You Very Much Dear

1 Like

Hey guys i get "This app is not Verified by Google when i try to run the Script.

any solution

1 Like

This was super-helpful in getting me started, thanks for posting! I am having real problems creating a correctly formatted URL including the API key. I clearly see Bittrix’s example, but do you have anything via google scripts that would work? Alternately, do you have a sample string with fake API code, so I can see exactly what the string should look like. I think I can create nonce from looking at other samples, plus it says it ignores nonce. I appreciate any guidance you can provide. Thanks!

1 Like