Created
October 14, 2016 16:37
-
-
Save lordloh/f5c8c589b4538ab9674db919ae2e2834 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var waitUntil = require('wait-until'); | |
var credentials = { | |
username: 'username', | |
password: 'Password' | |
}; | |
var allOrders=[]; | |
var nextURL=null; | |
var processed=false; | |
function order_handler(orderArray,allOs){ | |
var i, len; | |
for (i=0, len=orderArray.length;i<len;i++){ | |
var e = orderArray[i]; | |
var ss=(e.instrument).split('/'); | |
var instrument=ss[ss.length-2]; | |
allOs.push({'id':e.id, | |
'instrument':instrument, | |
'quantity':e.quantity, | |
'price':e.average_price, | |
'side':e.side, | |
'transaction_time':e.last_transaction_at | |
}); | |
} | |
return allOs; | |
} | |
function url_sequence(RH,url,allOs){ | |
// console.log("L:"+allOs.length); | |
if (url!=null){ | |
processed=false; | |
RH.url(url,function(e,r,b){ | |
nextURL=b.next; | |
var orderArray=b.results; | |
allOrders=order_handler(orderArray,allOs); | |
processed=true; | |
allOrders=url_sequence(RH,nextURL,allOrders); | |
}); | |
}else{ | |
// console.log("C:"+allOs.length); | |
// console.log(allOs); | |
csv(allOs); | |
return allOs; | |
} | |
} | |
function csv(Arr){ | |
var A; | |
for (var i=0;i<Arr.length;i++){ | |
A=Arr[i]; | |
console.log(A.id+", "+A.instrument+", "+A.quantity+", "+A.price+", "+A.quantity+", "+A.side+", "+A.transaction_time); | |
} | |
} | |
var Robinhood = require('../robinhood-node/src/robinhood')(credentials, function (){ | |
Robinhood.orders(function(e,r,b){ | |
nextURL=b.next; | |
var orderArray=b.results; | |
//nsole.log("O Before :"+allOrders.length); | |
allOrders=order_handler(orderArray,allOrders); | |
//nsole.log("O After :"+allOrders.length); | |
// console.log("Order"); | |
processed=true; | |
}); | |
waitUntil(700,Infinity,function condition(){ | |
if (processed){ | |
//console.log(allOrders); | |
processed=false; | |
return true; | |
}else | |
return false; | |
},function done(){ | |
allOrders=url_sequence(Robinhood,nextURL,allOrders); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment