Skip to content

Commit

Permalink
refactor: Mark overridden functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Aug 28, 2021
1 parent c85cd15 commit ad94144
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/AC/AC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ export class AC extends SimpleIndicator {
this.momentum = new MOM(1);
}

get isStable(): boolean {
override get isStable(): boolean {
return this.result !== undefined;
}

getResult(): Big {
override getResult(): Big {
if (!this.result) {
throw new NotEnoughDataError();
}

return this.result;
}

update(low: BigSource, high: BigSource): void | Big {
override update(low: BigSource, high: BigSource): void | Big {
const ao = this.ao.update(low, high);
if (ao) {
this.signal.update(ao);
Expand Down
6 changes: 3 additions & 3 deletions src/AO/AO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ export class AO extends SimpleIndicator {
this.long = new SMA(longInterval);
}

get isStable(): boolean {
override get isStable(): boolean {
return this.result !== undefined;
}

getResult(): Big {
override getResult(): Big {
if (!this.result) {
throw new NotEnoughDataError();
}

return this.result;
}

update(low: BigSource, high: BigSource): void | Big {
override update(low: BigSource, high: BigSource): void | Big {
const candleSum = new Big(low).add(high);
const medianPrice = candleSum.div(2);

Expand Down
6 changes: 3 additions & 3 deletions src/ATR/ATR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class ATR extends SimpleIndicator {
this.smma = new SMMA(interval);
}

get isStable(): boolean {
override get isStable(): boolean {
return this.candles.length > this.interval;
}

update(candle: ATRCandle): void {
override update(candle: ATRCandle): void {
this.candles.push(candle);

if (!this.prevCandle) {
Expand All @@ -49,7 +49,7 @@ export class ATR extends SimpleIndicator {
this.prevCandle = candle;
}

getResult(): Big {
override getResult(): Big {
if (!this.result) {
throw new NotEnoughDataError();
}
Expand Down
6 changes: 3 additions & 3 deletions src/CG/CG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CG extends SimpleIndicator {

public readonly prices: Big[] = [];

get isStable(): boolean {
override get isStable(): boolean {
return this.prices.length >= this.interval && this.signal.isStable;
}

Expand All @@ -27,7 +27,7 @@ export class CG extends SimpleIndicator {
this.signal = new SMA(signalInterval);
}

update(price: BigSource): void {
override update(price: BigSource): void {
this.prices.push(new Big(price));

if (this.prices.length > this.interval) {
Expand All @@ -50,7 +50,7 @@ export class CG extends SimpleIndicator {
this.setResult(cg);
}

getResult(): Big {
override getResult(): Big {
if (!this.isStable || !this.result) {
throw new NotEnoughDataError();
}
Expand Down
6 changes: 3 additions & 3 deletions src/DEMA/DEMA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export class DEMA extends SimpleIndicator {
this.outer = new EMA(interval);
}

update(price: BigSource): void {
override update(price: BigSource): void {
this.inner.update(price);
this.outer.update(this.inner.getResult());
this.setResult(this.inner.getResult().times(2).sub(this.outer.getResult()));
}

get isStable(): boolean {
override get isStable(): boolean {
try {
this.inner.getResult();
this.outer.getResult();
Expand All @@ -28,7 +28,7 @@ export class DEMA extends SimpleIndicator {
}
}

getResult(): Big {
override getResult(): Big {
if (!this.result) {
throw new NotEnoughDataError();
}
Expand Down
4 changes: 2 additions & 2 deletions src/EMA/EMA.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('EMA', () => {
ema.update(new Big(price));
const actual = ema.getResult();
const expected = new Big(ema10results[index]);
expect(actual!.toPrecision(12)).toEqual(expected.toPrecision(12));
expect(actual.toPrecision(12)).toEqual(expected.toPrecision(12));
});

expect(ema.lowest!.toFixed(2)).toBe('38.20');
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('EMA', () => {
ema.update(new Big(price));
const actual = ema.getResult();
const expected = new Big(ema26results[index]);
expect(actual!.toPrecision(12)).toEqual(expected.toPrecision(12));
expect(actual.toPrecision(12)).toEqual(expected.toPrecision(12));
});

expect(ema.lowest!.toFixed(2)).toBe('48.29');
Expand Down
2 changes: 1 addition & 1 deletion src/EMA/EMA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Big, {BigSource} from 'big.js';
import {MovingAverage} from '../MA/MovingAverage';

export class EMA extends MovingAverage {
update(_price: BigSource): void {
override update(_price: BigSource): void {
const price = new Big(_price);

// If it's the first update there is no previous result and a default has to be set.
Expand Down
4 changes: 2 additions & 2 deletions src/MA/MovingAverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export abstract class MovingAverage extends SimpleIndicator {
super();
}

get isStable(): boolean {
override get isStable(): boolean {
return !!this.result;
}

getResult(): Big {
override getResult(): Big {
if (!this.result) {
throw new NotEnoughDataError();
}
Expand Down
6 changes: 3 additions & 3 deletions src/MOM/MOM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ export class MOM extends SimpleIndicator {
this.history = getFixedArray<BigSource>(this.historyLength);
}

update(value: BigSource): void {
override update(value: BigSource): void {
this.history.push(value);
if (this.history.length === this.historyLength) {
this.setResult(new Big(value).minus(this.history[0]));
}
}

get isStable(): boolean {
override get isStable(): boolean {
return this.result !== undefined;
}

getResult(): Big {
override getResult(): Big {
if (!this.result) {
throw new NotEnoughDataError();
}
Expand Down
6 changes: 3 additions & 3 deletions src/ROC/ROC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export class ROC extends SimpleIndicator {
this.interval = interval;
}

get isStable(): boolean {
override get isStable(): boolean {
return this.result !== undefined;
}

update(_price: BigSource): void {
override update(_price: BigSource): void {
const price = new Big(_price);

this.priceHistory.push(price);
Expand All @@ -35,7 +35,7 @@ export class ROC extends SimpleIndicator {
this.setResult(price.sub(comparePrice).div(comparePrice));
}

getResult(): Big {
override getResult(): Big {
if (!this.result) {
throw new NotEnoughDataError();
}
Expand Down
6 changes: 3 additions & 3 deletions src/RSI/RSI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class RSI extends SimpleIndicator {
this.avgLoss = new Indicator(this.interval);
}

update(price: BigSource): void {
override update(price: BigSource): void {
const currentClose = new Big(price);
this.prices.push(currentClose);

Expand Down Expand Up @@ -52,14 +52,14 @@ export class RSI extends SimpleIndicator {
}
}

getResult(): Big {
override getResult(): Big {
if (!this.isStable) {
throw new NotEnoughDataError();
}
return this.result!;
}

get isStable(): boolean {
override get isStable(): boolean {
if (this.result) {
return this.result.gt(0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/SMA/SMA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {MovingAverage} from '../MA/MovingAverage';
export class SMA extends MovingAverage {
public readonly prices: Big[] = [];

update(price: BigSource): void {
override update(price: BigSource): void {
this.prices.push(new Big(price));

if (this.prices.length > this.interval) {
Expand Down
4 changes: 2 additions & 2 deletions src/SMMA/SMMA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SMMA extends MovingAverage {
this.sma = new SMA(interval);
}

update(price: BigSource): void {
override update(price: BigSource): void {
this.prices.push(new Big(price));

if (this.prices.length < this.interval) {
Expand All @@ -33,7 +33,7 @@ class SMMA extends MovingAverage {
}
}

getResult(): Big {
override getResult(): Big {
return this.result || new Big(0);
}
}
Expand Down

0 comments on commit ad94144

Please sign in to comment.