Skip to content

Commit 0ebc58e

Browse files
committed
Updated list
1 parent 9c91cc2 commit 0ebc58e

12 files changed

+311
-9
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/api/portfolio/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ router.post('/v2/sell', handler.tdSell);
2424
router.post('/v3/set-account', handler.setAccount);
2525
router.post('/v3/check-account', handler.checkAccount);
2626
router.post('/v3/delete-cred', handler.checkAccount);
27+
router.get('/instrument', handler.getInstrument);
2728

2829
module.exports = router;

server/api/portfolio/portfolio.controller.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ class PortfolioController extends BaseController {
109109
}
110110
}
111111

112+
getInstrument(request, response) {
113+
console.log('query',request.query);
114+
PortfolioService.getInstrument(request.query.cusip)
115+
.then((data) => BaseController.requestGetSuccessHandler(response, data))
116+
.catch((err) => BaseController.requestErrorHandler(response, err));
117+
}
118+
112119
midPrice(ask, bid) {
113120
return _.round(_.multiply(_.add(_.divide(_.subtract(_.divide(ask, bid), 1), 2), 1), bid), 2);
114121
}
@@ -184,7 +191,7 @@ class PortfolioController extends BaseController {
184191
.then((data) => BaseController.requestGetSuccessHandler(response, data))
185192
.catch((err) => BaseController.requestErrorHandler(response, err));
186193
}
187-
194+
188195
setCredentials(request, response) {
189196
PortfolioService.setCredentials(request.body.accountId,
190197
request.body.key,

server/api/portfolio/portfolio.router.js

+4
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@ export const deleteCredentials = (request, response) => {
8383
export const getEquityMarketHours = (request, response) => {
8484
PortfolioController.getEquityMarketHours(request, response);
8585
}
86+
87+
export const getInstrument = (request, response) => {
88+
PortfolioController.getInstrument(request, response);
89+
}

server/api/portfolio/portfolio.service.ts

+17
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,23 @@ class PortfolioService {
782782
.then(this.processTDData);
783783
}
784784

785+
getInstrument(cusip: string) {
786+
const accountId = this.getAccountId();
787+
788+
const query = `${tdaUrl}instruments/${cusip}`;
789+
const options = {
790+
uri: query,
791+
qs: {
792+
apikey: this.tdaKey[accountId]
793+
},
794+
headers: {
795+
Authorization: `Bearer ${this.access_token[accountId].token}`
796+
}
797+
};
798+
799+
return request.get(options)
800+
.then(this.processTDData);
801+
}
785802
}
786803

787804
export default new PortfolioService();

src/app/autopilot/autopilot.component.html

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<p-button icon="pi pi-times" *ngIf="display" styleClass="p-button-danger" (click)="stop()"></p-button>
2020
<p-button icon="pi pi-fw pi-money-bill" styleClass="p-button-success" (click)="runFindPattern()"></p-button>
2121
<p-button *ngIf="!display" styleClass="p-button-success" label="Next strategy" (click)="changeStrategy()"></p-button>
22+
<p-button styleClass="p-button-success" label="test" (click)="test()"></p-button>
2223
</div>
2324
</p-toolbar>
2425

src/app/autopilot/autopilot.component.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,12 @@ export class AutopilotComponent implements OnInit, OnDestroy {
11831183
});
11841184
}
11851185

1186+
test() {
1187+
this.portfolioService.getInstrument('NVDA').subscribe((response) => {
1188+
console.log('test123', response);
1189+
});
1190+
}
1191+
11861192
unsubscribeStockFinder() {
11871193
this.unsubscribe$.next();
11881194
this.unsubscribe$.complete();

src/app/login/login.component.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
<div class="p-inputgroup">
1717
<textarea pInputTextarea placeholder="Refresh Token" formControlName="refreshToken" name="refreshToken"
1818
required></textarea>
19-
19+
</div>
20+
<div class="p-inputgroup">
21+
<p-checkbox formControlName="saveToCookie" label="Save to Cookie" [binary]="true"></p-checkbox>
2022
</div>
2123
</div>
2224
<div>
25+
2326
<div *ngIf="loading">
2427
<p-progressSpinner styleClass="w-4rem h-4rem" strokeWidth="8" fill="var(--surface-ground)"
2528
animationDuration="1s"></p-progressSpinner>

src/app/login/login.component.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ export class LoginComponent implements OnInit {
2727

2828
ngOnInit() {
2929
this.tdaForm = new FormGroup({
30-
accountId: new FormControl('', Validators.required),
30+
accountId: new FormControl(document.cookie
31+
.split('; ')
32+
.find((row) => row.startsWith('accountId')) || '', Validators.required),
3133
consumerKey: new FormControl('', Validators.required),
32-
refreshToken: new FormControl('', Validators.required)
34+
refreshToken: new FormControl('', Validators.required),
35+
saveToCookie: new FormControl(false, Validators.required),
3336
});
3437

3538
this.selectedLogin = 'tda';
@@ -71,6 +74,9 @@ export class LoginComponent implements OnInit {
7174
this.tdaForm.reset();
7275
this.credentialSet.emit(true);
7376
this.snackBar.open('Credentials saved.', 'Dismiss', { duration: 2000 });
77+
if (this.tdaForm.value.saveToCookie) {
78+
document.cookie = `accountId=${this.tdaForm.value.accountId}; consumerKey=${this.tdaForm.value.consumerKey}; refreshToken=${this.tdaForm.value.refreshToken}; SameSite=None; Secure`;
79+
}
7480
},
7581
error => {
7682
console.log(error);

src/app/overview/overview.module.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import { OverviewComponent } from './overview.component';
55
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
66
import { SharedModule } from '../shared/shared.module';
77
import { LoginComponent } from '../login/login.component';
8+
import { CheckboxModule } from 'primeng/checkbox';
89

910
@NgModule({
1011
declarations: [TodoListComponent, OverviewComponent, LoginComponent],
1112
imports: [
1213
CommonModule,
1314
FormsModule,
1415
ReactiveFormsModule,
15-
SharedModule
16+
SharedModule,
17+
CheckboxModule
1618
],
1719
exports: [TodoListComponent, LoginComponent]
1820
})

0 commit comments

Comments
 (0)