Skip to content

Commit

Permalink
add more indicators (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender authored Mar 27, 2022
1 parent b9af454 commit 6d193e1
Show file tree
Hide file tree
Showing 21 changed files with 2,259 additions and 1,369 deletions.
3,135 changes: 1,899 additions & 1,236 deletions Client/package-lock.json

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions Client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
},
"private": false,
"dependencies": {
"@angular/animations": "~13.2.5",
"@angular/cdk": "~13.2.5",
"@angular/common": "~13.2.5",
"@angular/compiler": "~13.2.5",
"@angular/core": "~13.2.5",
"@angular/forms": "~13.2.5",
"@angular/material": "~13.2.5",
"@angular/platform-browser": "~13.2.5",
"@angular/platform-browser-dynamic": "~13.2.5",
"@angular/router": "~13.2.5",
"@angular/animations": "~13.3.0",
"@angular/cdk": "~13.3.1",
"@angular/common": "~13.3.0",
"@angular/compiler": "~13.3.0",
"@angular/core": "~13.3.0",
"@angular/forms": "~13.3.0",
"@angular/material": "~13.3.1",
"@angular/platform-browser": "~13.3.0",
"@angular/platform-browser-dynamic": "~13.3.0",
"@angular/router": "~13.3.0",
"@ctrl/tinycolor": "^3.4.0",
"@fortawesome/angular-fontawesome": "^0.10.1",
"@fortawesome/fontawesome-svg-core": "^1.3.0",
"@fortawesome/free-brands-svg-icons": "^6.0.0",
"@ng-matero/extensions": "^13.0.3",
"@fortawesome/angular-fontawesome": "^0.10.2",
"@fortawesome/fontawesome-svg-core": "^6.1.1",
"@fortawesome/free-brands-svg-icons": "^6.1.1",
"@ng-matero/extensions": "^13.1.0",
"chart.js": "^3.7.1",
"chartjs-adapter-date-fns": "^2.0.0",
"chartjs-chart-financial": "^0.1.1",
"chartjs-plugin-annotation": "^1.3.1",
"chartjs-plugin-annotation": "^1.4.0",
"chartjs-plugin-crosshair": "^1.2.0",
"date-fns": "^2.28.0",
"guid-typescript": "^1.0.9",
Expand All @@ -39,20 +39,20 @@
"zone.js": "~0.11.5"
},
"devDependencies": {
"@angular-devkit/build-angular": "~13.2.5",
"@angular-devkit/build-angular": "~13.3.0",
"@angular-eslint/builder": "~13.1.0",
"@angular-eslint/eslint-plugin": "~13.1.0",
"@angular-eslint/eslint-plugin-template": "~13.1.0",
"@angular-eslint/schematics": "~13.1.0",
"@angular-eslint/template-parser": "~13.1.0",
"@angular/cli": "~13.2.5",
"@angular/compiler-cli": "~13.2.5",
"@angular/language-service": "~13.2.5",
"@types/node": "^17.0.21",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
"eslint": "^8.10.0",
"ts-node": "~10.6.0",
"@angular/cli": "~13.3.0",
"@angular/compiler-cli": "~13.3.0",
"@angular/language-service": "~13.3.0",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"eslint": "^8.12.0",
"ts-node": "~10.7.0",
"typescript": "~4.5.5"
}
}
2 changes: 1 addition & 1 deletion Client/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class AppComponent implements OnInit {

// PICKERS
openPickList(): void {
const listRef = this.list.open(PickListComponent, {
this.list.open(PickListComponent, {
minWidth: '300px',
maxHeight: '80vh'
});
Expand Down
111 changes: 81 additions & 30 deletions Client/src/app/chart/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export class ApiService {
return this.http.get(`${env.api}/indicators`, this.requestHeader());
}

getSelectionData(selection: IndicatorSelection, listing: IndicatorListing): Observable<any> {
getSelection(selection: IndicatorSelection, listing: IndicatorListing): Observable<any> {

const green = "#2E7D32";
const red = "#DD2C00";
const gray = "#9E9E9E";

const obs = new Observable((observer) => {

Expand All @@ -58,27 +62,49 @@ export class ApiService {
const config = listing.results.find(x => x.dataName == result.dataName);
const dataset = this.initializeDataset(result, config);
const data: ScatterDataPoint[] = [];
const pointColor: string[] = [];
const pointRotation: number[] = [];

// populate data
apidata.forEach(row => {

let yValue = row[result.dataName];

// apply candle offset
if (yValue && config.candleOffset !== 0) {

console.log("candle", row["candle"].high);
// apply candle pointers
if (yValue && listing.category == "candlestick-pattern") {

console.log("candle", row["signal"]);
switch (row["signal"]) {

case -100:
yValue = 1.01 * row["candle"].high;
pointColor.push(red);
pointRotation.push(180);
break;

case 100:
yValue = 0.99 * row["candle"].low;
pointColor.push(green);
pointRotation.push(0);
break;

default:
yValue = 0.99 * row["candle"].low;
pointColor.push(gray);
pointRotation.push(0);
break;
}
}

yValue = config.candleOffset > 0
? (1 + config.candleOffset/100) * row["candle"].high
: (1 + config.candleOffset/100) * row["candle"].low;
else {
pointColor.push(config.defaultColor);
pointRotation.push(0);
}

data
.push({
x: new Date(row.date).valueOf(),
y: yValue
});
data.push({
x: new Date(row.date).valueOf(),
y: yValue
});
});

// add extra bars
Expand All @@ -92,11 +118,21 @@ export class ApiService {
});
}

// custom candlestick pattern points
if (listing.category == "candlestick-pattern" && dataset.type != 'bar') {
dataset.pointRotation = pointRotation;
dataset.pointBackgroundColor = pointColor;
dataset.pointBorderColor = pointColor;
}

dataset.data = data;
result.dataset = dataset;
});

observer.next(selection.results);
// replace tokens with values
selection = this.selectionTokenReplacement(selection);

observer.next(selection);
},

error: (e: HttpErrorResponse) => {
Expand Down Expand Up @@ -163,39 +199,40 @@ export class ApiService {
};
return dotsDataset;

case 'triangle-up':
const triUpDataset: ChartDataset = {
case 'bar':
const barDataset: ChartDataset = {
label: r.label,
type: 'line',
type: 'bar',
data: [],
yAxisID: 'yAxis',
pointRadius: r.lineWidth,
pointBorderWidth: 0,
pointBorderColor: "none",
pointBackgroundColor: r.color,
pointStyle: 'triangle',
pointRotation: 0,
showLine: false,
borderWidth: 0,
borderColor: r.color,
backgroundColor: r.color,
order: r.order
};
return triUpDataset;

case 'triangle-down':
const triDnDataset: ChartDataset = {
// add stack, if specified
if (c.stack) {
barDataset.stack = c.stack;
}
return barDataset;

case 'pointer':
const ptDataset: ChartDataset = {
label: r.label,
type: 'line',
data: [],
yAxisID: 'yAxis',
pointRadius: r.lineWidth,
pointBorderWidth: 0,
pointBorderColor: "none",
pointBorderColor: r.color,
pointBackgroundColor: r.color,
pointStyle: 'triangle',
pointRotation: 180,
pointRotation: 0,
showLine: false,
order: r.order
};
return triDnDataset;
return ptDataset;
}
}

Expand All @@ -207,4 +244,18 @@ export class ApiService {

return { headers: simpleHeaders };
}

selectionTokenReplacement(selection: IndicatorSelection): IndicatorSelection {

selection.params.forEach((param, index) => {

selection.label = selection.label.replace(`[P${index + 1}]`, param.value.toString());

selection.results.forEach(r => {
r.label = r.label.replace(`[P${index + 1}]`, param.value.toString());
});
});
return selection;
}

}
1 change: 0 additions & 1 deletion Client/src/app/chart/chart.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export interface IndicatorResultConfig {
lineType: string;
stack: string,
lineWidth: number;
candleOffset: number,
defaultColor: string;
fill: ChartFill;
order: number
Expand Down
Loading

0 comments on commit 6d193e1

Please sign in to comment.