Skip to content

Commit

Permalink
refactored submit deltas
Browse files Browse the repository at this point in the history
  • Loading branch information
pghalliday committed Jun 30, 2013
1 parent 9e5c407 commit ed7e4ab
Show file tree
Hide file tree
Showing 12 changed files with 1,031 additions and 933 deletions.
44 changes: 23 additions & 21 deletions lib/src/Engine/Balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,38 @@
Balance.prototype.applyOffer = function(params) {
var debit;

debit = {
amount: params.amount
};
this.lockedFunds = this.lockedFunds.subtract(params.fundsUnlocked);
this.funds = this.funds.subtract(debit.amount);
return debit;
this.funds = this.funds.subtract(params.amount);
return debit = {
amount: params.amount.toString()
};
};

Balance.prototype.applyBid = function(params) {
var credit;
var amount, commission, credit;

if (this.commissionBalance) {
credit = {
commission: this.commissionCalculate({
amount: params.amount,
timestamp: params.timestamp,
account: this.account,
currency: this.currency
})
commission = this.commissionCalculate({
amount: params.amount,
timestamp: params.timestamp,
account: this.account,
currency: this.currency
});
amount = params.amount.subtract(commission.amount);
this.funds = this.funds.add(amount);
this.commissionBalance.deposit(commission.amount);
return credit = {
amount: amount.toString(),
commission: {
amount: commission.amount.toString(),
reference: commission.reference
}
};
credit.amount = params.amount.subtract(credit.commission.amount);
this.funds = this.funds.add(credit.amount);
this.commissionBalance.deposit(credit.commission.amount);
return credit;
} else {
credit = {
amount: params.amount
this.funds = this.funds.add(params.amount);
return credit = {
amount: params.amount.toString()
};
this.funds = this.funds.add(credit.amount);
return credit;
}
};

Expand Down
68 changes: 30 additions & 38 deletions lib/src/Engine/Engine.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ed7e4ab

Please sign in to comment.