Creating Your Own Spreadsheets and Charts Using Poloniex API – Part Two – Beginner – s Guide To Poloniex API Programming
If you have reached this page without going through the previous instructions, please Click Here to commence at Part 1.
We need to open a fresh Google Sheet to get began. To do this, go to your Google Drive and click Fresh. A Dropdown will show up. Click Google Sheets and a fresh spreadsheet will open for you.
In the top left of your fresh Spreadsheet you will see the name is ‘Untitled Spreadsheet’. Click that Text and give it a fresh name such as XMRBuyOrders. Next, go to the bottom of the spreadsheet and find the Tab named Sheet1. Dual click the text and rename it to APIPull. This is the sheet we are going to put the API data from Poloniex into. You can name them whatever you choose, and tho’ I do not use spaces in my names out of habit, spaces are fine also. Every time you make a switch in a Google Sheet it is automatically saved. There is an Undo and Redo button on the top row next to the printer. I have needed these many times.
Let me remind you here of the very first rule of working on any document, spreadsheet or programming on a computer. Save a copy periodically. This can be done by clicking File, and choosing Make a Copy from any Google Application you are using. When attempting to clear data about five days into my programming, I accidentally chose the delete column function instead of the clear column function. This wiped out everything I had been working on in my spreadsheet, and I would have had to embark from scrape if not for my saved copy.
Next, we need to do our very first chunk of programming. The language used in Google Scripts is very similar to Java, however not all the functions work exactly the same and not all Java options are available in Scripts. If you want to do some research into how Java programming is done, you can visit W3Schools at the link below. This is not needed to do what I am going to demonstrate you, but it is informative, and may be helpful as you attempt things on your own and need to use functions I have not covered. Also, Google Search is your friend when you need to figure out something fresh.
Open a fresh Google Apps Script from the Fresh button on your main Google Drive screen. On the Fresh pull down menu, select More >,, then Google Apps Script. You may see this referred to as GAS when you are searching the Internet for help on Scripts.
A fresh scripts screen will open. Click ‘Untitled Project’ and switch the name to something like XMRScript.
We can name our function, or routine, at this time. In the script you just opened, the function name defaulted to myFunction. You can have many functions within a single Script, but we are going to use just one to do everything here. I am switching the name myFunction to processXMRAPI. Everything within the top and bottom bracket < >following this name is part of the function.
VERY Significant – DO NOT MISS THIS
We are about to commence writing code into our script. At the bottom of each Page where any Script is modified is a link like this:
Please open that link to copy the code you use into your own script. For some reason, when you copy from a web page directly into your code, Google Scripts sometimes sees an ‘,illegal character’ . This is due to the single quote ( ‘, ) not being interpreted correctly on the copy. Usually if you retype each single quote in your script the error will vanish.
We need to tell the Script where to find the Spreadsheet so the two can interact. This will be our very first line of code. The link we will use is found in the Web Address of the Spreadsheet. There is a long 44 character unique identifier consisting of random numbers and letters in the URL address itself. You need to copy that identifier. For the Spreadsheet I created I have…
Using this identifier, insert the following code in your function to link your Script to your Spreadsheet. The // before text denotes a comment. You may want to add to the comments to document what each step in the process does as you go. This way when you look back later you can lightly recall what you were doing.
// Link the script with a spreadsheet using the identifier found in the spreadsheet URL
var ss = SpreadsheetApp.openById(‘Paste Your 44 Character Identifier Here’),
Your Script will look something like this when you are done…
Please click Save at this point and be sure you are not receiving the ‘,illegal charater’ error message. If you are, you can use the code from the ‘,see what my script looks like’ link at the bottom of each page. It will copy and paste the exact same text without an error from Google. I do not know why.
Now we are able to write code in this script that uses and switches values in the associated spreadsheet. For example, you might want to pull data from Poloniex and populate the spreadsheet with the information. We will be doing that in the next lesson.
Please recognize a lot of effort went into figuring this process out and documenting it to save you time, with the objective of providing you information you can use to make more BTC in the future. If this is useful information for you, I would appreciate any tips you are able to send to the following BTC address.