-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.js
67 lines (46 loc) · 1.72 KB
/
bot.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
var moment = require("moment");
var _ = require("lodash");
var util = require ('./core/util');
var config = util.getConfig();
var log = require('./core/log');
var sleep = require('sleep');
var StrategyManager = require('./core/strategy/strategyManager');
var TradeManager = require('./core/trader/tradeManager');
var CandleWriter = require("./database/writer.js");
class Bot {
constructor(){
_.bindAll(this);
this.processCandle = this.processCandle.bind(this);
this.done = this.done.bind(this);
let exchange = require(`${util.dirs().exchanges}/bitfinex.js`);
exchange.getSymbols((err, symbols) => this.start(symbols));
}
start(symbols){
log.info(JSON.stringify(symbols, null, '\t'));
this.pairs = symbols.map(s => s.asset+s.currency);
var Market = require(util.dirs().markets + config.mode);
this.tradeManager = new TradeManager();
this.market = new Market(this.pairs);
this.market.on('processCandle', this.processCandle);
this.market.on('done', this.done);
this.strategyManager = new StrategyManager(this.pairs);
this.strategyManager.on("report", this.tradeManager.processReports);
if (config.mode == 'importer') {
this.candleWriter = new CandleWriter();
}
this.market.get();
}
processCandle(candle, next){
if (config.mode == 'importer')
this.candleWriter.addCandles(candle);
this.strategyManager.processCandle(candle, () => process.nextTick(next));
}
done(){
if (config.mode == 'importer'){
this.candleWriter.finalize();
}
this.tradeManager.done();
log.info("done");
}
}
new Bot();