Skip to content

Commit e42420d

Browse files
committed
account summary, order cancel support
1 parent 028a9d3 commit e42420d

File tree

5 files changed

+82
-27
lines changed

5 files changed

+82
-27
lines changed

src/components/card.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ class Card extends Component {
2929
<div className="row no-gutters align-items-center">
3030
<div className="col mr-2">
3131
<div className="text-xs font-weight-bold text-primary text-uppercase mb-1">
32-
{this.state.header}
32+
{this.props.header}
3333
</div>
3434
<div className="h5 mb-0 font-weight-bold text-gray-800">
35-
{this.props.result}
35+
{this.props.result === undefined
36+
? ""
37+
: this.props.result.toLocaleString()}
3638
</div>
3739
</div>
3840
</div>

src/components/createOrder.jsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import React, { Component } from "react";
22
import InstBlotter from "./instBlotter";
33
import AppConfig from "../utils/constants";
44

5+
var _ = require("lodash");
6+
57
class OrderComponent extends Component {
68
state = {
79
accountId: 1,
810
favTickers: ["AAPL", "MSFT"],
911
customTicker: "",
1012
prices: [],
1113
lastOrder: {},
14+
bookingErrors: {},
1215
tradeDate: "",
1316
buySell: "B",
1417
ticker: "",
@@ -37,7 +40,7 @@ class OrderComponent extends Component {
3740
};
3841
console.log("input order to be sent: ", inputOrder);
3942
/* Post Order to server */
40-
fetch(baseUrl + "/orders/create", {
43+
fetch(baseUrl + "/orders/new", {
4144
method: "POST",
4245
mode: "cors",
4346
cache: "no-cache",
@@ -48,7 +51,13 @@ class OrderComponent extends Component {
4851
body: JSON.stringify(inputOrder),
4952
})
5053
.then((resp) => resp.json())
51-
.then((data) => this.setState({ lastOrder: data || {} }));
54+
.then((result) => {
55+
if (result.success) {
56+
this.setState({ bookingErrors: {}, lastOrder: result.data || {} });
57+
} else {
58+
this.setState({ bookingErrors: result.errors, lastOrder: {} });
59+
}
60+
});
5261
return;
5362
};
5463

@@ -86,6 +95,19 @@ class OrderComponent extends Component {
8695
};
8796

8897
render() {
98+
var footer = "";
99+
const { bookingErrors } = this.state;
100+
if (!_.isEmpty(bookingErrors)) {
101+
const notes = Object.keys(bookingErrors).map((k) => (
102+
<li>
103+
{k} : {bookingErrors[k]}
104+
</li>
105+
));
106+
footer = <ul>{notes}</ul>;
107+
} else if (this.state.lastOrder) {
108+
footer = <h4>Order created with Id= {this.state.lastOrder.orderId}</h4>;
109+
}
110+
89111
return (
90112
<div className="card o-hidden border-0 shadow-lg my-2">
91113
<div className="card-body">
@@ -172,9 +194,7 @@ class OrderComponent extends Component {
172194
</div>
173195
</div>
174196
</div>
175-
<div>
176-
<h4>Order created with Id= {this.state.lastOrder.orderId}</h4>
177-
</div>
197+
<div>{footer}</div>
178198
</div>
179199
</div>
180200
);

src/components/dashboard.jsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import AppConfig from "../utils/constants";
77
class Dashboard extends Component {
88
state = {
99
accountId: 1,
10+
accountSummary: {},
1011
results: {
1112
daily: 0,
1213
mtd: 0,
@@ -17,7 +18,7 @@ class Dashboard extends Component {
1718

1819
constructor(props) {
1920
super(props);
20-
this.reloadTradeCount();
21+
this.reloadSummary();
2122
}
2223

2324
tradeChanged = (e) => {
@@ -33,9 +34,22 @@ class Dashboard extends Component {
3334
mode: "cors",
3435
})
3536
.then((resp) => resp.json())
36-
.then((data) =>
37-
this.setState({ results: { ...results, orderCount: data.result } })
38-
);
37+
.then((result) => {
38+
if (result.success)
39+
this.setState({ results: { ...results, orderCount: result.data } });
40+
});
41+
};
42+
43+
reloadSummary = () => {
44+
fetch(AppConfig.serverUrl + "/acctsummary/" + this.state.accountId, {
45+
mode: "cors",
46+
})
47+
.then((resp) => resp.json())
48+
.then((result) => {
49+
if (result.success) {
50+
this.setState({ accountSummary: result.data });
51+
}
52+
});
3953
};
4054

4155
render() {
@@ -45,9 +59,12 @@ class Dashboard extends Component {
4559
<h1 className="h3 mb-0 text-primary">Dashboard</h1>
4660
</div>
4761

48-
<DashboardSummary results={this.state.results} />
62+
<DashboardSummary
63+
results={this.state.results}
64+
summary={this.state.accountSummary}
65+
/>
4966
<div className="row">
50-
<PositionBlotter reloadTradeCount={this.reloadTradeCount} />
67+
<PositionBlotter reloadTradeCount={this.reloadSummary} />
5168
<InstBlotteer />
5269
</div>
5370
</div>

src/components/dashboardSummary.jsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,31 @@ class DashboardSummary extends Component {
1616
<React.Fragment>
1717
<div className="row">
1818
<Card
19-
header="Monthly Earning"
19+
header="Account Balance"
2020
url="/acctsummary"
2121
id="mtd"
22-
result={this.props.results["mtd"]}
23-
/>
24-
<Card
25-
header="Daily P/L"
26-
url="/acctsummary"
27-
id="daily"
28-
result={this.props.results["daily"]}
22+
result={this.props.summary.accountBalance}
2923
/>
24+
3025
<Card
3126
header="Order Count"
3227
url="/orders/count/1"
3328
id="orderCount"
34-
result={this.props.results["orderCount"]}
29+
result={this.props.summary.orderCount}
3530
/>
31+
32+
<Card
33+
header="Daily P/L"
34+
url="/acctsummary"
35+
id="daily"
36+
result={this.props.summary.dailyPL}
37+
/>
38+
3639
<Card
37-
header="Some Other"
40+
header="MTD P/L"
3841
url="/acctsummary"
3942
id="test"
40-
result={this.props.results["test"]}
43+
result={this.props.summary.mtdPL}
4144
/>
4245
</div>
4346
</React.Fragment>

src/components/positionBlotter.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ class PositionBlotter extends Component {
3030
<td>{order.quantity}</td>
3131
<td>{order.price}</td>
3232
<td>{order.marketValue}</td>
33-
<td>{order.tradeDate}</td>
33+
<td>{order.buySellFlag}</td>
3434
<td>{order.executedTime}</td>
35+
<td>{order.status}</td>
3536
</tr>
3637
);
3738
});
@@ -47,7 +48,18 @@ class PositionBlotter extends Component {
4748
if (msg.orderId) {
4849
//check if valid message
4950
const { orders } = this.state;
50-
this.setState({ orders: [msg, ...orders] });
51+
const orderId = msg.orderId;
52+
if ("OPEN" === msg.status) {
53+
//new trade
54+
this.setState({ orders: [msg, ...orders] });
55+
} else {
56+
//Edited trade
57+
const newOrders = orders.map((order) =>
58+
order.orderId === orderId ? msg : order
59+
);
60+
this.setState({ orders: newOrders });
61+
}
62+
5163
this.props.reloadTradeCount();
5264
}
5365
}}
@@ -107,8 +119,9 @@ class PositionBlotter extends Component {
107119
<th>Quanity</th>
108120
<th>Price</th>
109121
<th>Market Value</th>
122+
<th>Buy/Sell</th>
110123
<th>Trade Date</th>
111-
<th>Exec Date</th>
124+
<th>Status</th>
112125
</tr>
113126
</thead>
114127
<tbody>{tableRows}</tbody>

0 commit comments

Comments
 (0)