<commit_before>var config = require('../config.js');
var util = require('../util.js');

var balances = require('../DB/InMemory/accountBalances.js');

function updateReserveAmountsByParams(accountId, amount, price, orderType){
  if(orderType == 'ask'){
    balances.AddToReservedCurrency1(accountId, amount);
  } else if(orderType == 'cancelask'){
    balances.RemoveFromReservedCurrency1(accountId, amount);
  } else if(orderType == 'matchedask'){
    balances.RemoveFromReservedCurrency1(accountId, amount);
  }  else if(orderType == 'bid'){
    var bidAmount = amount * price;
    balances.AddToReservedCurrency2(accountId, bidAmount);
  } else if(orderType == 'cancelbid'){
    var bidAmount = amount * price;
    balances.RemoveFromReservedCurrency2(accountId, bidAmount);
  } else if(orderType == 'matchedbid'){
    var bidAmount = amount * price;
    balances.RemoveFromReservedCurrency2(accountId, bidAmount);
  } 
}

function updateReserveAmounts(order){
  updateReserveAmountsByParams(order.accountId, order.amount, order.price, order.type);
}

function updateAccountBalances(match){
  var currency1Amount = match.amount;
  var price = match.order1.price;
  var currency2Amount = price * currency1Amount;
  if(match.order1.type == 'ask'){
    var account1 = balances.AccountList[match.order1.accountId];
    account1.currency1 -= currency1Amount;
    account1.currency1 = util.Round(account1.currency1, config.currency1.constant);
    account1.currency2 += currency2Amount;
    account1.currency2 = util.Round(account1.currency2, config.currency2.constant);
    updateReserveAmountsByParams(account1.id, currency1Amount, price, 'matchedask');

    var account2 = balances.AccountList[match.order2.accountId];
    account2.currency1 += currency1Amount;
    account2.currency1 = util.Round(account2.currency1, config.currency1.constant);
    account2.currency2 -= currency2Amount;
    account2.currency2 = util.Round(account2.currency2, config.currency2.constant);
    updateReserveAmountsByParams(account2.id, currency1Amount, price, 'matchedbid');
  } else if(match.order1.type == 'bid') { 
    var account1 = balances.AccountList[match.order1.accountId];
    account1.currency1 += currency1Amount;
    account1.currency1 = util.Round(account1.currency1, config.currency1.constant);
    account1.currency2 -= currency2Amount;
    account1.currency2 = util.Round(account1.currency2, config.currency2.constant);
    updateReserveAmountsByParams(account1.id, currency1Amount, price, 'matchedbid');

    var account2 = balances.AccountList[match.order2.accountId];
    account2.currency1 -= currency1Amount;
    account2.currency1 = util.Round(account2.currency1, config.currency1.constant);
    account2.currency2 += currency2Amount;
    account2.currency2 = util.Round(account2.currency2, config.currency2.constant);
    updateReserveAmountsByParams(account2.id, currency1Amount, price, 'matchedask');
  } 
}

function auditTotals(){
  /*var totalCurrency1 = 0;
  var totalCurrency2 = 0;
  for(var i=accountList.length; i--;){
    totalCurrency1 += accountList[i].currency1;
    totalCurrency1 = util.Round(totalCurrency1, config.currency1.constant);
    totalCurrency2 += accountList[i].currency2; 
    totalCurrency2 = util.Round(totalCurrency2, config.currency2.constant);
  }  

  var totalDeposited1 = accountBalance*accountList.length;
  var totalDeposited2 = accountBalance*accountList.length;
  var diffCurrency1 = Math.abs(totalCurrency1 - totalDeposited1);
  var diffCurrency2 = Math.abs(totalCurrency2 - totalDeposited2);

  
  if(Number(diffCurrency1) > 0 || Number(diffCurrency2) > 0){
    console.log('ERROR: Audited totals: '+'\nBTC: '+totalCurrency1+'\nUSD: '+totalCurrency2);
  }<commit_msg>Changed all references to accountList to balances.AccountList<commit_after>var config = require('../config.js');
var util = require('../util.js');

var balances = require('../DB/InMemory/accountBalances.js');

function updateReserveAmountsByParams(accountId, amount, price, orderType){
  if(orderType == 'ask'){
    balances.AddToReservedCurrency1(accountId, amount);
  } else if(orderType == 'cancelask'){
    balances.RemoveFromReservedCurrency1(accountId, amount);
  } else if(orderType == 'matchedask'){
    balances.RemoveFromReservedCurrency1(accountId, amount);
  }  else if(orderType == 'bid'){
    var bidAmount = amount * price;
    balances.AddToReservedCurrency2(accountId, bidAmount);
  } else if(orderType == 'cancelbid'){
    var bidAmount = amount * price;
    balances.RemoveFromReservedCurrency2(accountId, bidAmount);
  } else if(orderType == 'matchedbid'){
    var bidAmount = amount * price;
    balances.RemoveFromReservedCurrency2(accountId, bidAmount);
  } 
}

function updateReserveAmounts(order){
  updateReserveAmountsByParams(order.accountId, order.amount, order.price, order.type);
}

function updateAccountBalances(match){
  var currency1Amount = match.amount;
  var price = match.order1.price;
  var currency2Amount = price * currency1Amount;
  if(match.order1.type == 'ask'){
    var account1 = balances.AccountList[match.order1.accountId];
    account1.currency1 -= currency1Amount;
    account1.currency1 = util.Round(account1.currency1, config.currency1.constant);
    account1.currency2 += currency2Amount;
    account1.currency2 = util.Round(account1.currency2, config.currency2.constant);
    updateReserveAmountsByParams(account1.id, currency1Amount, price, 'matchedask');

    var account2 = balances.AccountList[match.order2.accountId];
    account2.currency1 += currency1Amount;
    account2.currency1 = util.Round(account2.currency1, config.currency1.constant);
    account2.currency2 -= currency2Amount;
    account2.currency2 = util.Round(account2.currency2, config.currency2.constant);
    updateReserveAmountsByParams(account2.id, currency1Amount, price, 'matchedbid');
  } else if(match.order1.type == 'bid') { 
    var account1 = balances.AccountList[match.order1.accountId];
    account1.currency1 += currency1Amount;
    account1.currency1 = util.Round(account1.currency1, config.currency1.constant);
    account1.currency2 -= currency2Amount;
    account1.currency2 = util.Round(account1.currency2, config.currency2.constant);
    updateReserveAmountsByParams(account1.id, currency1Amount, price, 'matchedbid');

    var account2 = balances.AccountList[match.order2.accountId];
    account2.currency1 -= currency1Amount;
    account2.currency1 = util.Round(account2.currency1, config.currency1.constant);
    account2.currency2 += currency2Amount;
    account2.currency2 = util.Round(account2.currency2, config.currency2.constant);
    updateReserveAmountsByParams(account2.id, currency1Amount, price, 'matchedask');
  } 
}

function auditTotals(){
  /*var totalCurrency1 = 0;
  var totalCurrency2 = 0;
  for(var i=balances.AccountList.length; i--;){
    totalCurrency1 += balances.AccountList[i].currency1;
    totalCurrency1 = util.Round(totalCurrency1, config.currency1.constant);
    totalCurrency2 += balances.AccountList[i].currency2; 
    totalCurrency2 = util.Round(totalCurrency2, config.currency2.constant);
  }  

  var totalDeposited1 = accountBalance*balances.AccountList.length;
  var totalDeposited2 = accountBalance*balances.AccountList.length;
  var diffCurrency1 = Math.abs(totalCurrency1 - totalDeposited1);
  var diffCurrency2 = Math.abs(totalCurrency2 - totalDeposited2);

  
  if(Number(diffCurrency1) > 0 || Number(diffCurrency2) > 0){
    console.log('ERROR: Audited totals: '+'\nBTC: '+totalCurrency1+'\nUSD: '+totalCurrency2);
  }
{'fraction_non_alphanumeric': 0.1209623820284461, 'fraction_numerical': 0.03190216668882095, 'mean_word_length': 5.213047068538398, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1979444', 'n_tokens_mistral': 2343, 'n_tokens_neox': 2346, 'n_words': 388}