Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS682-HW1-OrderMatching
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Rohit Prasad
CS682-HW1-OrderMatching
Commits
bd2fed22
Commit
bd2fed22
authored
Jan 20, 2018
by
Rohit Prasad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify findBuyOrders() to take care of the case when buy order has more stock than the sell order
parent
7e5fb883
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
6 deletions
+25
-6
src/OrderMatching.java
src/OrderMatching.java
+25
-6
No files found.
src/OrderMatching.java
View file @
bd2fed22
...
...
@@ -19,10 +19,12 @@ public class OrderMatching {
boolean
buySellOrderMatch
(
BuyOrder
b
,
SellOrder
s
)
{
return
!
b
.
getCustomer
().
equals
(
s
.
getCustomer
())
&&
b
.
getStock
().
equals
(
s
.
getStock
())
&&
b
.
getPrice
()
>=
s
.
getPrice
()
&&
b
.
getQty
()
<=
s
.
getQty
();
b
.
getPrice
()
>=
s
.
getPrice
();
}
/*
* Finds all buy orders for current sell order
*/
ArrayList
<
BuyOrder
>
findBuyOrders
(
SellOrder
s
)
{
ArrayList
<
BuyOrder
>
matchedOrders
=
new
ArrayList
<>();
...
...
@@ -34,11 +36,28 @@ public class OrderMatching {
// check if trade is possible
if
(
buySellOrderMatch
(
b
,
s
))
{
matchedOrders
.
add
(
b
);
int
qty
=
s
.
getQty
()
-
b
.
getQty
();
if
(
qty
>=
0
)
{
// modify sell order quantity to prevent
// repeated purchases
s
.
setQty
(
s
.
getQty
()
-
b
.
getQty
());
matchedOrders
.
add
(
b
);
}
else
{
s
.
setQty
(
0
);
// create a temporary BuyOrder with quantity equal to
// the remaining stocks in sell order
BuyOrder
_b
=
new
BuyOrder
(
b
);
_b
.
setQty
(
s
.
getQty
());
// add it to buy orders queue
matchedOrders
.
add
(
_b
);
// modify buy order's quantity to reflect quantity
// remaining after trade
b
.
setQty
(
b
.
getQty
()
-
s
.
getQty
());
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment