Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

made jslint happy

  • Loading branch information...
commit ad77b07a8e84679bf6658e9df72e34e66d0e2080 1 parent cea188b
@egorFiNE authored
View
36 CandlesCalculator.js
@@ -1,4 +1,8 @@
-util = require('util');
+/*jslint devel: false, node: true, sloppy: true, eqeq: true, es5: true, vars: true, white: true, nomen: true, plusplus: true, maxerr: 50, indent: 4 */
+
+var
+ util = require('util'),
+ TickStorage = require('./TickStorage');
/**
@@ -50,7 +54,7 @@ function CandlesCalculator(tickStorage, periodSizeInMinutes) {
this._calculate();
}
-CandlesCalculator.prototype._findOc = function(minute, openPos, closePos) {
+CandlesCalculator.prototype._findOc = function(openPos, closePos) {
var i, tick;
var open=null, close=null, _openPos=null;
@@ -83,8 +87,8 @@ CandlesCalculator.prototype._findOc = function(minute, openPos, closePos) {
return {
o: open,
c: close
- }
-}
+ };
+};
/**
@@ -100,7 +104,7 @@ CandlesCalculator.prototype.dumpMinutes = function(from, to) {
for (i=from;i<=to;i++) {
console.log("%d: %s", i, util.inspect(this._calculatedMinuteIndex[i]));
}
-}
+};
/**
@@ -116,7 +120,7 @@ CandlesCalculator.prototype.dumpCandles = function(from, to) {
for (i=from;i<=to;i+=this.periodSize) {
console.log("%d: %s", i, util.inspect(this.candles[i]));
}
-}
+};
/**
@@ -130,7 +134,7 @@ Get calculated candle.
CandlesCalculator.prototype.getCandle = function(minute) {
return this.candles[minute] || null;
-}
+};
CandlesCalculator.prototype._calculate = function() {
var i;
@@ -138,7 +142,7 @@ CandlesCalculator.prototype._calculate = function() {
this.candles[i] = this._calculatePeriod(i);
CandlesCalculator._setCandleHourMinute(this.candles[i], i);
}
-}
+};
CandlesCalculator.prototype._calculatePeriod = function(period) {
var open=0, close=0, high=Number.MIN_VALUE, low=Number.MAX_VALUE, volume=0, ticks=0;
@@ -169,11 +173,11 @@ CandlesCalculator.prototype._calculatePeriod = function(period) {
c: close,
v: volume,
t: ticks
- }
+ };
} else {
return null;
}
-}
+};
CandlesCalculator.prototype._calculateMinutes = function() {
var _newMinuteIndex=[];
@@ -189,7 +193,7 @@ CandlesCalculator.prototype._calculateMinutes = function() {
var minute = this._tickStorage.minuteIndex.index[m];
if (minute) {
- var oc = this._findOc(m, minute.o, minute.c);
+ var oc = this._findOc(minute.o, minute.c);
if (oc) {
_newMinuteIndex[m].h=minute.h;
_newMinuteIndex[m].l=minute.l;
@@ -202,7 +206,7 @@ CandlesCalculator.prototype._calculateMinutes = function() {
}
this._calculatedMinuteIndex = _newMinuteIndex;
-}
+};
CandlesCalculator._setCandleHourMinute = function(candle, minute) {
if (candle) {
@@ -213,7 +217,7 @@ CandlesCalculator._setCandleHourMinute = function(candle, minute) {
candle.minute = d.getMinutes();
candle.m = minute;
}
-}
+};
/**
@@ -256,7 +260,7 @@ CandlesCalculator.getCandlesOfTickStorage = function(tickStorage, period, from,
}
return _result;
-}
+};
/**
@@ -279,7 +283,9 @@ CandlesCalculator.getCandles = function(dbPath, symbol, daystamp, period, from,
}
return CandlesCalculator.getCandlesOfTickStorage(tickStorage, period, from, to);
-}
+};
module.exports = CandlesCalculator;
+
+
View
32 ExtraDate.js
@@ -1,5 +1,9 @@
require('date-utils');
+function _zeroStrip(s) {
+ return s.toString().replace(/^0+/, '');
+}
+
/**
Various date methods useful for stock trading.
@@ -16,7 +20,7 @@ be specified both in string or integer and all the methods and functions must ac
// trick doc.js into thinking that we have declared the Date class.
/*
function Date() {
-}
+};
*/
/**
@@ -38,7 +42,7 @@ Date.parseDaystamp = function(daystamp) {
m--;
return new Date(y,m,d);
-}
+};
/**
@@ -50,7 +54,7 @@ Return daystamp representation of a Date.
Date.prototype.daystamp = function() {
return this.toFormat('YYYYMMDD');
-}
+};
/**
@@ -64,7 +68,7 @@ Parse unixtime into Date. It's a factory method.
Date.parseUnixtime = function(unixtime) {
return new Date(unixtime*1000);
-}
+};
/**
@@ -75,8 +79,8 @@ Return unixtime representation of a Date.
*/
Date.prototype.unixtime = function() {
- return this.getTime()/1000 >> 0;
-}
+ return parseInt(this.getTime()/1000);
+};
/**
@@ -88,7 +92,7 @@ Return current unixtime.
Date.unixtime = function() {
return new Date().unixtime();
-}
+};
/**
@@ -142,7 +146,7 @@ Date.fillEmptyDays = function(from, to) {
}
return result;
-}
+};
/**
@@ -154,7 +158,7 @@ Get short human readable day name for given Date, like "Sun", "Mon", ...
Date.prototype.getDayName = function() {
return ['Sun','Mon','Tue','Wed','Thu','Fri','Sat','Sun'][this.getDay()];
-}
+};
/**
@@ -169,7 +173,7 @@ Date.prototype.setCurrentDayMinute = function(minute) {
var hours = Math.floor(minute/60);
var minutes = minute-hours*60;
this.setHours(hours, minutes, 0, 0);
-}
+};
/**
@@ -182,7 +186,7 @@ e.g. 570 for 9:30.
Date.prototype.getCurrentDayMinute = function() {
return this.getHours()*60 + this.getMinutes();
-}
+};
/**
@@ -203,9 +207,5 @@ Date.minuteToFormat = function(minute, format) {
var d = new Date();
d.setCurrentDayMinute(minute);
return d.toFormat(format);
-}
-
-function _zeroStrip(s) {
- return s.toString().replace(/^0+/, '');
-}
+};
View
29 ExtraLog.js
@@ -1,5 +1,6 @@
require('./ExtraNumber');
require('./ExtraDate');
+var util = require('util');
/**
@@ -7,13 +8,7 @@ Actually it's a printf substitute with support for prices and unixtimes. Contain
*/
-// trick doc.js into thinking that we have declared the class.
-/*
-function ExtraLog() {
-}
-*/
-
-ExtraLog = {};
+function ExtraLog() {}
var formatRegExp = /%[sdjpTD%]/g;
@@ -33,19 +28,11 @@ Example:
*/
ExtraLog.format = function(f) {
- if (typeof f !== 'string') {
- var objects = [];
- for (var i = 0; i < arguments.length; i++) {
- objects.push(inspect(arguments[i]));
- }
- return objects.join(' ');
- }
-
- var i = 1;
+ var i=1, x;
var args = arguments;
var len = args.length;
var str = String(f).replace(formatRegExp, function(x) {
- if (i >= len) return x;
+ if (i >= len) { return x; }
switch (x) {
case '%D':return Date.parseUnixtime(args[i++]).toFormat('YYYYMMDD');
case '%T':return Date.parseUnixtime(args[i++]).toFormat('HH24:MI:SS');
@@ -58,15 +45,15 @@ ExtraLog.format = function(f) {
return x;
}
});
- for (var x = args[i]; i < len; x = args[++i]) {
+ for (x = args[i]; i < len; x = args[++i]) {
if (x === null || typeof x !== 'object') {
str += ' ' + x;
} else {
- str += ' ' + inspect(x);
+ str += ' ' + util.inspect(x);
}
}
return str;
-}
+};
/**
@@ -76,7 +63,7 @@ Similar to <code>console.log</code> but uses <code>ExtraLog.format()</code>.
ExtraLog.log = function() {
process.stdout.write(ExtraLog.format.apply(this, arguments) + '\n');
-}
+};
module.exports = {
format: ExtraLog.format,
View
10 ExtraNumber.js
@@ -25,7 +25,7 @@ Example:
*/
Number.prototype.humanReadablePrice = function() {
return (this/10000).toFixed(2);
-}
+};
/**
@@ -47,8 +47,8 @@ Number.prototype.pad = function(length) {
return _num;
}
- return (Array(length).join('0') + this).slice(-length);
-}
+ return (new Array(length).join('0') + this).slice(-length);
+};
/**
@@ -75,5 +75,5 @@ Number.prototype.humanReadableOrder = function() {
return (this/1000).toFixed(1)+'k';
}
- return this+'';
-}
+ return this.toString();
+};
View
24 MinuteIndex.js
@@ -1,6 +1,7 @@
-util = require('util');
-compress = require('compress-buffer').compress;
-uncompress = require('compress-buffer').uncompress;
+var
+ util = require('util'),
+ compress = require('compress-buffer').compress,
+ uncompress = require('compress-buffer').uncompress;
/**
@@ -39,17 +40,18 @@ function MinuteIndex() {
@private
*/
MinuteIndex.prototype.resetIndex = function() {
- for(var m=0;m<=1440;m++) {
+ var m;
+ for(m=0;m<=1440;m++) {
this.index[m]=null;
}
-}
+};
/**
@private
*/
MinuteIndex.prototype.setStartUnixtime = function(unixtime) {
this._startUnixtime = unixtime;
-}
+};
/**
@@ -67,7 +69,7 @@ MinuteIndex.prototype.dump = function(fromMinute, toMinute) {
for(i=fromMinute;i<=toMinute;i++) {
util.debug(util.format("%d: %s", i, util.inspect(this.index[i])));
}
-}
+};
/**
@private
@@ -115,14 +117,14 @@ MinuteIndex.prototype.addTick = function(position, unixtime, volume, price, isMa
} else {
this.index[minute].l = Math.min(this.index[minute].l, price);
}
-}
+};
/**
@private
*/
MinuteIndex.prototype.toGzip = function() {
return compress(new Buffer(JSON.stringify(this.index)));
-}
+};
/**
@private
@@ -141,11 +143,11 @@ MinuteIndex.prototype.fromGzip = function(buffer) {
try {
this.index = JSON.parse(uncompressed.toString());
- } catch (e) {
+ } catch (ee) {
return false;
}
return true;
-}
+};
module.exports = MinuteIndex;
View
33 Symbol.js
@@ -1,5 +1,6 @@
-fs = require('fs');
-path = require('path');
+var
+ fs = require('fs'),
+ path = require('path');
/**
@@ -9,7 +10,7 @@ list of *.ticks files with handy access methods.
@param {String} dbPath path to ticks database.
@param {String} symbol symbol name, must be uppercase.
-Tick files list is generated from <code>dbPath/symbol/*.ticks</code>.
+Tick files list is generated from <code>*.ticks</code> in <code>dbPath/SYMBOL/</code>.
Example:
@@ -53,7 +54,7 @@ Symbol.prototype.setIsActive = function(isActive) {
} else {
this.meta.isInactive = true;
}
-}
+};
/**
@@ -63,7 +64,7 @@ Get active flag for the ticker.
Symbol.prototype.isActive = function() {
return this.meta.isInactive ? false : true;
-}
+};
/**
@@ -83,7 +84,7 @@ Symbol.prototype._loadMeta = function() {
this.meta = {};
}
}
-}
+};
/**
@@ -93,7 +94,7 @@ Save updated information for the ticker. Now this is just the meta information t
Symbol.prototype.save = function() {
this._saveMeta();
-}
+};
/**
@@ -112,7 +113,7 @@ Symbol.prototype._saveMeta = function() {
fs.unlinkSync(this._metaFilename);
}
fs.renameSync(this._metaFilename+'.tmp', this._metaFilename);
-}
+};
/**
@@ -144,7 +145,7 @@ Symbol.prototype.load = function() {
}, this);
return true;
-}
+};
/**
@@ -159,7 +160,7 @@ Callback function will receive one argument: the daystamp, string.
Symbol.prototype.forEachDay = function(cb, context) {
this.days.forEach(cb, context);
-}
+};
/**
@@ -169,7 +170,7 @@ Rewind current iterator position to the beginning.
Symbol.prototype.rewind = function() {
this.dayPosition=0;
-}
+};
/**
@@ -181,7 +182,7 @@ Get the next day from list of days.
Symbol.prototype.nextDay = function() {
return this.days[this.dayPosition++];
-}
+};
/**
@@ -193,7 +194,7 @@ Get the first day from list of days.
Symbol.prototype.firstDay = function() {
return this.days[0];
-}
+};
/**
@@ -205,7 +206,7 @@ Get the last day from list of days.
Symbol.prototype.lastDay = function() {
return this.days[this.days.length-1];
-}
+};
/**
@@ -217,7 +218,7 @@ Get the count of available days.
Symbol.prototype.count = function() {
return this.days.length;
-}
+};
/**
@@ -231,6 +232,6 @@ Check if this daystamp exists for this ticker.
Symbol.prototype.dayExists = function(daystamp) {
return this.days.indexOf(daystamp)>=0;
-}
+};
module.exports = Symbol;
View
18 Symbols.js
@@ -1,6 +1,7 @@
-fs = require('fs');
-path = require('path');
-Symbol = require('./Symbol');
+var
+ fs = require('fs'),
+ path = require('path'),
+ Symbol = require('./Symbol');
/**
@@ -42,7 +43,6 @@ Symbols.prototype.load = function() {
var files = fs.readdirSync(this.dbPath);
files = files.sort();
- var i=0;
var symbolsUnsorted = [];
files.forEach(function(name) {
if (name.substr(0,1)!=='.' && name.toUpperCase()===name) {
@@ -54,7 +54,7 @@ Symbols.prototype.load = function() {
this.position=0;
return true;
-}
+};
/**
@@ -69,7 +69,7 @@ exists in dbpath.
Symbols.prototype.exists = function(symbol) {
return this.symbols.indexOf((symbol || '').toUpperCase()) >= 0;
-}
+};
/**
@@ -79,7 +79,7 @@ Rewind the iterator position back to zero.
Symbols.prototype.rewind = function() {
this.position=0;
-}
+};
/**
@@ -94,7 +94,7 @@ Symbols.prototype.next = function() {
return new Symbol(this.dbPath, this.symbols[this.position++]);
}
return null;
-}
+};
/**
@@ -106,7 +106,7 @@ Will return the count of symbols in tickers database.
Symbols.prototype.count = function() {
return this.symbols.length;
-}
+};
module.exports = Symbols;
View
104 TickStorage.js
@@ -1,11 +1,13 @@
-util = require('util');
-fs = require('fs');
-path = require('path');
-events = require('events');
+var
+ util = require('util'),
+ fs = require('fs'),
+ path = require('path'),
+ events = require('events'),
+ compress = require('compress-buffer').compress,
+ uncompress = require('compress-buffer').uncompress,
+ MinuteIndex = require('./MinuteIndex');
+
require('./ExtraDate');
-compress = require('compress-buffer').compress;
-uncompress = require('compress-buffer').uncompress;
-MinuteIndex = require('./MinuteIndex');
/**
@@ -131,7 +133,7 @@ TickStorage.prototype.filterMarketTime = function() {
}
this.nextTick = this._nextTickMarket;
-}
+};
/**
@@ -142,7 +144,7 @@ Returns symbol name.
*/
TickStorage.prototype.getSymbol = function() {
return this._symbol;
-}
+};
/**
@@ -153,7 +155,7 @@ Return true if this file exists in tick database.
*/
TickStorage.prototype.exists = function() {
return path.existsSync(this._path+this._filename);
-}
+};
/**
@@ -163,14 +165,14 @@ Will return the day minute to which the current position points to.
*/
TickStorage.prototype.tellMinute = function() {
- var _m=null;
- for (var m=0;m<1440;m++) {
+ var _m=null,m;
+ for (m=0;m<1440;m++) {
if (this.minuteIndex.index[m] && this.position>=this.minuteIndex.index[m].o ) {
_m = m;
}
}
return _m;
-}
+};
/**
@@ -189,7 +191,7 @@ TickStorage.prototype.seekToMinute = function(minute) {
} else {
return false;
}
-}
+};
/**
@@ -202,7 +204,7 @@ Seek to the first tick.
TickStorage.prototype.rewind = function() {
return this.seek(0, TickStorage.SEEK_SET);
-}
+};
/**
@@ -253,7 +255,7 @@ TickStorage.prototype.seek = function(ticks, whence) {
this.position = newPosition;
return this.position;
-}
+};
TickStorage.prototype._possiblyCreatePath = function() {
if (!path.existsSync(this._path)) {
@@ -264,7 +266,7 @@ TickStorage.prototype._possiblyCreatePath = function() {
}
}
return true;
-}
+};
/**
@@ -310,11 +312,13 @@ TickStorage.prototype.save = function(quick) {
var fd = fs.openSync(this._path+this._filename+".tmp", "w");
+ var bufferHeader;
+
if (this.count>0) {
var bytesLength = this.count*TickStorage.ENTRY_SIZE;
var bufferCompressed = compress(this._bufferData.slice(0, bytesLength));
- var bufferHeader = this._generateHeader(fd, header);
+ bufferHeader = this._generateHeader(header);
var targetBuffer = new Buffer(bufferHeader.length + bufferMinuteIndex.length + bufferCompressed.length);
bufferHeader.copy(targetBuffer);
@@ -326,7 +330,7 @@ TickStorage.prototype.save = function(quick) {
// despite that it exists it's not stored, so do not confuse
// any software with it's fake size
header.minuteIndexSize = 0;
- var bufferHeader = this._generateHeader(fd, header);
+ bufferHeader = this._generateHeader(header);
fs.writeSync(fd, bufferHeader, 0, bufferHeader.length);
}
fs.closeSync(fd);
@@ -341,20 +345,20 @@ TickStorage.prototype.save = function(quick) {
try {
fs.renameSync(this._path+this._filename+".tmp", this._path+this._filename);
- } catch (e) {
+ } catch (ee) {
return false;
}
}
return true;
-}
+};
-TickStorage.prototype._generateHeader = function(fd, header) {
+TickStorage.prototype._generateHeader = function(header) {
var bufHeader = new Buffer(TickStorage.HEADER_SIZE);
bufHeader.fill(0);
bufHeader.write(JSON.stringify(header)+"\n",0,'ascii');
return bufHeader;
-}
+};
/**
@@ -367,7 +371,7 @@ TickStorage.prototype.remove = function() {
fs.unlinkSync(this._path+this._filename);
} catch(e) {
}
-}
+};
/**
@@ -415,19 +419,20 @@ TickStorage.prototype.load = function() {
try {
this._bufferData = uncompress(buffer);
- } catch (e) {
+ } catch (ee) {
return false;
}
+
delete buffer;
return this._bufferData ? true : false;
-}
+};
TickStorage.prototype._loadMinuteIndex = function(fd, minuteIndexSize) {
var compressedMinuteIndex = new Buffer(minuteIndexSize);
fs.readSync(fd, compressedMinuteIndex, 0, minuteIndexSize, TickStorage.HEADER_SIZE);
return compressedMinuteIndex;
-}
+};
TickStorage.prototype._loadHeader = function(fd) {
try {
@@ -453,7 +458,7 @@ TickStorage.prototype._loadHeader = function(fd) {
} catch (e) {
return null;
}
-}
+};
/**
@@ -485,7 +490,7 @@ TickStorage.prototype.prepareForNew = function(megs) {
this.additionalData={};
this._orphanTicks=[];
-}
+};
/**
@@ -519,10 +524,10 @@ TickStorage.prototype.addTick = function(unixtime, volume, price, isMarket, disa
}
if (!disableOrphanLogic && unixtime < this._lastUnixtime-600) {
- var found = this._findPositionOfPreviousTickWithCloseUnixtime(unixtime);
+ var found = this._findPositionOfPreviousTickWithCloseUnixtime(unixtime), z;
if (found!=null) {
- for(var z=found+1;z<this.position;z++) {
+ for(z=found+1;z<this.position;z++) {
this._orphanTicks.push(this.tickAtPosition(z));
}
@@ -556,35 +561,38 @@ TickStorage.prototype.addTick = function(unixtime, volume, price, isMarket, disa
this.position++;
this.count++;
-}
+};
TickStorage.prototype._possiblyAppendAdditionalTicks = function() {
- for (var p=0;p<this._orphanTicks.length;p++) {
- var tick = this._orphanTicks[p];
+ var tick, p;
+ for (p=0;p<this._orphanTicks.length;p++) {
+ tick = this._orphanTicks[p];
if (tick && tick.unixtime<this._lastUnixtime) {
this.addTick(tick.unixtime, tick.volume, tick.price, tick.isMarket, true);
this._orphanTicks[p] = null;
}
}
-}
+};
TickStorage.prototype._findPositionOfPreviousTickWithCloseUnixtime = function(unixtime) {
- for (var pos=this.position-1;pos>=this.position-5;pos--) {
- var _tick = this.tickAtPosition(pos);
+ var _tick, pos;
+ for (pos=this.position-1;pos>=this.position-5;pos--) {
+ _tick = this.tickAtPosition(pos);
if (_tick && Math.abs(_tick.unixtime - unixtime) < 10) {
return pos;
}
}
return null;
-}
+};
TickStorage.prototype._generateMinuteIndex = function() {
+ var tick, pos;
this.minuteIndex.resetIndex();
- for (var pos=0;pos<this.count;pos++) {
- var tick = this.tickAtPosition(pos);
+ for (pos=0;pos<this.count;pos++) {
+ tick = this.tickAtPosition(pos);
this.minuteIndex.addTick(pos, tick.unixtime, tick.volume, tick.price, tick.isMarket);
}
-}
+};
/**
@@ -603,7 +611,7 @@ TickStorage.prototype.dumpOrphanTicks = function() {
);
}
}, this);
-}
+};
TickStorage.prototype._compressAdditionalTicks = function() {
var lastEntry = JSON.stringify(this._orphanTicks[0]);
@@ -617,7 +625,7 @@ TickStorage.prototype._compressAdditionalTicks = function() {
}, this);
this._orphanTicks = clearPool;
-}
+};
/**
@@ -635,7 +643,7 @@ TickStorage.prototype.tickAtPosition = function(position) {
}
return this._tickAtOffset(position*TickStorage.ENTRY_SIZE);
-}
+};
TickStorage.prototype._tickAtOffset = function(offset) {
if (!this._bufferData || offset>=this._bufferData.length || offset < 0) {
@@ -647,12 +655,12 @@ TickStorage.prototype._tickAtOffset = function(offset) {
volume: this._bufferData.readUInt32LE(offset+4),
price: this._bufferData.readUInt32LE(offset+8),
isMarket: this._bufferData.readUInt8(offset+12) == 1
- }
-}
+ };
+};
TickStorage.prototype._nextTickAll = function() {
return this._tickAtOffset(this.position++*TickStorage.ENTRY_SIZE);
-}
+};
TickStorage.prototype._nextTickMarket = function() {
var tick;
@@ -664,7 +672,7 @@ TickStorage.prototype._nextTickMarket = function() {
return null;
}
return tick;
-}
+};
/**
View
56 TimePeriod.js
@@ -61,9 +61,9 @@ function TimePeriod(str) {
this._baseUnixtime=0;
}
-module.exports = TimePeriod;
-
TimePeriod.prototype._parse = function() {
+ var i, m;
+
this.isValid=true;
this._periods=[];
@@ -71,12 +71,11 @@ TimePeriod.prototype._parse = function() {
this.lastMinute=null;
var periods = this._periodString.split(',');
- var i=0;
for(i=0;i<periods.length;i++) {
this._parseSinglePeriod(periods[i]);
}
- for(var m=0;m<1440;m++) {
+ for(m=0;m<1440;m++) {
if (this._periods[m]) {
if (this.firstMinute==null) {
this.firstMinute=m;
@@ -84,13 +83,13 @@ TimePeriod.prototype._parse = function() {
this.lastMinute=m;
}
}
-}
+};
TimePeriod.prototype._setUnixtime = function(unixtime) {
var d = Date.parseUnixtime(unixtime);
d.clearTime();
this._baseUnixtime = d.unixtime();
-}
+};
/**
@@ -114,7 +113,7 @@ TimePeriod.prototype.isUnixtimeIn = function(unixtime) {
var seconds = unixtime - this._baseUnixtime;
var minute = parseInt(seconds/60);
return this.isMinuteIn(minute);
-}
+};
TimePeriod.prototype._parseSinglePeriod = function(periodString) {
if (periodString.match(/-$/)) {
@@ -138,7 +137,7 @@ TimePeriod.prototype._parseSinglePeriod = function(periodString) {
return;
}
- if (endMinute===NaN || startMinute===NaN) {
+ if (isNaN(endMinute) || isNaN(startMinute)) {
this.isValid=false;
return;
}
@@ -152,7 +151,7 @@ TimePeriod.prototype._parseSinglePeriod = function(periodString) {
for(i=startMinute;i<endMinute;i++) {
this._periods[i]=true;
}
-}
+};
/**
@@ -166,7 +165,7 @@ Check if given date matches the period.
TimePeriod.prototype.isDateIn = function(date) {
return this.isHourMinuteIn(date.getHours(), date.getMinutes());
-}
+};
/**
@@ -180,8 +179,8 @@ Check if given hour and minute matches the period.
*/
TimePeriod.prototype.isHourMinuteIn = function(hour,minute) {
- return this.isMinuteIn(hour*60+minute*1);
-}
+ return this.isMinuteIn(hour*60+minute);
+};
/**
@@ -196,7 +195,7 @@ so 9:45 becomes 9*60+45=585.
TimePeriod.prototype.isMinuteIn = function(minute) {
return this._periods[minute];
-}
+};
/**
@@ -215,7 +214,7 @@ TimePeriod.prototype.getFirstMinute = function() {
}
return 0;
-}
+};
/**
@@ -233,8 +232,8 @@ TimePeriod.prototype.getLastMinute = function() {
lastMinute = i;
}
}
- return lastMinute==null?1339:lastMinute
-}
+ return lastMinute==null?1339:lastMinute;
+};
/**
@@ -253,7 +252,7 @@ Example:
TimePeriod.prototype.setMinute = function(m, enabled) {
this._periods[m] = enabled? true: false;
-}
+};
/**
@@ -268,13 +267,13 @@ TimePeriod.prototype.normalize = function() {
return '';
}
- var firstMinute = this.getFirstMinute();
- var lastMinute = this.getLastMinute();
-
- var _periods=[];
+ var
+ firstMinute = this.getFirstMinute(),
+ lastMinute = this.getLastMinute(),
+ _periods=[],
+ _periodsStrings=[],
+ currentPeriodOpen, m;
- var currentPeriodOpen=undefined;
- var m;
for(m=firstMinute;m<=lastMinute;m++) {
if (this._periods[m]) {
if (!currentPeriodOpen) {
@@ -291,12 +290,11 @@ TimePeriod.prototype.normalize = function() {
_periods.push([currentPeriodOpen, lastMinute]);
}
- var _periodsStrings=[];
_periods.forEach(function(period) {
_periodsStrings.push(TimePeriod.minuteToTime(period[0])+"-"+TimePeriod.minuteToTime(period[1]+1));
});
return _periodsStrings.join(',').replace(/:00/g,'');
-}
+};
/**
@@ -326,8 +324,8 @@ TimePeriod.timeToMinute = function(timeString) {
return undefined;
}
- return times[0]*60+times[1]*1;
-}
+ return times[0]*60+times[1];
+};
/**
@@ -341,4 +339,6 @@ Helper function. Will return time string for day minute.
TimePeriod.minuteToTime = function(m) {
return parseInt(m/60) + ':' +(parseInt(m%60)).pad(2);
-}
+};
+
+module.exports = TimePeriod;
View
21 WorkingDays.js
@@ -7,12 +7,7 @@ See source code for holidays array.
*/
-/*
-function WorkingDays() {
-}
-*/
-
-WorkingDays = {};
+function WorkingDays() {}
WorkingDays.nyseHolidays = {
2010: {
@@ -55,7 +50,7 @@ WorkingDays.nyseHolidays = {
11: [28],
12: [25]
}
-}
+};
WorkingDays.nyseShortDays = {
2011: {
@@ -81,7 +76,7 @@ WorkingDays.isNyseShortDay = function(day) {
}
}
return false;
-}
+};
/**
@@ -101,7 +96,7 @@ WorkingDays.isNyseHoliday = function(day) {
}
}
return false;
-}
+};
/**
@@ -116,7 +111,7 @@ Check if a given date is a Sunday or Saturday.
WorkingDays.isWeekend = function(day) {
var _d = day.getDay();
return (_d == 6 || _d==0);
-}
+};
/*
@@ -130,7 +125,7 @@ Check if the given date is a trading day at NYSE.
WorkingDays.isNyseWorkingDay = function(day) {
return (!WorkingDays.isNyseHoliday(day) && !WorkingDays.isWeekend(day));
-}
+};
/**
@@ -149,7 +144,7 @@ WorkingDays.prevNyseDay = function(day) {
nextDate.addDays(-1);
}
return nextDate;
-}
+};
/**
@@ -168,6 +163,6 @@ WorkingDays.nextNyseDay = function(day) {
nextDate.addDays(1);
}
return nextDate;
-}
+};
module.exports = WorkingDays;
View
2  docs/Symbol.html
@@ -48,7 +48,7 @@
<ul><li><code><span class="type">String</span></code> <code><strong>dbPath</strong></code> &#8212; path to ticks database.</li><li><code><span class="type">String</span></code> <code><strong>symbol</strong></code> &#8212; symbol name, must be uppercase.</li></ul>
-<p>Tick files list is generated from <code>dbPath/symbol/*.ticks</code>.</p>
+<p>Tick files list is generated from <code>*.ticks</code> in <code>dbPath/SYMBOL/</code>.</p>
<p>Example: </p>
View
12 test/CandlesCalculatorTest.js
@@ -1,9 +1,11 @@
-fs = require('fs');
-util = require('util');
+var
+ fs = require('fs'),
+ util = require('util'),
+ TickStorage = require('../TickStorage'),
+ CandlesCalculator = require('../CandlesCalculator');
+
require('../ExtraDate');
require('../ExtraNumber');
-TickStorage = require('../TickStorage');
-CandlesCalculator = require('../CandlesCalculator');
process.env.TZ='America/New_York';
@@ -33,5 +35,5 @@ exports['holes'] = function(test) {
// candles.dumpCandles(600, 620);
test.done();
-}
+};
View
6 test/ExtraDateTest.js
@@ -38,13 +38,13 @@ exports['current day minute'] = function(test) {
test.equal(day.toFormat('HH24:MI'), '23:59');
test.done();
-}
+};
exports['minutes helper'] = function(test) {
test.expect(1);
test.equal(Date.minuteToFormat(400, 'HH24:MI'), '06:40');
test.done();
-}
+};
exports['fill empty days'] = function(test) {
test.expect(4);
@@ -72,4 +72,4 @@ exports['fill empty days'] = function(test) {
test.deepEqual(days, ['20110615']);
test.done();
-}
+};
View
4 test/ExtraLogTest.js
@@ -1,11 +1,11 @@
require('date-utils');
-ExtraLog = require('../ExtraLog');
+var ExtraLog = require('../ExtraLog');
exports['price format'] = function(test) {
test.expect(4);
var d = new Date();
- d.setHours(13,23,41,00);
+ d.setHours(13,23,41,0);
d.setMonth(11, 29);
d.setYear(2011);
View
6 test/ExtraNumberTest.js
@@ -7,7 +7,7 @@ exports['number pad'] = function(test) {
test.equal((23).pad(2), "23");
test.equal((23).pad(1), "23");
test.done();
-}
+};
exports['check float errors'] = function(test) {
test.expect(2);
@@ -36,9 +36,9 @@ exports['check float errors'] = function(test) {
exports['human-readable number'] = function(test) {
test.equal(parseInt(23.34*10000).humanReadablePrice(), "23.34");
test.done();
-}
+};
exports['human-readable order'] = function(test) {
test.equal((9300000).humanReadableOrder(), "9.3m");
test.done();
-}
+};
View
13 test/SymbolTest.js
@@ -1,6 +1,7 @@
-util = require('util');
-fs = require('fs');
-Symbol = require('../Symbol');
+var
+ util = require('util'),
+ fs = require('fs'),
+ Symbol = require('../Symbol');
exports['basic']= function(test) {
test.expect(11);
@@ -22,7 +23,7 @@ exports['basic']= function(test) {
test.equal(symbol.nextDay(), '20110201');
test.done();
-}
+};
exports['meta']= function(test) {
test.expect(6);
@@ -47,7 +48,7 @@ exports['meta']= function(test) {
fs.unlinkSync('/tmp/DDDD/meta.json');
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['nonexisting']= function(test) {
@@ -63,4 +64,4 @@ exports['nonexisting']= function(test) {
test.equal(symbol.nextDay(), null);
test.ok(!symbol.dayExists('20110201'));
test.done();
-}
+};
View
11 test/SymbolsTest.js
@@ -1,6 +1,7 @@
-util = require('util');
-fs = require('fs');
-Symbols = require('../Symbols');
+var
+ util = require('util'),
+ fs = require('fs'),
+ Symbols = require('../Symbols');
exports['basic']= function(test) {
test.expect(8);
@@ -18,7 +19,7 @@ exports['basic']= function(test) {
test.equal(symbols.next().symbol, 'AAA');
test.done();
-}
+};
exports['nonexisting']= function(test) {
test.expect(1);
@@ -26,4 +27,4 @@ exports['nonexisting']= function(test) {
var symbols = new Symbols(__dirname+'/data/doesntexists');
test.ok(!symbols.load());
test.done();
-}
+};
View
49 test/TickStorageTest.js
@@ -1,11 +1,12 @@
-util = require('util');
-fs = require('fs');
-TickStorage = require('../TickStorage');
+var
+ util = require('util'),
+ fs = require('fs'),
+ TickStorage = require('../TickStorage');
exports['timezone test']= function(test) {
test.equal(process.env.TZ, 'America/New_York');
test.done();
-}
+};
exports['basic read']= function(test) {
test.expect(6);
@@ -28,7 +29,7 @@ exports['basic read']= function(test) {
test.equal(totalCount, 118003, 'total count');
test.equal(tickStorage.count, totalCount, 'tickstorage.count');
test.done();
-}
+};
exports['basic create'] = function(test) {
test.expect(7);
@@ -71,7 +72,7 @@ exports['basic create'] = function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['set incorrect unixtime'] = function(test) {
test.expect(5);
@@ -108,7 +109,7 @@ exports['set incorrect unixtime'] = function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['non-sequential unixtime'] = function(test) {
test.expect(7);
@@ -150,7 +151,7 @@ exports['non-sequential unixtime'] = function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['create huge'] = function(test) {
if (process.env.SKIP_HUGE) {
@@ -192,7 +193,7 @@ exports['create huge'] = function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['rewind and position'] = function(test) {
test.expect(13);
@@ -258,7 +259,7 @@ exports['rewind and position'] = function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['create zero tick'] = function(test) {
test.expect(4);
@@ -282,7 +283,7 @@ exports['create zero tick'] = function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['non-existing'] = function(test) {
test.expect(2);
@@ -295,7 +296,7 @@ exports['non-existing'] = function(test) {
test.ok(!tickStorage.save());
test.done();
-}
+};
exports['zero data'] = function(test) {
test.expect(6);
@@ -328,7 +329,7 @@ exports['zero data'] = function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['market open/close pos'] = function(test) {
test.expect(4);
@@ -368,7 +369,7 @@ exports['market open/close pos'] = function(test) {
test.equal(tickStorage.marketClosePos, 5);
test.done();
-}
+};
exports['market only'] = function(test) {
//test.expect(4);
@@ -403,7 +404,7 @@ exports['market only'] = function(test) {
tickStorage.remove();
test.done();
-}
+};
exports['invalid data'] = function(test) {
test.expect(5);
@@ -496,7 +497,7 @@ exports['minute index'] = function(test) {
test.deepEqual(tickStorage.minuteIndex.index[minute+4], {o: 16, c: 18, v: 300, h: 300, l: 100});
test.done();
-}
+};
exports['seek to minute']= function(test) {
//test.expect(9);
@@ -523,7 +524,7 @@ exports['seek to minute']= function(test) {
tickStorage = new TickStorage('/tmp', 'DDDD', '20110922');
tickStorage.prepareForNew();
- tickStorage.addTick(baseUnixtime+0, 100, 200, true);
+ tickStorage.addTick(baseUnixtime, 100, 200, true);
tickStorage.addTick(baseUnixtime+1, 100, 200, true);
tickStorage.addTick(baseUnixtime+60, 102, 400, true);
@@ -559,7 +560,7 @@ exports['seek to minute']= function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['ignore out of day ticks'] = function(test) {
test.expect(9);
@@ -593,7 +594,7 @@ exports['ignore out of day ticks'] = function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['blast from the future'] = function(test) {
test.expect(7);
@@ -624,7 +625,7 @@ exports['blast from the future'] = function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['blast from the past'] = function(test) {
test.expect(7);
@@ -655,7 +656,7 @@ exports['blast from the past'] = function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['out of order data small'] = function(test) {
@@ -685,7 +686,7 @@ exports['out of order data small'] = function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['out of order data larger'] = function(test) {
// basically it is the same as previous test but we add two ticks before and after and two future ticks in between
@@ -724,7 +725,7 @@ exports['out of order data larger'] = function(test) {
fs.rmdirSync('/tmp/DDDD/');
test.done();
-}
+};
exports['minute index with huge out of order data'] = function(test) {
test.expect(7);
@@ -754,5 +755,5 @@ exports['minute index with huge out of order data'] = function(test) {
test.deepEqual(tmpStorage.minuteIndex.index[15*60+30], {o: 125290, c: 125590, v: 337992, h: 245600, l: 245200});
test.done();
-}
+};
View
40 test/TimePeriodTest.js
@@ -1,4 +1,4 @@
-TimePeriod = require('../TimePeriod');
+var TimePeriod = require('../TimePeriod');
require('../ExtraDate');
require('../ExtraNumber');
@@ -11,7 +11,7 @@ exports['basic']= function(test) {
test.ok(t.isHourMinuteIn(9, 35));
test.ok(t.isHourMinuteIn(9, 30));
test.ok(t.isHourMinuteIn(9, 59));
- test.ok(!t.isHourMinuteIn(10, 00));
+ test.ok(!t.isHourMinuteIn(10, 0));
test.ok(!t.isHourMinuteIn(9, 29));
test.equal(t.firstMinute, 9*60+30);
@@ -23,12 +23,12 @@ exports['basic']= function(test) {
test.ok(t.isHourMinuteIn(9, 35));
test.ok(t.isHourMinuteIn(9, 30));
test.ok(t.isHourMinuteIn(9, 59));
- test.ok(!t.isHourMinuteIn(10, 00));
+ test.ok(!t.isHourMinuteIn(10, 0));
test.ok(!t.isHourMinuteIn(10, 30));
test.ok(!t.isHourMinuteIn(9, 29));
- test.ok(t.isHourMinuteIn(11, 00));
+ test.ok(t.isHourMinuteIn(11, 0));
test.ok(t.isHourMinuteIn(11, 59));
- test.ok(!t.isHourMinuteIn(12, 00));
+ test.ok(!t.isHourMinuteIn(12, 0));
test.ok(!t.isHourMinuteIn(10, 59));
test.ok(t.isHourMinuteIn(13, 35));
test.ok(!t.isHourMinuteIn(13, 43));
@@ -46,7 +46,7 @@ exports['basic']= function(test) {
test.equal(t.lastMinute, 23*60+59);
test.done();
-}
+};
exports['empty']= function(test) {
test.expect(13);
@@ -57,19 +57,19 @@ exports['empty']= function(test) {
test.ok(!t.isHourMinuteIn(9, 35));
test.ok(!t.isHourMinuteIn(9, 29));
test.ok(!t.isHourMinuteIn(15, 59));
- test.ok(!t.isHourMinuteIn(16, 00));
+ test.ok(!t.isHourMinuteIn(16, 0));
t = new TimePeriod();
test.ok(t.isValid);
test.ok(!t.isHourMinuteIn(9, 35));
test.ok(!t.isHourMinuteIn(9, 29));
test.ok(!t.isHourMinuteIn(15, 59));
- test.ok(!t.isHourMinuteIn(16, 00));
+ test.ok(!t.isHourMinuteIn(16, 0));
- test.ok(!t.isHourMinuteIn(16, 00));
+ test.ok(!t.isHourMinuteIn(16, 0));
test.ok(!t.isUnixtimeIn(Date.unixtime()));
test.done();
-}
+};
exports['hours']= function(test) {
test.expect(18);
@@ -91,14 +91,14 @@ exports['hours']= function(test) {
t = new TimePeriod('9-13:30');
test.ok(t.isValid);
- test.ok(t.isHourMinuteIn(9, 00));
+ test.ok(t.isHourMinuteIn(9, 0));
test.ok(t.isHourMinuteIn(13, 29));
test.ok(t.isHourMinuteIn(11, 23));
test.ok(!t.isHourMinuteIn(8, 59));
test.ok(!t.isHourMinuteIn(13, 30));
test.done();
-}
+};
exports['single hours']= function(test) {
test.expect(12);
@@ -108,20 +108,20 @@ exports['single hours']= function(test) {
test.ok(t.isValid);
test.ok(t.isHourMinuteIn(9, 0));
test.ok(t.isHourMinuteIn(9, 59));
- test.ok(!t.isHourMinuteIn(10, 00));
+ test.ok(!t.isHourMinuteIn(10, 0));
t = new TimePeriod('9,13,16');
test.ok(t.isValid);
test.ok(t.isHourMinuteIn(9, 0));
test.ok(t.isHourMinuteIn(9, 59));
- test.ok(!t.isHourMinuteIn(10, 00));
+ test.ok(!t.isHourMinuteIn(10, 0));
test.ok(!t.isHourMinuteIn(12, 59));
test.ok(t.isHourMinuteIn(13, 23));
- test.ok(!t.isHourMinuteIn(14, 00));
+ test.ok(!t.isHourMinuteIn(14, 0));
test.ok(!t.isHourMinuteIn(17, 0));
test.done();
-}
+};
exports['first and last minutes']= function(test) {
test.expect(6);
@@ -138,7 +138,7 @@ exports['first and last minutes']= function(test) {
test.equal(t.getLastMinute(), 16*60+30-1);
test.done();
-}
+};
exports['invalid']= function(test) {
test.expect(4);
@@ -157,7 +157,7 @@ exports['invalid']= function(test) {
test.ok(!t.isValid);
test.done();
-}
+};
exports['normalize']= function(test) {
test.expect(18);
@@ -200,7 +200,7 @@ exports['normalize']= function(test) {
test.equal(t.normalize(), "9:30-17");
test.done();
-}
+};
exports['unixtime']= function(test) {
@@ -229,4 +229,4 @@ exports['unixtime']= function(test) {
_test();
test.done();
-}
+};
View
11 test/WorkingDaysTest.js
@@ -1,6 +1,7 @@
-util = require('util');
+var
+ util = require('util'),
+ WorkingDays = require('../WorkingDays');
require('../ExtraDate');
-require('../WorkingDays');
exports['check nyse working days'] = function(test) {
process.env.TZ='America/New_York';
@@ -27,7 +28,7 @@ exports['check nyse working days'] = function(test) {
test.ok(WorkingDays.isNyseHoliday(day));
test.done();
-}
+};
exports['check nyse short days'] = function(test) {
process.env.TZ='America/New_York';
@@ -42,7 +43,7 @@ exports['check nyse short days'] = function(test) {
day = Date.parseDaystamp('20111125');
test.ok(WorkingDays.isNyseShortDay(day));
test.done();
-}
+};
exports['check nyse prev/next day'] = function(test) {
@@ -73,4 +74,4 @@ exports['check nyse prev/next day'] = function(test) {
test.equal(WorkingDays.nextNyseDay(day).daystamp(), '20110919');
test.done();
-}
+};
Please sign in to comment.
Something went wrong with that request. Please try again.