Skip to content

Commit

Permalink
Fix duplicate forex quotes (^EURUSD and ^USDEUR). Eliminate duplicate…
Browse files Browse the repository at this point in the history
… refreshes (in some cases)
  • Loading branch information
bryaningl3 committed Nov 22, 2023
1 parent 3484655 commit ec94efe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .releases/1.27.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**Bug Fixes**

* Corrected failure to translate currencies by preventing two `Rate` objects, which represent same currency pair, from existing in the `PositionContainer` (e.g. ^EURUSD and ^USDEUR).
* Eliminated multiple unnecessary calls to the `PositionGroup.setForexRates` function.
* Eliminated multiple unnecessary calls to the `PositionContainer.refresh` function.
17 changes: 12 additions & 5 deletions lib/processing/PositionContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,21 +583,28 @@ module.exports = (() => {

if (symbol) {
const rate = Rate.fromPair(quote.lastPrice, symbol);
const index = this._forexQuotes.findIndex(existing => existing.formatPair() === rate.formatPair());

let index = this._forexQuotes.findIndex(existing => existing.formatPair() === rate.formatPair());

if (index < 0) {
const inverted = rate.invert();

index = this._forexQuotes.findIndex(existing => existing.formatPair() === inverted.formatPair());
}

if (index < 0) {
this._forexQuotes.push(rate);
} else {
this._forexQuotes[index] = rate;
}

Object.keys(this._trees).forEach((key) => {
this._trees[key].walk(group => group.setForexRates(this._forexQuotes), true, false);
});

recalculatePercentages.call(this);
}
});

Object.keys(this._trees).forEach((key) => {
this._trees[key].walk(group => group.setForexRates(this._forexQuotes), true, false);
});
}

if (positionQuotes.length !== 0 || forexQuotes.length !== 0) {
Expand Down

0 comments on commit ec94efe

Please sign in to comment.