<commit_before>/*

  The portfolio manager is responsible for making sure that
  all decisions are turned into orders and make sure these orders
  get executed. Besides the orders the manager also keeps track of
  the client's portfolio.

*/

var _ = require('lodash');
var EventEmitter = require('events').EventEmitter;
var Util = require("util");
var util = require('./util')
var events = require("events");
var log = require('./log');
var async = require('async');
var exchangeChecker = require('./exchangeChecker.js');

var Manager = function(conf) {
  this.exchangeSlug = conf.exchange.toLowerCase();

  // create an exchange
  var Exchange = require('./exchanges/' + this.exchangeSlug);
  this.exchange = new Exchange(conf);

  //    state
  this.conf = conf;
  this.portfolio = {};
  this.fee;
  this.order;
  this.action;

  this.directExchange = conf.direct;
  this.infinityOrderExchange = conf.infinityOrder;

  this.currency = conf.currency || 'USD';
  this.asset = conf.asset || 'BTC';

  _.bindAll(this);

  log.debug('getting balance & fee from', this.exchange.name);
  var prepare = function() {
    this.starting = false;

    log.info('trading at', this.exchange.name, 'ACTIVE');
    log.info(this.exchange.name, 'trading fee will be:', this.fee * 100 + '%');
    log.info('current', this.exchange.name, 'portfolio:');
    _.each(this.portfolio, function(fund) {
      log.info('\t', fund.name + ':', fund.amount);
    });
    this.emit('ready');
  };

  async.series([
    this.setPortfolio,
    this.setFee
  ], _.bind(prepare, this));

  // Because on cex.io your asset grows refresh and
  // display portfolio stats every 11 minutes
  if(this.exchange.name === 'cex.io')
    setInterval(this.displayPortfolio, util.minToMs( 11 ));
}

// teach our Manager events
Util.inherits(Manager, events.EventEmitter);

Manager.prototype.setPortfolio = function(callback) {
  var set = function(err, portfolio) {
    this.portfolio = portfolio;<commit_msg>removed code duplication<commit_after>/*

  The portfolio manager is responsible for making sure that
  all decisions are turned into orders and make sure these orders
  get executed. Besides the orders the manager also keeps track of
  the client's portfolio.

*/

var _ = require('lodash');
var EventEmitter = require('events').EventEmitter;
var Util = require("util");
var util = require('./util')
var events = require("events");
var log = require('./log');
var async = require('async');
var exchangeChecker = require('./exchangeChecker.js');

var Manager = function(conf) {
  this.exchangeSlug = conf.exchange.toLowerCase();

  // create an exchange
  var Exchange = require('./exchanges/' + this.exchangeSlug);
  this.exchange = new Exchange(conf);

  //    state
  this.conf = conf;
  this.portfolio = {};
  this.fee;
  this.order;
  this.action;

  this.directExchange = conf.direct;
  this.infinityOrderExchange = conf.infinityOrder;

  this.currency = conf.currency || 'USD';
  this.asset = conf.asset || 'BTC';

  _.bindAll(this);

  log.debug('getting balance & fee from', this.exchange.name);
  var prepare = function() {
    this.starting = false;

    log.info('trading at', this.exchange.name, 'ACTIVE');
    log.info(this.exchange.name, 'trading fee will be:', this.fee * 100 + '%');
    this.logPortfolio();
    this.emit('ready');
  };

  async.series([
    this.setPortfolio,
    this.setFee
  ], _.bind(prepare, this));

  // Because on cex.io your asset grows refresh and
  // display portfolio stats every 11 minutes
  if(this.exchange.name === 'cex.io')
    setInterval(this.displayPortfolio, util.minToMs( 11 ));
}

// teach our Manager events
Util.inherits(Manager, events.EventEmitter);

Manager.prototype.setPortfolio = function(callback) {
  var set = function(err, portfolio) {
    this.portfolio = portfolio;
{'fraction_non_alphanumeric': 0.14357086510649486, 'fraction_numerical': 0.0036813042334998686, 'mean_word_length': 3.778894472361809, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4359373', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1134, 'n_words': 312}