<commit_before>var WebsocketClient = require('./clients/websocket.js');
var PublicClient = require('./clients/public.js');
var Orderbook = require('./orderbook.js');
var util = require('util');
var _ = {
  forEach: require('lodash.foreach'),
  assign: require('lodash.assign'),
};

// Orderbook syncing
var OrderbookSync = function(productID) {
  var self = this;

  self.productID = productID || 'BTC-USD';

  self._queue = [];
  self._sequence = -1;

  WebsocketClient.call(self, self.productID);
  self.loadOrderbook();
};

util.inherits(OrderbookSync, WebsocketClient);

_.assign(OrderbookSync.prototype, new function() {
  var prototype = this;

  prototype.onMessage = function(data) {
    var self = this;
    data = JSON.parse(data);

    if (self._sequence ===  -1) {
      // Orderbook snapshot not loaded yet
      self._queue.push(data);
    } else {
      self.processMessage(data);
    }
  };

  prototype.loadOrderbook = function() {
    var self = this;
    var bookLevel = 3;

    self.book = new Orderbook();

    if (!self.publicClient) {
      self.publicClient = new PublicClient();
    }

    var args = { 'level': bookLevel };
    self.publicClient.getProductOrderBook(args, function(err, response, body) {

      if (err) {<commit_msg>Fix orderbook_sync init when using productId != BTC-USD<commit_after>var WebsocketClient = require('./clients/websocket.js');
var PublicClient = require('./clients/public.js');
var Orderbook = require('./orderbook.js');
var util = require('util');
var _ = {
  forEach: require('lodash.foreach'),
  assign: require('lodash.assign'),
};

// Orderbook syncing
var OrderbookSync = function(productID) {
  var self = this;

  self.productID = productID || 'BTC-USD';

  self._queue = [];
  self._sequence = -1;

  WebsocketClient.call(self, self.productID);
  self.loadOrderbook();
};

util.inherits(OrderbookSync, WebsocketClient);

_.assign(OrderbookSync.prototype, new function() {
  var prototype = this;

  prototype.onMessage = function(data) {
    var self = this;
    data = JSON.parse(data);

    if (self._sequence ===  -1) {
      // Orderbook snapshot not loaded yet
      self._queue.push(data);
    } else {
      self.processMessage(data);
    }
  };

  prototype.loadOrderbook = function() {
    var self = this;
    var bookLevel = 3;

    self.book = new Orderbook();

    if (!self.publicClient) {
      self.publicClient = new PublicClient(self.productID);
    }

    var args = { 'level': bookLevel };
    self.publicClient.getProductOrderBook(args, function(err, response, body) {

      if (err) {
{'fraction_non_alphanumeric': 0.14685314685314685, 'fraction_numerical': 0.002331002331002331, 'mean_word_length': 3.424398625429553, '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': '7110808', 'n_tokens_mistral': 837, 'n_tokens_neox': 802, 'n_words': 178}