Skip to content

Instantly share code, notes, and snippets.

@FernandoEscher
Forked from chenosaurus/buy.js
Last active November 28, 2017 12:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save FernandoEscher/5103601 to your computer and use it in GitHub Desktop.
Save FernandoEscher/5103601 to your computer and use it in GitHub Desktop.
//you will need to install node.js and restler first
//npm install restler
//run with the following command
// node buy.js
var sys = require('util'),
rest = require('restler');
//set these to your coinbase API key, the amount you want to buy & the price that you're expecting for
var apiKey = 'xxx';
var quantity = 10;
var expectedPrice = 44.00
var jsonData = { qty: quantity };
function onComplete(data, res) {
console.log(new Date().toString());
if (!data.success) {
console.log(data.errors);
setTimeout(buy, 5000);
} else {
console.log("SUCCESS!");
}
};
function buy() {
// Will check the price until it reaches the expected value
rest.get('https://coinbase.com/api/v1/prices/buy').on('complete', function(data){
console.log("Current price: "+data.amount+". Expected price: "+expectedPrice)
if(data.amount <= expectedPrice){
rest.postJson('https://coinbase.com/api/v1/buys?api_key=' + apiKey, jsonData).on('complete', onComplete);
}else{
setTimeout(buy, 60000)
}
return
});
}
buy();
@Wingman4l7
Copy link

You're missing an ending semicolon on line 13 and line 36.

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