-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
73 lines (54 loc) · 1.32 KB
/
index.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
Market tick storage for Node.js
=============
Stores and reads market ticks data in very condensed format and does it very fast.
Writing ticks
--------------
Example usage:
```javascript
var Writer = require('tickstorage').Writer;
writer = new Writer("/tmp/test.ticks");
writer.addTick({
unixtime: Date.now(),
volume: 100,
price: 50000,
bid: 50100,
ask: 49900,
bidSize: 100000,
askSize: 100000,
isMarket: true
});
writer.save(fucntion(err) {
if (err) return console.log(err);
console.log("Ticks saved successfully");
});
```
See [Writer documentation](lib/Writer.html) for implementation details.
Reading ticks
----------
Example usage:
```javascript
var Reader = require('tickstorage').Reader;
reader = new Reader("/tmp/test.ticks");
reader.load(function(err) {
if (err) return console.error(err);
console.log("Ticks count: ", reader.length);
var tick, totalVolume = 0;
while(tick = reader.nextTick()) {
if (tick.isMarket) {
totalVolume += tick.volume;
}
}
console.log("Total volume: ", totalVolume);
});
```
Reader supports tick files created by [stock module](http://github.com/egorFiNE/node-stock).
See [Reader documentation](lib/Reader.html) for implementation details.
*/
var
Reader = require('./lib/Reader'),
Writer = require('./lib/Writer');
module.exports = {
Reader: Reader,
Writer: Writer
};