Comparing version 0.1.0 to 0.2.0
849
lib/data.js
@@ -13,7 +13,6 @@ /* | ||
moment = require('moment'), | ||
Q = require('q'), | ||
request = require('request'), | ||
xml2js = require('xml2js'); | ||
var _util = require('./util'); | ||
var debug = require('debug')('eoddata:data'); | ||
@@ -67,9 +66,9 @@ | ||
Data.prototype.getCountryList = function (cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -85,11 +84,12 @@ debug('Downloading CountryList...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.COUNTRIES) { | ||
return cb(new Error( | ||
util.format('Failed to get CountryList: %s', | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get CountryList: %s', | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -104,9 +104,10 @@ var countries = {}; | ||
_.keys(countries).length).yellow); | ||
return cb(null, countries); | ||
return _.isFunction(cb) ? cb(null, countries) : dfd.resolve(countries); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get CountryList: status %d', | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get CountryList: status %d', | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -116,12 +117,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getDataFormats = function (cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -137,11 +140,12 @@ debug('Downloading DataFormats...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.DATAFORMATS) { | ||
return cb(new Error( | ||
util.format('Failed to get DataFormats: %s', | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get DataFormats: %s', | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -155,9 +159,10 @@ var dataFormats = {}; | ||
debug(util.format('DataFormats: %d', _.keys(dataFormats).length).yellow); | ||
return cb(null, dataFormats); | ||
return _.isFunction(cb) ? cb(null, dataFormats) : dfd.resolve(dataFormats); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get DataFormats: status %d', | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get DataFormats: status %d', | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -167,12 +172,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getExchangeGet = function (exchangeCode, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -189,23 +196,25 @@ debug('Downloading ExchangeGet...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.EXCHANGE) { | ||
return cb(new Error( | ||
util.format('Failed to get ExchangeGet (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get ExchangeGet (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
var exchange = result.RESPONSE.EXCHANGE[0].$; | ||
debug(util.format('ExchangeGet (%s)', exchangeCode).yellow); | ||
return cb(null, exchange); | ||
return _.isFunction(cb) ? cb(null, exchange) : dfd.resolve(exchange); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get ExchangeGet (%s): status %d', | ||
exchangeCode, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get ExchangeGet (%s): status %d', | ||
exchangeCode, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -215,12 +224,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getExchangeList = function (cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -236,11 +247,12 @@ debug('Downloading ExchangeList...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.EXCHANGES) { | ||
return cb(new Error( | ||
util.format('Failed to get ExchangeList: %s', | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get ExchangeList: %s', | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -255,9 +267,10 @@ var exchanges = {}; | ||
_.keys(exchanges).length).yellow); | ||
return cb(null, exchanges); | ||
return _.isFunction(cb) ? cb(null, exchanges) : dfd.resolve(exchanges); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get ExchangeList: status %d', | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get ExchangeList: status %d', | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -267,12 +280,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getFundamentalList = function (exchangeCode, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -289,12 +304,13 @@ debug('Downloading FundamentalList...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.FUNDAMENTALS) { | ||
return cb(new Error( | ||
util.format('Failed to get FundamentalList (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get FundamentalList (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -310,10 +326,11 @@ var fundamentals = {}; | ||
_.keys(fundamentals).length).yellow); | ||
return cb(null, fundamentals); | ||
return _.isFunction(cb) ? cb(null, fundamentals) : dfd.resolve(fundamentals); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get FundamentalList (%s): status %d', | ||
exchangeCode, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get FundamentalList (%s): status %d', | ||
exchangeCode, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -323,12 +340,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getQuoteGet = function (exchangeCode, symbolCode, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -346,13 +365,14 @@ debug('Downloading QuoteGet...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.QUOTE) { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteGet (%s:%s): %s', | ||
exchangeCode, | ||
symbolCode, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get QuoteGet (%s:%s): %s', | ||
exchangeCode, | ||
symbolCode, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -363,11 +383,12 @@ var quote = result.RESPONSE.QUOTE[0].$; | ||
symbolCode).yellow); | ||
return cb(null, quote); | ||
return _.isFunction(cb) ? cb(null, quote) : dfd.resolve(quote); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteGet (%s:%s): status %d', | ||
exchangeCode, | ||
symbolCode, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get QuoteGet (%s:%s): status %d', | ||
exchangeCode, | ||
symbolCode, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -377,12 +398,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getQuoteList = function (exchangeCode, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -399,12 +422,13 @@ debug('Downloading QuoteList...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.QUOTES) { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteList (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get QuoteList (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -420,10 +444,11 @@ var quotes = {}; | ||
_.keys(quotes).length).yellow); | ||
return cb(null, quotes); | ||
return _.isFunction(cb) ? cb(null, quotes) : dfd.resolve(quotes); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteList (%s): status %d', | ||
exchangeCode, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get QuoteList (%s): status %d', | ||
exchangeCode, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -433,9 +458,11 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getQuoteList2 = function (exchangeCode, symbolCodes, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
@@ -445,3 +472,3 @@ symbolCodes = (_.isArray(symbolCodes) ? symbolCodes : [symbolCodes]); | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -459,13 +486,14 @@ debug('Downloading QuoteList2...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.QUOTES) { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteList2 (%s:%s): %s', | ||
exchangeCode, | ||
symbolCodes.join(','), | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get QuoteList2 (%s:%s): %s', | ||
exchangeCode, | ||
symbolCodes.join(','), | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -482,11 +510,12 @@ var quotes = {}; | ||
_.keys(quotes).length).yellow); | ||
return cb(null, quotes); | ||
return _.isFunction(cb) ? cb(null, quotes) : dfd.resolve(quotes); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteList2 (%s:%s): status %d', | ||
exchangeCode, | ||
symbolCodes.join(','), | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get QuoteList2 (%s:%s): status %d', | ||
exchangeCode, | ||
symbolCodes.join(','), | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -496,12 +525,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getQuoteListByDate = function (exchangeCode, quoteDate, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -519,13 +550,14 @@ debug('Downloading QuoteListByDate...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.QUOTES) { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteListByDate (%s, %s): %s', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get QuoteListByDate (%s, %s): %s', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -542,11 +574,12 @@ var quotes = {}; | ||
_.keys(quotes).length).yellow); | ||
return cb(null, quotes); | ||
return _.isFunction(cb) ? cb(null, quotes) : dfd.resolve(quotes); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteListByDate (%s, %s): status %d', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get QuoteListByDate (%s, %s): status %d', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -556,12 +589,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getQuoteListByDate2 = function (exchangeCode, quoteDate, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -579,13 +614,14 @@ debug('Downloading QuoteListByDate2...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.QUOTES2) { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteListByDate2 (%s, %s): %s', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get QuoteListByDate2 (%s, %s): %s', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -602,11 +638,12 @@ var quotes = {}; | ||
_.keys(quotes).length).yellow); | ||
return cb(null, quotes); | ||
return _.isFunction(cb) ? cb(null, quotes) : dfd.resolve(quotes); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteListByDate2 (%s, %s): status %d', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get QuoteListByDate2 (%s, %s): status %d', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -616,12 +653,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getQuoteListByDatePeriod = function (exchangeCode, quoteDate, period, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -640,14 +679,15 @@ debug('Downloading QuoteListByDatePeriod...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.QUOTES) { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteListByDatePeriod (%s, %s, %s): %s', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
period, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get QuoteListByDatePeriod (%s, %s, %s): %s', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
period, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -668,12 +708,13 @@ var quotes = {}; | ||
_.keys(quotes).length).yellow); | ||
return cb(null, quotes); | ||
return _.isFunction(cb) ? cb(null, quotes) : dfd.resolve(quotes); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteListByDatePeriod (%s, %s, %s): status %d', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
period, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get QuoteListByDatePeriod (%s, %s, %s): status %d', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
period, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -683,12 +724,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getQuoteListByDatePeriod2 = function (exchangeCode, quoteDate, period, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -707,14 +750,15 @@ debug('Downloading QuoteListByDatePeriod2...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.QUOTES2) { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteListByDatePeriod2 (%s, %s, %s): %s', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
period, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get QuoteListByDatePeriod2 (%s, %s, %s): %s', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
period, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -735,12 +779,13 @@ var quotes = {}; | ||
_.keys(quotes).length).yellow); | ||
return cb(null, quotes); | ||
return _.isFunction(cb) ? cb(null, quotes) : dfd.resolve(quotes); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get QuoteListByDatePeriod2 (%s, %s, %s): status %d', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
period, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get QuoteListByDatePeriod2 (%s, %s, %s): status %d', | ||
exchangeCode, | ||
moment(quoteDate).format('M/D/YYYY'), | ||
period, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -750,12 +795,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getSplitListByExchange = function (exchangeCode, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -772,12 +819,13 @@ debug('Downloading SplitListByExchange...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.SPLITS) { | ||
return cb(new Error( | ||
util.format('Failed to get SplitListByExchange (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get SplitListByExchange (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -793,10 +841,11 @@ var splits = []; | ||
_.keys(splits).length).yellow); | ||
return cb(null, splits); | ||
return _.isFunction(cb) ? cb(null, splits) : dfd.resolve(splits); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get SplitListByExchange (%s): status %d', | ||
exchangeCode, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get SplitListByExchange (%s): status %d', | ||
exchangeCode, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -806,12 +855,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getSplitListBySymbol = function (exchangeCode, symbolCode, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -829,13 +880,14 @@ debug('Downloading SplitListBySymbol...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.SPLITS) { | ||
return cb(new Error( | ||
util.format('Failed to get SplitListBySymbol (%s:%s): %s', | ||
exchangeCode, | ||
symbolCode, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get SplitListBySymbol (%s:%s): %s', | ||
exchangeCode, | ||
symbolCode, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -852,11 +904,12 @@ var splits = []; | ||
_.keys(splits).length).yellow); | ||
return cb(null, splits); | ||
return _.isFunction(cb) ? cb(null, splits) : dfd.resolve(splits); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get SplitListBySymbol (%s:%s): status %d', | ||
exchangeCode, | ||
symbolCode, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get SplitListBySymbol (%s:%s): status %d', | ||
exchangeCode, | ||
symbolCode, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -866,12 +919,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getSymbolChangesByExchange = function (exchangeCode, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -888,12 +943,13 @@ debug('Downloading SymbolChangesByExchange...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.SYMBOLCHANGES) { | ||
return cb(new Error( | ||
util.format('Failed to get SymbolChangesByExchange (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get SymbolChangesByExchange (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -909,10 +965,11 @@ var symbolChanges = []; | ||
_.keys(symbolChanges).length).yellow); | ||
return cb(null, symbolChanges); | ||
return _.isFunction(cb) ? cb(null, symbolChanges) : dfd.resolve(symbolChanges); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get SymbolChangesByExchange (%s): status %d', | ||
exchangeCode, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get SymbolChangesByExchange (%s): status %d', | ||
exchangeCode, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -922,12 +979,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getSymbolGet = function (exchangeCode, symbolCode, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -945,25 +1004,27 @@ debug('Downloading SymbolGet...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.SYMBOL) { | ||
return cb(new Error( | ||
util.format('Failed to get SymbolGet (%s:%s): %s', | ||
exchangeCode, | ||
symbolCode, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get SymbolGet (%s:%s): %s', | ||
exchangeCode, | ||
symbolCode, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
var symbol = result.RESPONSE.SYMBOL[0].$; | ||
debug(util.format('SymbolGet (%s:%s)', exchangeCode, symbolCode).yellow); | ||
return cb(null, symbol); | ||
return _.isFunction(cb) ? cb(null, symbol) : dfd.resolve(symbol); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get SymbolGet (%s:%s): status %d', | ||
exchangeCode, | ||
symbolCode, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get SymbolGet (%s:%s): status %d', | ||
exchangeCode, | ||
symbolCode, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -973,12 +1034,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getSymbolHistory = function (exchangeCode, symbolCode, startDate, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -997,14 +1060,15 @@ debug('Downloading SymbolHistory...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.QUOTES) { | ||
return cb(new Error( | ||
util.format('Failed to get SymbolHistory (%s:%s, %s-): %s', | ||
exchangeCode, | ||
symbolCode, | ||
moment(startDate).format('M/D/YYYY'), | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get SymbolHistory (%s:%s, %s-): %s', | ||
exchangeCode, | ||
symbolCode, | ||
moment(startDate).format('M/D/YYYY'), | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1022,12 +1086,13 @@ var quotes = []; | ||
quotes.length).yellow); | ||
return cb(null, quotes); | ||
return _.isFunction(cb) ? cb(null, quotes) : dfd.resolve(quotes); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get SymbolHistory (%s:%s, %s-): status %d', | ||
exchangeCode, | ||
symbolCode, | ||
moment(startDate).format('M/D/YYYY'), | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get SymbolHistory (%s:%s, %s-): status %d', | ||
exchangeCode, | ||
symbolCode, | ||
moment(startDate).format('M/D/YYYY'), | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1037,12 +1102,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getSymbolHistoryPeriod = function (exchangeCode, symbolCode, date, period, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -1062,15 +1129,16 @@ debug('Downloading SymbolHistoryPeriod...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.QUOTES) { | ||
return cb(new Error( | ||
util.format('Failed to get SymbolHistoryPeriod (%s:%s, %s, %s): %s', | ||
exchangeCode, | ||
symbolCode, | ||
moment(date).format('M/D/YYYY'), | ||
period, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get SymbolHistoryPeriod (%s:%s, %s, %s): %s', | ||
exchangeCode, | ||
symbolCode, | ||
moment(date).format('M/D/YYYY'), | ||
period, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1089,13 +1157,14 @@ var quotes = []; | ||
quotes.length).yellow); | ||
return cb(null, quotes); | ||
return _.isFunction(cb) ? cb(null, quotes) : dfd.resolve(quotes); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get SymbolHistoryPeriod (%s:%s, %s, %s): status %d', | ||
exchangeCode, | ||
symbolCode, | ||
moment(date).format('M/D/YYYY'), | ||
period, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get SymbolHistoryPeriod (%s:%s, %s, %s): status %d', | ||
exchangeCode, | ||
symbolCode, | ||
moment(date).format('M/D/YYYY'), | ||
period, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1105,12 +1174,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getSymbolHistoryPeriodByDateRange = function (exchangeCode, symbolCode, startDate, endDate, period, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -1131,16 +1202,17 @@ debug('Downloading SymbolHistoryPeriodByDateRange...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.QUOTES) { | ||
return cb(new Error( | ||
util.format('Failed to get SymbolHistoryPeriodByDateRange (%s:%s, %s-%s, %s): %s', | ||
exchangeCode, | ||
symbolCode, | ||
moment(startDate).format('M/D/YYYY'), | ||
moment(endDate).format('M/D/YYYY'), | ||
period, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get SymbolHistoryPeriodByDateRange (%s:%s, %s-%s, %s): %s', | ||
exchangeCode, | ||
symbolCode, | ||
moment(startDate).format('M/D/YYYY'), | ||
moment(endDate).format('M/D/YYYY'), | ||
period, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1160,14 +1232,15 @@ var quotes = []; | ||
quotes.length).yellow); | ||
return cb(null, quotes); | ||
return _.isFunction(cb) ? cb(null, quotes) : dfd.resolve(quotes); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get SymbolHistoryPeriodByDateRange (%s:%s, %s-%s, %s): status %d', | ||
exchangeCode, | ||
symbolCode, | ||
moment(startDate).format('M/D/YYYY'), | ||
moment(endDate).format('M/D/YYYY'), | ||
period, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get SymbolHistoryPeriodByDateRange (%s:%s, %s-%s, %s): status %d', | ||
exchangeCode, | ||
symbolCode, | ||
moment(startDate).format('M/D/YYYY'), | ||
moment(endDate).format('M/D/YYYY'), | ||
period, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1177,12 +1250,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getSymbolList2 = function (exchangeCode, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -1199,12 +1274,13 @@ debug('Downloading SymbolList2...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.SYMBOLS2) { | ||
return cb(new Error( | ||
util.format('Failed to get SymbolList2 (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get SymbolList2 (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1220,10 +1296,11 @@ var symbols = {}; | ||
_.keys(symbols).length).yellow); | ||
return cb(null, symbols); | ||
return _.isFunction(cb) ? cb(null, symbols) : dfd.resolve(symbols); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get SymbolList2 (%s): status %d', | ||
exchangeCode, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get SymbolList2 (%s): status %d', | ||
exchangeCode, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1233,12 +1310,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getTechnicalList = function (exchangeCode, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -1255,12 +1334,13 @@ debug('Downloading TechnicalList...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.TECHNICALS) { | ||
return cb(new Error( | ||
util.format('Failed to get TechnicalList (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get TechnicalList (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1276,10 +1356,11 @@ var technicals = {}; | ||
_.keys(technicals).length).yellow); | ||
return cb(null, technicals); | ||
return _.isFunction(cb) ? cb(null, technicals) : dfd.resolve(technicals); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get TechnicalList (%s): status %d', | ||
exchangeCode, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get TechnicalList (%s): status %d', | ||
exchangeCode, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1289,12 +1370,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getTop10Gains = function (exchangeCode, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -1311,12 +1394,13 @@ debug('Downloading Top10Gains...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.QUOTES) { | ||
return cb(new Error( | ||
util.format('Failed to get Top10Gains (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get Top10Gains (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1332,10 +1416,11 @@ var quotes = []; | ||
quotes.length).yellow); | ||
return cb(null, quotes); | ||
return _.isFunction(cb) ? cb(null, quotes) : dfd.resolve(quotes); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get Top10Gains (%s): status %d', | ||
exchangeCode, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get Top10Gains (%s): status %d', | ||
exchangeCode, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1345,12 +1430,14 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
Data.prototype.getTop10Losses = function (exchangeCode, cb) { | ||
var self = this; | ||
var self = this, | ||
dfd = Q.defer(), | ||
e; | ||
if (!_.isFunction(cb)) { cb = _util.logCallback; } | ||
this._taskQueue.push({run: function (next) { | ||
self._getToken(function (err, token) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
@@ -1367,12 +1454,13 @@ debug('Downloading Top10Losses...'.cyan); | ||
next(); | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (res.statusCode === 200) { | ||
xml2js.parseString(body, function (err, result) { | ||
if (err) { return cb(err); } | ||
if (err) { return _.isFunction(cb) ? cb(err) : dfd.reject(err); } | ||
if (!result.RESPONSE.QUOTES) { | ||
return cb(new Error( | ||
util.format('Failed to get Top10Losses (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message) | ||
e = new Error(util.format( | ||
'Failed to get Top10Losses (%s): %s', | ||
exchangeCode, | ||
result.RESPONSE.$.Message | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1388,10 +1476,11 @@ var quotes = []; | ||
quotes.length).yellow); | ||
return cb(null, quotes); | ||
return _.isFunction(cb) ? cb(null, quotes) : dfd.resolve(quotes); | ||
}); | ||
} else { | ||
return cb(new Error( | ||
util.format('Failed to get Top10Losses (%s): status %d', | ||
exchangeCode, | ||
res.statusCode) | ||
e = new Error(util.format( | ||
'Failed to get Top10Losses (%s): status %d', | ||
exchangeCode, | ||
res.statusCode | ||
)); | ||
return _.isFunction(cb) ? cb(e) : dfd.reject(e); | ||
} | ||
@@ -1401,2 +1490,4 @@ }); | ||
}}); | ||
return dfd.promise; | ||
}; | ||
@@ -1403,0 +1494,0 @@ |
{ | ||
"name": "eoddata", | ||
"description": "EODData client library for Node.js", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -29,15 +29,16 @@ "author": { | ||
"dependencies": { | ||
"async": "~0.2.9", | ||
"async": "~0.2.10", | ||
"colors": "~0.6.2", | ||
"debug": "~0.7.3", | ||
"lodash": "~1.0.1", | ||
"moment": "~2.0.0", | ||
"request": "~2.16.6", | ||
"xml2js": "~0.2.8" | ||
"debug": "~0.7.4", | ||
"lodash": "~2.4.1", | ||
"moment": "~2.5.1", | ||
"q": "~1.0.0", | ||
"request": "~2.33.0", | ||
"xml2js": "~0.4.1" | ||
}, | ||
"devDependencies": { | ||
"grunt": "~0.4.1", | ||
"grunt-contrib-jshint": "~0.3.0", | ||
"grunt": "~0.4.2", | ||
"grunt-contrib-jshint": "~0.8.0", | ||
"grunt-contrib-watch": "~0.5.3", | ||
"matchdep": "~0.1.2" | ||
"matchdep": "~0.3.0" | ||
}, | ||
@@ -44,0 +45,0 @@ "scripts": { |
[![NPM](https://nodei.co/npm/eoddata.png?downloads=false&stars=false)](https://npmjs.org/package/eoddata) [![NPM](https://nodei.co/npm-dl/eoddata.png?months=6)](https://npmjs.org/package/eoddata) | ||
# EODData | ||
`eoddata` is a client library for [EODData Web Service](http://eoddata.com/) written in [Node.js](http://nodejs.org/). | ||
`eoddata` is a client library for [EODData Web Service](http://eoddata.com/) written in [Node.js](http://nodejs.org/). This library returns the result in both callback & promise styles. | ||
## Installation | ||
@@ -11,2 +13,3 @@ | ||
## Usage | ||
@@ -21,2 +24,5 @@ | ||
* [See more comprehensive examples here.](https://github.com/pilwon/node-eoddata/tree/master/examples) | ||
### API ([documentation](http://ws.eoddata.com/Data.asmx)) | ||
@@ -26,5 +32,8 @@ | ||
All API functions accept callback as the last parameter. Whether you pass a callback function or not, they will always return a promise object built using Q. You can do whatever you want with the returned promise, or stick with the traditional callback style. | ||
- **Date Format:** JavaScript Date Object or String format supported by [Moment.js](http://momentjs.com/docs/) | ||
- **Periods:** 1, 5, 10, 15, 30, h, d, w, m, q, y | ||
#### Country List | ||
@@ -49,2 +58,3 @@ | ||
#### Data Formats | ||
@@ -84,2 +94,3 @@ | ||
#### Exchange Get | ||
@@ -109,2 +120,3 @@ | ||
#### Exchange List | ||
@@ -137,2 +149,3 @@ | ||
#### Fundamental List | ||
@@ -174,2 +187,3 @@ | ||
#### Quote Get | ||
@@ -204,2 +218,3 @@ | ||
#### Quote List | ||
@@ -237,2 +252,3 @@ | ||
#### Quote List 2 | ||
@@ -248,2 +264,3 @@ | ||
#### Quote List by Date | ||
@@ -259,2 +276,3 @@ | ||
#### Quote List by Date 2 | ||
@@ -285,2 +303,3 @@ | ||
#### Quote List by Date Period | ||
@@ -321,2 +340,3 @@ | ||
#### Quote List by Date Period 2 | ||
@@ -350,2 +370,3 @@ | ||
#### Split List by Exchange | ||
@@ -370,2 +391,3 @@ | ||
#### Split List by Symbol | ||
@@ -381,2 +403,3 @@ | ||
#### Symbol Changes by Exchange | ||
@@ -402,2 +425,3 @@ | ||
#### Symbol Get | ||
@@ -419,2 +443,3 @@ | ||
#### Symbol History | ||
@@ -452,2 +477,3 @@ | ||
#### Symbol History Period | ||
@@ -463,2 +489,3 @@ | ||
#### Symbol History Period by Date Range | ||
@@ -474,2 +501,3 @@ | ||
#### Symbol List 2 | ||
@@ -498,2 +526,3 @@ | ||
#### Technical List | ||
@@ -559,2 +588,3 @@ | ||
#### Top 10 Gains | ||
@@ -592,2 +622,3 @@ | ||
#### Top 10 Losses | ||
@@ -603,2 +634,3 @@ | ||
## Credits | ||
@@ -608,2 +640,3 @@ | ||
## License | ||
@@ -614,3 +647,3 @@ | ||
Copyright (c) 2012-2013 Pilwon Huh | ||
Copyright (c) 2012-2014 Pilwon Huh | ||
@@ -635,1 +668,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy | ||
</pre> | ||
[![Analytics](https://ga-beacon.appspot.com/UA-47034562-5/node-eoddata/readme?pixel)](https://github.com/pilwon/node-eoddata) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66400
1336
642
8
5
+ Addedq@~1.0.0
+ Addedasn1@0.1.11(transitive)
+ Addedassert-plus@0.1.5(transitive)
+ Addedasync@0.9.2(transitive)
+ Addedaws-sign2@0.5.0(transitive)
+ Addedboom@0.4.2(transitive)
+ Addedcryptiles@0.2.2(transitive)
+ Addedctype@0.5.3(transitive)
+ Addedforever-agent@0.5.2(transitive)
+ Addedform-data@0.1.4(transitive)
+ Addedhawk@1.0.0(transitive)
+ Addedhoek@0.9.1(transitive)
+ Addedhttp-signature@0.10.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedlodash@2.4.2(transitive)
+ Addedmoment@2.5.1(transitive)
+ Addedoauth-sign@0.3.0(transitive)
+ Addedq@1.0.1(transitive)
+ Addedqs@0.6.6(transitive)
+ Addedrequest@2.33.0(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedsntp@0.2.4(transitive)
+ Addedtldts@6.1.71(transitive)
+ Addedtldts-core@6.1.71(transitive)
+ Addedtough-cookie@5.1.0(transitive)
+ Addedtunnel-agent@0.3.0(transitive)
+ Addedxml2js@0.4.23(transitive)
+ Addedxmlbuilder@11.0.1(transitive)
- Removedaws-sign@0.2.1(transitive)
- Removedboom@0.3.8(transitive)
- Removedcookie-jar@0.2.0(transitive)
- Removedcryptiles@0.1.3(transitive)
- Removedforever-agent@0.2.0(transitive)
- Removedform-data@0.0.10(transitive)
- Removedhawk@0.10.2(transitive)
- Removedhoek@0.7.6(transitive)
- Removedjson-stringify-safe@3.0.0(transitive)
- Removedlodash@1.0.2(transitive)
- Removedmoment@2.0.0(transitive)
- Removedoauth-sign@0.2.0(transitive)
- Removedqs@0.5.6(transitive)
- Removedrequest@2.16.6(transitive)
- Removedsax@0.5.8(transitive)
- Removedsntp@0.1.4(transitive)
- Removedtunnel-agent@0.2.0(transitive)
- Removedxml2js@0.2.8(transitive)
Updatedasync@~0.2.10
Updateddebug@~0.7.4
Updatedlodash@~2.4.1
Updatedmoment@~2.5.1
Updatedrequest@~2.33.0
Updatedxml2js@~0.4.1