Skip to content

Commit 8f88925

Browse files
author
Carlos Rodriguez
committed
switch to dirscan model for extensions, import gdax extension, strip out old stuff, defaults now in conf-sample.js
1 parent 8a86755 commit 8f88925

28 files changed

Lines changed: 179 additions & 386 deletions

_codemap.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module.exports = {
33
_maps: [
44
require('./commands/_codemap'),
55
require('./db/_codemap'),
6-
require('./lib/_codemap'),
7-
require('./strategies/_codemap')
6+
require('./lib/_codemap')
87
],
9-
'conf': null,
10-
'exchanges.list': []
8+
'conf': {},
9+
'exchanges.list': [],
10+
'strategies.list': []
1111
}

boot.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
var glob = require('glob')
2+
, path = require('path')
3+
14
module.exports = function (cb) {
25
var zenbot = require('./')()
36
try {
@@ -6,44 +9,47 @@ module.exports = function (cb) {
69
catch (e) {
710
c = {}
811
}
9-
var defaults = require('./defaults')
12+
var defaults = require('./conf-sample')
1013
Object.keys(defaults).forEach(function (k) {
1114
if (typeof c[k] === 'undefined') {
1215
c[k] = defaults[k]
1316
}
1417
})
1518
zenbot.set('@zenbot:conf', c)
19+
20+
function withMongo () {
21+
glob('extensions/*', {cwd: __dirname, absolute: true}, function (err, results) {
22+
if (err) return cb(err)
23+
results.forEach(function (result) {
24+
if (path.basename(result) === 'README.md') {
25+
return
26+
}
27+
var ext = require(path.join(result, '_codemap'))
28+
zenbot.use(ext)
29+
})
30+
cb(null, zenbot)
31+
})
32+
}
33+
1634
var u = 'mongodb://' + c.mongo_host + ':' + c.mongo_port + '/' + c.mongo_db
1735
require('mongodb').MongoClient.connect(u, function (err, db) {
1836
if (err) {
19-
err.code = 'CONNECT'
20-
return cb(err, zenbot)
37+
zenbot.set('zenbot:db.mongo', null)
38+
console.error('warning: mongodb not accessible. some features (such as backfilling/simulation) may be disabled.')
39+
return withMongo()
2140
}
2241
zenbot.set('zenbot:db.mongo', db)
23-
function withAuth () {
24-
var extensions = zenbot.get('zenbot:db.extensions')
25-
extensions.select(function (err, results) {
26-
if (err) {
27-
return cb(err, zenbot)
28-
}
29-
results.forEach(function (result) {
30-
var ext = require(result.path)
31-
zenbot.use(ext)
32-
})
33-
cb(null, zenbot)
34-
})
35-
}
3642
if (c.mongo_username) {
3743
db.authenticate(c.mongo_username, c.mongo_password, function (err, result) {
3844
if (err) {
39-
err.code = 'AUTH'
40-
return cb(err, zenbot)
45+
zenbot.set('zenbot:db.mongo', null)
46+
console.error('warning: mongodb auth failed. some features (such as backfilling/simulation) may be disabled.')
4147
}
42-
withAuth()
48+
withMongo()
4349
})
4450
}
4551
else {
46-
withAuth()
52+
withMongo()
4753
}
4854
})
4955
}

commands/_codemap.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ module.exports = {
22
_ns: 'zenbot',
33
_folder: 'commands',
44

5-
'list[10]': '#commands.extend',
6-
'list[20]': '#commands.list-selectors',
7-
'list[50]': '#commands.backfill',
8-
'list[60]': '#commands.sim',
9-
10-
'extend': require('./extend'),
115
'list-selectors': require('./list-selectors'),
12-
'ls': '#commands.list-selectors',
136
'backfill': require('./backfill'),
14-
'sim': require('./sim')
7+
'sim': require('./sim'),
8+
9+
'list[20]': '#commands.list-selectors',
10+
'list[50]': '#commands.backfill',
11+
'list[60]': '#commands.sim'
1512
}

commands/extend.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

commands/init.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

commands/list-selectors.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,10 @@
1-
var path = require('path')
2-
var parallel = require('run-parallel')
3-
41
module.exports = function container (get, set, clear) {
52
return function (program) {
63
program
74
.command('list-selectors')
8-
.alias('ls')
9-
.description('list available selectors to watch')
5+
.description('list available selectors')
106
.action(function (cmd) {
11-
get('db.selectors').select(function (err, watching) {
12-
if (err) throw err
13-
var watch_list = watching.map(function (watched_selector) {
14-
return watched_selector.id
15-
})
16-
get('lib.list-selectors')(function (err, selectors) {
17-
if (err) throw err
18-
console.log()
19-
selectors.forEach(function (selector) {
20-
console.log(' ' + selector + (watch_list.indexOf(selector) !== -1 ? ' (watching)' : ''))
21-
})
22-
console.log()
23-
process.exit(0)
24-
})
25-
})
7+
268
})
279
}
2810
}

commands/list-strategies.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = function container (get, set, clear) {
2+
return function (program) {
3+
program
4+
.command('list-strategies')
5+
.description('list available strategies')
6+
.action(function (cmd) {
7+
8+
})
9+
}
10+
}

commands/sim.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = function container (get, set, clear) {
2222
.option('--start_capital <amount>', 'amount of start capital in currency', Number, 1000, c.start_capital)
2323
.option('--markup_pct <pct>', '% to raise price above market for sell orders', Number, c.markup_pct)
2424
.option('--markdown_pct <pct>', '% to lower price below market for buy orders', Number, c.markdown_pct)
25-
.option('--bid_adjust_time <ms>', 'adjust bid/ask on this interval to keep orders competitive', Number, c.bid_adjust_time)
25+
.option('--order_adjust_time <ms>', 'adjust bid/ask on this interval to keep orders competitive', Number, c.order_adjust_time)
2626
.option('--max_sell_loss_pct <pct>', 'avoid selling at a loss pct under this float', c.max_sell_loss_pct)
2727
.action(function (selector, cmd) {
2828
selector = get('lib.normalize-selector')(selector)
@@ -241,8 +241,8 @@ module.exports = function container (get, set, clear) {
241241

242242
function adjustBid (trade) {
243243
var price
244-
if (s.options.bid_adjust_time && trade.price > 100) {
245-
if (s.buy_order && trade.time - s.buy_order.time >= s.options.bid_adjust_time) {
244+
if (s.options.order_adjust_time && trade.price > 100) {
245+
if (s.buy_order && trade.time - s.buy_order.time >= s.options.order_adjust_time) {
246246
price = trade.price - (trade.price * (s.options.markdown_pct / 100))
247247
s.buy_order = {
248248
size: s.buy_order.size,
@@ -251,7 +251,7 @@ module.exports = function container (get, set, clear) {
251251
time: trade.time
252252
}
253253
}
254-
else if (s.sell_order && trade.time - s.sell_order.time >= s.options.bid_adjust_time) {
254+
else if (s.sell_order && trade.time - s.sell_order.time >= s.options.order_adjust_time) {
255255
price = trade.price + (trade.price * (s.options.markup_pct / 100))
256256
var sell_loss = s.last_buy_price ? ((price / s.last_buy_price) * 100) - 100 : null
257257
if (sell_loss !== null && sell_loss < s.options.max_sell_loss_pct) {

commands/watch.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)