Last active
December 13, 2017 16:44
-
-
Save jonparker/d6c7d8c5bea2270cca90a169f75d91ab to your computer and use it in GitHub Desktop.
GoogleSheet App Script Import GDax and Poloniex and email if difference is greater than a threshold percentage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gets GDAX and Poloniex prices for BTC/ETH and BTC/LTC | |
// Requies arbitrageSheetID set to the id of a google sheet with an APIPull tab. | |
function checkArbitrageOpportunities() { | |
var poloniexUrl = 'https://poloniex.com/public?command=returnTicker'; | |
var poloniexResponse = UrlFetchApp.fetch(poloniexUrl); | |
var poloniexApiData = JSON.parse(poloniexResponse.getContentText()); | |
var rates = ['ETH', 'LTC']; | |
var arbitrageSheetID = '1f4C5X_93OVyxVi1z4VsjPpfyfPBK3-wqjW1Wo79d4MQ'; | |
var sheet = SpreadsheetApp.openById(arbitrageSheetID); | |
var apiTab = sheet.getSheetByName('APIPull'); | |
// Clear existing data | |
apiTab.getRange('A2:B15').clearContent(); | |
var rowNum = 2; | |
for(var rate in rates) | |
{ | |
var rateCode = rates[rate]; | |
var poloniexRate = poloniexApiData['BTC_' + rateCode].last; | |
var rateCodeCell = apiTab.getRange('A' + rowNum); | |
rateCodeCell.setValue('PLX/BTC-' + rateCode); | |
var rateCell = apiTab.getRange('B' + rowNum); | |
rateCell.setValue(poloniexRate); | |
rowNum++; | |
// GDAX | |
var gdaxResponse = UrlFetchApp.fetch('https://api.gdax.com/products/' + rateCode + '-BTC/ticker'); | |
var gdaxData = JSON.parse(gdaxResponse.getContentText()); | |
rateCodeCell = apiTab.getRange('A' + rowNum); | |
rateCodeCell.setValue('GDAX/BTC-' + rateCode); | |
rateCell = apiTab.getRange('B' + rowNum); | |
rateCell.setValue(gdaxData.price); | |
var percentageDiffCell = apiTab.getRange('C' + rowNum); | |
var percentageDiff = percentageDiffCell.getValue(); | |
var alertThreshold = 0.02; | |
if (percentageDiff > alertThreshold) | |
{ | |
GmailApp.sendEmail('youremail@somewhere.com', 'Arbitrage Alert for BTC/' + rateCode + ' @ ' + percentageDiff, | |
'https://www.coinigy.com/main/markets/PLNX/BTC/' + rateCode + ' https://www.coinigy.com/main/markets/GDAX/BTC/' + rateCode); | |
} | |
rowNum++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment