bluebot
Version:
A bitcoin trading bot for auto trading at various exchanges
90 lines (67 loc) • 1.85 kB
JavaScript
// Sonic is the realtime market for BlueBot!
//
//
var _ = require('lodash');
var async = require('async');
var util = require(__dirname + '/../util');
var dirs = util.dirs();
var Heart = require(dirs.sonic + 'heart');
var MarketDataProvider = require(dirs.sonic + 'marketDataProvider');
var CandleManager = require(dirs.sonic + 'candleManager');
var Sonic = function(config) {
_.bindAll(this);
Readable.call(this, {objectMode: true});
// Sonic internal modules:
this.heart = new Heart;
this.marketDataProvider = new MarketDataProvider(config);
this.candleManager = new CandleManager;
// Sonic data flow:
// on every `tick` retrieve trade data
this.heart.on(
'tick',
this.marketDataProvider.retrieve
);
// on new trade data create candles
this.marketDataProvider.on(
'trades',
this.candleManager.processTrades
);
// Output the candles
this.candleManager.on(
'candles',
this.pushCandles
);
this.heart.pump();
// Sonic also reports:
// Trades & last trade
//
// this.marketDataProvider.on(
// 'trades',
// this.broadcast('trades')
// );
// this.marketDataProvider.on(
// 'trades',
// this.broadcastTrade
// );
}
var Readable = require('stream').Readable;
Sonic.prototype = Object.create(Readable.prototype, {
constructor: { value: Sonic }
});
Sonic.prototype._read = function noop() {}
Sonic.prototype.pushCandles = function(candles) {
_.each(candles, this.push);
}
// Sonic.prototype.broadcastTrade = function(trades) {
// _.defer(function() {
// this.emit('trade', trades.last);
// }.bind(this));
// }
// Sonic.prototype.broadcast = function(message) {
// return function(payload) {
// _.defer(function() {
// this.emit(message, payload);
// }.bind(this));
// }.bind(this);
// }
module.exports = Sonic;