Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Jasmine refactor/backfill command/creating collections service2 #974

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions commands/backfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ var tb = require('timebucket')

module.exports = function container (get, set, clear) {
var c = get('conf') || {}

var collectionService = get('lib.collection-service')(get, set, clear)

return function (program) {
program
.command('backfill [selector]')
Expand All @@ -17,10 +20,10 @@ module.exports = function container (get, set, clear) {
console.error('cannot backfill ' + selector.normalized + ': exchange not implemented')
process.exit(1)
}
var trades = get('db.trades')
get('db.mongo').collection('trades').ensureIndex({selector: 1, time: 1})
var resume_markers = get('db.resume_markers')
get('db.mongo').collection('resume_markers').ensureIndex({selector: 1, to: -1})

var trades = collectionService.getTrades();
var resume_markers = collectionService.getResumeMarkers();

var marker = {
id: crypto.randomBytes(4).toString('hex'),
selector: selector.normalized,
Expand Down
1 change: 1 addition & 0 deletions lib/_codemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ module.exports = {
'adx': require('./adx'),
'vwap': require('./vwap'),
'slow_stochastic': require('./slow_stochastic'),
'collection-service': require('./services/collection-service'),
'cmf': require('./cmf')
}
21 changes: 21 additions & 0 deletions lib/services/collection-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = (function (get, set, clear) {

return {

getTrades: () => {
var trades = get('db.trades')
get('db.mongo').collection('trades').ensureIndex({selector: 1, time: 1})

return trades
},

getResumeMarkers: () => {
var resume_markers = get('db.resume_markers')
get('db.mongo').collection('resume_markers').ensureIndex({selector: 1, to: -1})

return resume_markers;
}
}

})

74 changes: 47 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"zenbot": "./zenbot.sh"
},
"scripts": {
"test": "jasmine test/**/**.test.js",
"postinstall": "rm -rf node_modules/forex.analytics/.git"
},
"dependencies": {
Expand All @@ -21,13 +22,13 @@
"bitfinex-api-node": "^1.2.0",
"bitstamp": "^1.0.4",
"bl": "^1.2.1",
"ccxt": "^1.10.171",
"cexio-api-node": "^1.0.8",
"cliff": "^0.1.10",
"codemap": "^1.3.1",
"colors": "^1.1.2",
"commander": "^2.9.0",
"convnetjs": "0.3.0",
"ccxt": "^1.10.171",
"express": "^4.16.2",
"forex.analytics": "mkmarek/forex.analytics#7bc278987700d4204e959af17de61495941d1a14",
"gdax": "^0.4.2",
Expand All @@ -36,6 +37,7 @@
"har-validator": "^5.0.3",
"idgen": "^2.0.2",
"ip": "~1.1.5",
"jasmine": "^2.8.0",
"kraken-api": "^0.1.7",
"mathjs": "3.16.5",
"micro-request": "^666.0.10",
Expand All @@ -55,16 +57,16 @@
"pusher-js": "^4.1.0",
"quadrigacx": "0.0.7",
"random-port": "^0.1.0",
"regression": "^2.0.0",
"run-parallel": "^1.1.6",
"run-series": "^1.1.4",
"regression": "^2.0.0",
"semver": "^5.4.1",
"simple-xmpp": "^1.3.0",
"sosa_mongo": "^1.0.3",
"stats-lite": "2.1.0",
"talib": "^1.0.3",
"trend": "0.3.0",
"timebucket": "^0.4.0",
"trend": "0.3.0",
"wexnz": "^0.1.3",
"ws": "^3.2.0",
"zero-fill": "^2.2.3"
Expand Down
58 changes: 58 additions & 0 deletions test/lib/services/collections-service.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

var service = require('../../../lib/services/collection-service')

describe('Collections Service', function() {
beforeEach(function() {
foo = {
get: function() { },
set: function() { },
clear: function() { }
}
})

describe(' trades ', function() {
beforeEach(function() {
spyOn(foo, 'get').and.returnValues([1, 2, 3], {collection: function() { return { ensureIndex: function() { }} } });
})

it('is available', function() {
expect(service).not.toBe(undefined);
}),

it('returns the expected objects', function() {

var instance = service(foo.get, foo.set, foo.clear)

var rtn = instance.getTrades()

expect(rtn).toBeDefined();
expect(rtn.length).toEqual(3);
expect(rtn[0]).toEqual(1);
expect(rtn[1]).toEqual(2);
expect(rtn[2]).toEqual(3);
})
}),

describe(' resume_markers ', function() {
beforeEach(function() {
spyOn(foo, 'get').and.returnValues([1, 2, 3], {collection: function() { return { ensureIndex: function() { }} } });
})

it('is available', function() {
expect(service).not.toBe(undefined);
}),

it('returns the expected objects', function() {

var instance = service(foo.get, foo.set, foo.clear)

var rtn = instance.getResumeMarkers()

expect(rtn).toBeDefined();
expect(rtn.length).toEqual(3);
expect(rtn[0]).toEqual(1);
expect(rtn[1]).toEqual(2);
expect(rtn[2]).toEqual(3);
})
})
});