-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbitstamp.js
More file actions
59 lines (52 loc) · 1.92 KB
/
bitstamp.js
File metadata and controls
59 lines (52 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require('mootools');
var https = require('https');
var Q = require('q');
var bitstamp = Class({
// Responsible for sending the current bitstamp Balance.
tracker: function(from, to, ircWrite) {
var that = this;
console.log((new Date()) + '[' + from + '] Requesting bitstamp tracker.');
// request ticker infomration
var r = https.get('https://www.bitstamp.net/api/ticker/', function(res) {
var data = '';
var p = that;
var f = from;
var t = to;
var w = ircWrite;
if (res.statusCode == 200) {
// collect data!
res.on('data', function(chunk) {
data += chunk;
});
// respond with reply.
res.on('end', function() {
var response = JSON.parse(data);
if (response) {
w(
t,
'Bitstamp, Last[$' + parseFloat(response.last,2).toFixed(2) + '/BTC' +
'] High[$' + parseFloat(response.high,2).toFixed(2) +
'] Low[$' + parseFloat(response.low,2).toFixed(2) +
'] Volume[' + parseFloat(response.volume,2).toFixed(2) + '/BTC]'
);
console.log((new Date()) + '[' + t + '] Bitstamp, Successfully responded.');
} else {
w(t, "Bitstamp, ERROR: JSON Response couldn't parsed.");
console.log((new Date()) + '[' + t + '] Bitstamp, ERROR: JSON Response couldn\'t parsed.');
}
});
} else {
console.log(t, "Bitstamp, ERROR: HTTP Status " + res.statusCode);
}
}).on('error', function(e) {
that.irc.say(to, "Bitstamp, ERROR: " + e.message);
});
},
initialize: function(options) {
if (! options) {
throw new Error('Please pass an options object to the constructor.');
}
}
});
// Entry Point
module.exports = bitstamp;