Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CS2113-T16-3] Command Line Paper Trading #46

Open
wants to merge 206 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 157 commits
Commits
Show all changes
206 commits
Select commit Hold shift + click to select a range
3e56fab
Set theme jekyll-theme-slate
trolommonm Oct 1, 2020
3e38f84
Update AboutUs.md
yokemin Oct 1, 2020
0f90574
Merge pull request #2 from yokemin/about-us
trolommonm Oct 1, 2020
a8c55bd
Add barebones code and start on api
yokemin Oct 12, 2020
f15d947
Set up API to print json upon request
yokemin Oct 12, 2020
d730934
Edit code to follow coding standards
yokemin Oct 12, 2020
e7c0271
Edit code to meet coding standards
yokemin Oct 12, 2020
d7df2f3
Edit Javadoc sentence to meet coding standards
yokemin Oct 12, 2020
2fa7dd0
Comment code to print json string
yokemin Oct 12, 2020
b67bae4
Emptied text-ui-test txt files to pass CI test
yokemin Oct 12, 2020
9359cdf
Merge pull request #4 from yokemin/setup-API
yokemin Oct 12, 2020
6761268
Add functionality to search for company based on the ticker symbol
Oct 13, 2020
f75e25c
Merge pull request #7 from trolommonm/search-function
trolommonm Oct 13, 2020
f2f1655
Merge pull request #1 from AY2021S1-CS2113-T16-3/master
JunxianAng Oct 13, 2020
ccd67c1
Merge branch 'master' of https://github.com/JunxianAng/tp into master
JunxianAng Oct 13, 2020
35ba821
Add portfolio manager class
Oct 13, 2020
dc95e50
Update EXPECTED.TXT
Oct 13, 2020
c4dd49d
Merge pull request #9 from trolommonm/search-function
trolommonm Oct 13, 2020
e850225
Add transaction class
yokemin Oct 13, 2020
26f98a2
Merge pull request #10 from yokemin/portfolio-manager
yokemin Oct 13, 2020
4a8ffd7
Update README.md
wly99 Oct 13, 2020
16fd128
Add buy function
Oct 13, 2020
ba63108
Merge pull request #14 from trolommonm/buy-function
trolommonm Oct 13, 2020
de5bdb1
Set theme jekyll-theme-midnight
wly99 Oct 13, 2020
edf2b45
Merge pull request #15 from wly99/master
wly99 Oct 13, 2020
11f2b57
Add function to sell stocks
yokemin Oct 13, 2020
2c18fc6
Update UserGuide.md
wly99 Oct 13, 2020
124dab7
Edit error messages
yokemin Oct 13, 2020
323d3c3
Update UserGuide.md
wly99 Oct 13, 2020
4c0366a
Update UserGuide.md
wly99 Oct 13, 2020
ea38ff5
Update UserGuide.md
wly99 Oct 13, 2020
7dc7e4b
Edit text-ui-test files
yokemin Oct 13, 2020
45769d2
Update SellCommand class
wly99 Oct 13, 2020
ec549d1
Edit code to fit coding standards
yokemin Oct 13, 2020
da63fb5
Merge branch 'master' into sell-stocks
yokemin Oct 13, 2020
f2d3fe9
Merge pull request #16 from yokemin/sell-stocks
yokemin Oct 13, 2020
bec7cbd
Edit code to follow coding standards
yokemin Oct 13, 2020
b97556f
Revert "Edit code to follow coding standards"
yokemin Oct 13, 2020
2b0cd15
Merge branch 'master' of https://github.com/AY2021S1-CS2113-T16-3/tp …
yokemin Oct 13, 2020
4beafe3
Edit code to follow coding standards
yokemin Oct 13, 2020
20c72bd
Merge pull request #17 from yokemin/master
yokemin Oct 13, 2020
db777a8
Write Junit tests for sellStock method in Portfolio class
yokemin Oct 13, 2020
a5bdd29
Move "{" to meet code style requirements
yokemin Oct 13, 2020
df5036b
Merge pull request #20 from yokemin/master
yokemin Oct 13, 2020
c986fa4
Merge pull request #2 from AY2021S1-CS2113-T16-3/master
JunxianAng Oct 13, 2020
8c8614e
Merge branch 'master' of https://github.com/JunxianAng/tp into master
JunxianAng Oct 13, 2020
2c4cf6d
Wallet
Oct 13, 2020
9fc7d30
Update view to include individual stock profit/loss tracking
JunxianAng Oct 14, 2020
d20c5d0
Edit code to follow coding standard
JunxianAng Oct 14, 2020
b31aa09
Merge pull request #21 from JunxianAng/master
JunxianAng Oct 14, 2020
680a654
Update UserGuide.md
wly99 Oct 14, 2020
842d730
Update UserGuide.md
wly99 Oct 14, 2020
183bb81
Update UserGuide.md
wly99 Oct 14, 2020
5e71bb2
Update UserGuide.md
wly99 Oct 14, 2020
8509d8d
Update UserGuide.md
wly99 Oct 14, 2020
3e4ab6d
Merge pull request #22 from AY2021S1-CS2113-T16-3/wly99-patch-1
wly99 Oct 14, 2020
a7f7a59
Update UserGuide.md
wly99 Oct 14, 2020
5d64330
Update UserGuide.md
wly99 Oct 14, 2020
701a38b
Update DeveloperGuide.md
wly99 Oct 14, 2020
bc15eca
Update AboutUs.md
wly99 Oct 14, 2020
c946309
Update AboutUs.md
wly99 Oct 14, 2020
57806ad
Merge pull request #23 from wly99/master
wly99 Oct 14, 2020
3f83c83
Add JUnit testing for searching stock
Oct 14, 2020
6b4e1ee
Change Junit testing for search stock function
Oct 14, 2020
d5d5fd9
Merge pull request #24 from trolommonm/searchstock-junit
trolommonm Oct 14, 2020
6556990
FINALWALLETPLS
Oct 14, 2020
6faa035
MERGEPLSPLS
Oct 14, 2020
e07eb94
Merge pull request #28 from shaojingle/master
yokemin Oct 14, 2020
5ac1f7b
v1.0
yokemin Oct 14, 2020
eca29e1
Add link to first release in User Guide
yokemin Oct 14, 2020
30a9ffe
Add assertion and logging
yokemin Oct 16, 2020
4354743
Merge pull request #30 from yokemin/assertion-and-logging
yokemin Oct 16, 2020
1df0bed
Add logging and assertion
Oct 16, 2020
7c70163
Update codestyle to pass checks
Oct 16, 2020
d383ecb
Merge pull request #32 from trolommonm/assertion-logging
trolommonm Oct 16, 2020
f099260
Merge pull request #3 from AY2021S1-CS2113-T16-3/master
JunxianAng Oct 17, 2020
9ca6977
Merge branch 'master' of https://github.com/JunxianAng/tp into master
JunxianAng Oct 17, 2020
b75136e
Update view
JunxianAng Oct 17, 2020
f5f8739
Add assertion and logging
JunxianAng Oct 17, 2020
c584da1
Update codestyle
JunxianAng Oct 17, 2020
c8bb194
Merge pull request #33 from JunxianAng/master
JunxianAng Oct 17, 2020
bbdf58d
Update Developer Guide
Oct 19, 2020
db7bed1
Remove view to pass test
Oct 19, 2020
086debb
Add view back to input.txt
Oct 19, 2020
3188401
Merge pull request #35 from trolommonm/developer-guide
trolommonm Oct 19, 2020
9990af0
Fix errors for build.gradle
yokemin Oct 19, 2020
152e96f
Enable assertions in build.gradle
yokemin Oct 19, 2020
6700ad3
Merge pull request #43 from yokemin/master
yokemin Oct 19, 2020
db9c0c3
Merge pull request #4 from AY2021S1-CS2113-T16-3/master
JunxianAng Oct 19, 2020
9ce75a9
Merge branch 'master' of https://github.com/JunxianAng/tp into master
JunxianAng Oct 19, 2020
0df0a81
Update DG for buy/sell stock function
yokemin Oct 19, 2020
eac3db9
Update AboutUs and create md file for each person
yokemin Oct 19, 2020
6cc3258
Merge pull request #44 from yokemin/developer-guide
yokemin Oct 19, 2020
b1700a0
Merge pull request #5 from AY2021S1-CS2113-T16-3/master
JunxianAng Oct 20, 2020
42e8209
Merge branch 'master' of https://github.com/JunxianAng/tp into master
JunxianAng Oct 20, 2020
77fe3e1
Update Developerguide
JunxianAng Oct 20, 2020
b19ea51
Update diagram
JunxianAng Oct 20, 2020
afb45df
Merge pull request #45 from JunxianAng/master
JunxianAng Oct 20, 2020
ab2fc1a
Update UserGuide.md
wly99 Oct 21, 2020
e15c2fb
Updated parseBuy() to reflect correct error msg when user does not in…
wly99 Oct 21, 2020
a55288d
Merge branch 'master' of https://github.com/AY2021S1-CS2113-T16-3/tp
wly99 Oct 21, 2020
4b31655
Update UserGuide.md
wly99 Oct 21, 2020
c7ef8b9
Update UserGuide.md
wly99 Oct 21, 2020
6d415bd
Update DeveloperGuide.md
wly99 Oct 21, 2020
fe314c1
Update DeveloperGuide.md
wly99 Oct 21, 2020
b5a7dca
Update DeveloperGuide.md
wly99 Oct 21, 2020
f259d24
Update DeveloperGuide.md
wly99 Oct 21, 2020
c8ef2d4
Update DeveloperGuide.md
wly99 Oct 21, 2020
b7c2dae
Update README.md
wly99 Oct 21, 2020
102d4b1
Update README.md
wly99 Oct 21, 2020
512c6f3
Update README.md
wly99 Oct 21, 2020
70cc7ad
Fix wallet to prevent purchase if the total purchase amount is more t…
Oct 27, 2020
0e45ed2
Change exception thrown in junit test
Oct 27, 2020
190104f
Merge pull request #48 from trolommonm/fix-wallet
trolommonm Oct 27, 2020
006dfc8
Add function to store all the stocks and transaction history
Oct 27, 2020
59fedc8
Fix codestyle errors
Oct 27, 2020
1bab1bd
Merge pull request #49 from trolommonm/storage-function
trolommonm Oct 27, 2020
0851b8a
Update DG according to changes in code
yokemin Oct 27, 2020
57a069e
Add sequence diagram for buy stock function
yokemin Oct 27, 2020
e370910
Merge pull request #50 from yokemin/add-sequence-diagram
yokemin Oct 27, 2020
6fb0220
Remove redundant line in DG
yokemin Oct 27, 2020
fc34712
Update UG
yokemin Oct 27, 2020
28e96e0
Merge pull request #52 from yokemin/edit-UG
yokemin Oct 27, 2020
5e1c687
Refactor code
yokemin Oct 27, 2020
335b957
Remove storage class
yokemin Oct 27, 2020
34a41ab
Add mark, unmark and bookmarks function
yokemin Oct 27, 2020
25c8aa0
Update UG for functions related to bookmarking stocks
yokemin Oct 27, 2020
4695972
Update DG
yokemin Oct 27, 2020
acdaba3
Refactor code
yokemin Oct 27, 2020
e5ee57c
Add Junit test for functions in Bookmarks class
yokemin Oct 27, 2020
5073836
Merge pull request #53 from yokemin/bookmark-stocks
yokemin Oct 27, 2020
648043f
Add to UserGuide.md
Oct 28, 2020
fdcbf7d
Merge pull request #54 from trolommonm/user-guide
trolommonm Oct 28, 2020
daa552a
Fix stock still appearing on view when quantity is 0
Oct 28, 2020
a44215a
Ignore all data files
Oct 28, 2020
0d7520c
Merge branch 'user-guide'
Oct 28, 2020
6f9c600
Add more api keys
Oct 28, 2020
177755c
Update codestyle
Oct 28, 2020
7ec96ec
Merge pull request #55 from trolommonm/master
trolommonm Oct 28, 2020
13dc79b
Merge pull request #56 from trolommonm/api-keys
trolommonm Oct 28, 2020
abb83f5
Merge branch 'master' of https://github.com/AY2021S1-CS2113-T16-3/tp
wly99 Oct 28, 2020
593a811
no message
wly99 Oct 28, 2020
8212ccf
Merge pull request #57 from wly99/master
wly99 Oct 28, 2020
cde37b8
no message
wly99 Oct 29, 2020
35224f2
Added BuyCommandTest
wly99 Oct 29, 2020
9c9c2c6
Merge pull request #58 from wly99/master
wly99 Oct 29, 2020
52bebfa
Added SellCommandTest
wly99 Oct 29, 2020
f3b07bb
Merge pull request #59 from wly99/master
wly99 Oct 29, 2020
4359747
Added SearchCommandTest
wly99 Oct 29, 2020
87cd14a
Merge pull request #60 from wly99/master
wly99 Oct 29, 2020
e02a053
Added InvalidCommandTest
wly99 Oct 29, 2020
d6f5570
Merge pull request #61 from wly99/master
wly99 Oct 29, 2020
0acf9d8
Added AddBookmarkCommand
wly99 Oct 29, 2020
6747986
Added AddBookMarkCommand
wly99 Oct 29, 2020
6ff60bd
Merge pull request #62 from wly99/master
wly99 Oct 29, 2020
57daf32
RemoveBookmarkCommandTest
wly99 Oct 29, 2020
d0efc1e
Merge pull request #63 from wly99/master
wly99 Oct 29, 2020
9af5620
Merge pull request #6 from AY2021S1-CS2113-T16-3/master
JunxianAng Oct 29, 2020
466804e
Merge branch 'master' of https://github.com/JunxianAng/tp into master
JunxianAng Oct 29, 2020
91b05da
Fix selling and buying of negative quantities
Nov 3, 2020
c8a0dde
Fix checkstyle issues
Nov 3, 2020
c46aa28
Merge pull request #93 from trolommonm/negativeqty-fix
trolommonm Nov 3, 2020
e593ab2
Update DG
Nov 3, 2020
8fae8be
Merge pull request #94 from trolommonm/update-dg
trolommonm Nov 3, 2020
92b6d0a
Add Junit testing for selling negative quantity
Nov 3, 2020
7e529d8
Merge pull request #95 from trolommonm/add-junit
trolommonm Nov 3, 2020
9fd87b7
update ppp
Nov 7, 2020
76d7d54
Merge pull request #96 from trolommonm/update-ppp
trolommonm Nov 7, 2020
a5c6396
Edit User Guide
yokemin Nov 7, 2020
7567efd
Fix bugs related to bookmarks function
yokemin Nov 7, 2020
387cb5e
Merge pull request #97 from yokemin/fix-bugs
yokemin Nov 7, 2020
3d10720
Update PPP
yokemin Nov 7, 2020
55f6bfc
Merge pull request #99 from yokemin/update-ppp
yokemin Nov 7, 2020
d164446
Edit sequence diagram
yokemin Nov 7, 2020
2dca0bb
Merge pull request #100 from yokemin/master
yokemin Nov 7, 2020
61f572f
Add 10 more API keys to fix bugs
yokemin Nov 7, 2020
ef0a656
Merge pull request #101 from yokemin/master
yokemin Nov 7, 2020
9ec3f86
Limit bookmarks to a maximum of 5
yokemin Nov 7, 2020
9ded304
Merge pull request #102 from yokemin/master
yokemin Nov 7, 2020
9287fad
Change exception message for fetching latest stock data
yokemin Nov 7, 2020
5b44903
Merge branch 'master' of https://github.com/AY2021S1-CS2113-T16-3/tp
yokemin Nov 7, 2020
b152ec0
Refactor code and changed exception name
yokemin Nov 7, 2020
800b510
Fix checkstyle errors
yokemin Nov 7, 2020
95d3a0c
Merge pull request #103 from yokemin/master
yokemin Nov 7, 2020
c8be066
Add line to hide logger
yokemin Nov 7, 2020
c8a4b67
Change exception message
yokemin Nov 7, 2020
a75f1b3
Merge pull request #104 from yokemin/master
yokemin Nov 7, 2020
694f1d6
Edit UG
yokemin Nov 7, 2020
be269d2
Fix link to PPP
yokemin Nov 7, 2020
c0e913a
Edit readme.md
yokemin Nov 7, 2020
94c8559
Update liangyi.md
wly99 Nov 7, 2020
b5cffaa
Update liangyi.md
wly99 Nov 7, 2020
4fae56c
Update liangyi.md
wly99 Nov 7, 2020
3f886d7
Update junxian.md
wly99 Nov 7, 2020
0503765
Update shaojing.md
wly99 Nov 7, 2020
c2db328
Update liangyi.md
wly99 Nov 7, 2020
e78057f
Rename liangyi.md to wly99.md
wly99 Nov 7, 2020
5b7cc95
Update AboutUs.md
wly99 Nov 7, 2020
8f1b9dd
Update AboutUs.md
wly99 Nov 7, 2020
7d00312
Merge pull request #7 from AY2021S1-CS2113-T16-3/master
JunxianAng Nov 8, 2020
05405e1
Merge branch 'master' of https://github.com/JunxianAng/tp into master
JunxianAng Nov 8, 2020
2f2f064
Update PPP
JunxianAng Nov 8, 2020
24ce353
Delete junxian.md
JunxianAng Nov 8, 2020
bc413fe
Merge pull request #105 from JunxianAng/master
JunxianAng Nov 8, 2020
4bc8720
rename PPP
Nov 8, 2020
936f8b4
Merge pull request #106 from trolommonm/rename-ppp
trolommonm Nov 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ bin/

/text-ui-test/ACTUAL.txt
text-ui-test/EXPECTED-UNIX.TXT

data/*.ser
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-midnight
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ plugins {

repositories {
mavenCentral()
maven {
url "https://dl.bintray.com/patriques82/maven"
}
}

dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.0'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0'
compile 'org.patriques:alphavantage4j:1.4'
}

test {
Expand All @@ -29,18 +33,19 @@ test {
}

application {
mainClassName = "seedu.duke.Duke"
mainClassName = "seedu.duke.PaperTrade"
}

shadowJar {
archiveBaseName = "duke"
archiveBaseName = "paperTrade"
archiveClassifier = null
}

checkstyle {
toolVersion = '8.23'
}

run{
run {
standardInput = System.in
enableAssertions = true
}
12 changes: 6 additions & 6 deletions docs/AboutUs.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# About us
# About us(in-progress)

Display | Name | Github Profile | Portfolio
--------|:----:|:--------------:|:---------:
![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | Alvin | [Github](https://github.com/trolommonm) | [Portfolio](docs/team/alvin.md)
![](https://via.placeholder.com/100.png?text=Photo) | Yoke Min | [Github](https://github.com/yokemin) | [Portfolio](docs/team/yokemin.md)
![](https://via.placeholder.com/100.png?text=Photo) | Liang Yi | [Github](https://github.com/wly99) | [Portfolio](docs/team/liangyi.md)
![](https://via.placeholder.com/100.png?text=Photo) | Jun Xian | [Github](https://github.com/JunxianAng) | [Portfolio](docs/team/junxian.md)
![](https://via.placeholder.com/100.png?text=Photo) | Shao Jing | [Github](https://github.com/shaojingle) | [Portfolio](docs/team/shaojing.md)
196 changes: 191 additions & 5 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,215 @@
# Developer Guide
It is recommended that you read through the user guide to familiarize yourself with the program before using the
developer guide.

# Setting up PaperTrade
Fork the repository and clone the fork into your computer.

To set up the project:
1. Ensure that you have JDK 11 installed.
2. Import the project as a Gradle project.
3. To build the project, run "./gradlew build" on a Unix machine or run "gradlew build" on Windows.

## Design & implementation

{Describe the design and implementation of the product. Use UML diagrams and short code snippets where applicable.}
### Architecture

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Architecture part, there are many diagrams but few words to explain. Is it better to add more explanation in this part?


![](./diagrams/Packages.png)

The Package Diagram above gives a high level view of the project structure and the classes in each package.

![](./diagrams/Architecture.png)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be better to put the high level design of PaperTrade above the project structure?


The Architecture Diagram above gives a high level design of PaperTrade. Below is a quick overview of each component.

### Overview

* `PaperTrade`: The main entry point into the program. It initializes the Controller object which then takes over the
execution of the program.
* `Controller`: Acts as an interface between all the other classes, to process all the business logic incoming commands
from the user. Manipulates the data through `PortfolioManager` and interact with `Ui` to display information to the
user.
* `PortfolioManager`: Responsible for managing the persistency of the user's data through the `Storage` class and holds
all the data for the program at a point in time.
* `Ui`: Responsible for displaying information to the user and getting input from the user.
* `Parser`: Responsible for parsing the user input and returning a `Command` object corresponding to the user command
requested.
* `StockPriceFetcher`: Responsible for calling the AlphaVantage API to retrieve stock information.
* `Storage`: Responsible for managing the storing of data for persistency.

### Lifecycle of PaperTrade
The sequence diagram below shows how different packages and classes interact with each other throughout the lifecycle
of PaperTrade.

![](./diagrams/Lifecycle.png)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the activation of PaperTrade and Ui correct? Should the PaperTrade be activated when the main() is called?


## Implementation

### Buy/Sell Stock Feature

#### Current implementation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the DG is lacking some examples, is it better to add some sample inputs and outputs?


Buy and sell stock commands are largely similar, with the only difference being the way values of attributes in
the objects instantiated are updated and the condition for throwing exceptions.
Other than that, the way the functions work is the same.

Below is the explanation of the implementation of based on buy stock command,
which can be applied to the sell stock command as well.

Given below is an example usage scenario and how buy stock command behaves at each step.

![](./diagrams/BuyStockState0.png)

**Step 1** : The user calls the buy stock command from the `Parser`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the feature part, it looks redundant with too many steps. Is it better to divide them into operations, usages, and diagrams?

Buy stock command is instantiated by `Parser`, which calls the `buyParse` method to get the attribute values
for `symbol` and `quantity` required to instantiate `buyCommand`. The `Controller` instantiates `Ui`, `PortfolioManager`
and `StockPriceFetcher`, which gets the `price` of stock.
In the `Controller`, we check for the instance of `buyCommand` object and calls the `buyStock` method.

Below is a table of what each parameter corresponds to in the state diagram of the program.

|Parameter|Corresponds to
|:---:|:---:
|`symbol`| Ticker symbol of Stock to buy
|`quantity`| Integer number of shares to be
|`price`| Price of stock at current time

**Step 2** : `buyStock()` is called from the `PortfolioManager` with the values of `symbol` and `quantity`
and `price` passed to them.

**Step 3** : `Portfolio` is instantiated and its `buyStock` method is called as well.

![](./diagrams/BuyStockState1.png)


**Step 4** : `Wallet` and `Stock` are instantiated.
It then checks if there is sufficient fund in the wallet. If so, `buyStock` method is called from the `wallet` instance.
Then, new `Transaction` object is instantiated.
The `transaction` object stores details of the stock bought.
Below is a table of what each attribute in `Transaction` corresponds to in the program.

|Attribute|Corresponds to
|:---:|:---:
|`TransactionType`| Buy or Sell stock
|`Quantity`| Integer number of shares to be bought
|`BuyPrice`| Cost price of a stock at a specific time
|`LocalDateTime`| the time when the command is called

**Step 5** : Following that, _if a stock with the same symbol has not been instantiated before_,
a new 'Stock' object is also instantiated. Otherwise, the `Stock` object of that stock symbol will be used.

The method `addTransaction` in the `stock` object is then called, with the `transaction` object as a parameter,
to update the value of the attribute `totalQuantity` in `Stock`.

![](./diagrams/BuyStockState2.png)

**Step 6** : `Portfolio`, `Wallet`, `Transaction` and `Stock` are terminated first.
The `save` method is then called.

**Step 7**: `Controller` then calls the relevant methods from `Ui` to print the information about the stock bought and
the amount left in the wallet. `StockPriceFetcher`, `Ui` and `PortfolioManager` are then terminated.

![](./diagrams/BuyStockState3.png)

The following sequence diagram summarizes what happens when the user executes an `BuyCommand` :

![](./diagrams/BuyStockSequence.png)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the Portfolio, wallet, transaction and stock be destroyed when they are terminated (maybe could add a cross in the diagram) ?


#### Design consideration

The following explains the design considerations when implementing commands:

* Make `BuyCommand` As a class by itself
* Reason: Increases modularity of code, higher overall code quality
* Alternatives: have a `buyCommand` method, increases coupling and reduces testability

### View Portfolio feature

#### Current implementation

View portfolio command is executed by `Controller`. It allows users to access, retrieve and view array list of stocks
owned and their historical transactions. This is done by instantiating a new `PortfolioManager` which is able to
access `Portfolio`. The `Portfolio` object encapsulates `Stock` and `Transaction`.

Addtionally, `Stock` object is able to retrieve latest live prices by instantiating `StockPriceFetcher` to call
AlphaVantage API. This allows users to view not only their stocks historial transactions, but to see their profit/loss
based on current latest price.

Given below is an example usage scenario and how view portfolio command behaves at each step.

![](./diagrams/ViewPortfolioState0.png)

**Step 1**: `Parser` will initialise `ViewCommand` and call `viewPortfolio()` command from the `Controller`. `Ui` is initialised to call `view()`. The method
takes in an parameter of an array list of stock to be displayed.

|Parameter|Corresponds to
|:---:|:---:
|`Stock`| Stock objects

**Step 2**: To obtain an array list of stock to be used as an arugment in `Ui` `view()` method, `PortfolioManager` is initialised to call `getAllStocks()` method.
The method returns an array list of `Stock` by initialising `Portfolio` which is keeps a HashMap of `Stock` objects. Below is a table of what each attribute in
`Stock`corresponds to in the program.

|Attribute|Corresponds to
|:---:|:---:
|`Symbol`| Ticker Symbol of Stock in possession
|`totalQuantity`| Integer number of shares currently owned
|`transactions`| An array list of `Transaction` object

![](./diagrams/ViewPortfolioState1.png)

**Step 3**: For each of the `Stock` object to be displayed, `getTransaction()` method is called to obtained historial
records of user's stock transactions.
Below is a table of what each attribute in `Transaction` corresponds to in the program.

|Attribute|Corresponds to
|:---:|:---:
|`TransactionType`| Buy or Sell stock
|`Quantity`| Integer number of shares to be bought
|`BuyPrice`| Cost price of a stock at a specific time
|`LocalDateTime`| the time when the command is called

**Step 4**: For each of the `Stock` object to be displayed, `getLatestPrice()` method is called by instantiating a new `StockPriceFetcher`
which calls out to AlphaVantage API to obtain latest stock price.

User's latest profit/loss will be displayed through calculation of latest stock price
against historical buy price.

![](./diagrams/ViewPortfolioState2.png)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diagrams are clear to show the features step by step!


**Step 5**: `Parser`, `ViewCommand`, `Stock`, `Transaction`, `StockPriceFetcher` are terminated.


## Product scope
### Target user profile

{Describe the target user profile}
We are targeting people below 25 who have never traded stocks before.

### Value proposition

{Describe the value proposition: what problem does it solve?}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line supposed to be deleted?

Paper trading allows inexperienced people to get a feel of what trading feels like so that they can used to it without the downside of losing real money.

## User Stories

|Version| As a ... | I want to ... | So that I can ...|
|Version| As a/an ... | I want to ... | So that I can ...|
|--------|----------|---------------|------------------|
|v1.0|new user|see usage instructions|refer to them when I forget how to use the application|
|v2.0|user|find a to-do item by name|locate a to-do without having to go through the entire list|
|v1.0|new investor|see usage instructions|refer to them when I forget how to use the application|
|v1.0|new investor|trade without putting my money at risk|learn from my mistakes and experience without losing money|
|v1.0|investor|search for stocks I can buy|have more information to make a more informed decision|
|v1.0|investor|buy stocks|profit from any capital gains or dividends|
|v1.0|investor|sell stocks|realise my gains or reallocate my money to other stocks|
|v1.0|investor|view my portfolio|see what stocks I have and my past transactions|
|v2.0|investor|keep track of what stocks I have bought or sold|see how much money I've made or lost|
|v2.0|investor|see how much cash I have left|decide how much to buy or sell|
|v2.0|investor|have a watchlist of stocks|track the price movements of individual stocks|
|v2.1|investor|see the performance of my portfolio|see if I'm on track for my financial goals|

## Non-Functional Requirements

{Give non-functional requirements}
1. Program should not take more than 5s to run for every command.
2. Program should give some loading indicator when fetching stock prices from API calls.

## Glossary

Expand Down
8 changes: 4 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Duke

{Give product intro here}
{Paper trading command line app}

Useful links:
* [User Guide](UserGuide.md)
* [Developer Guide](DeveloperGuide.md)
* [About Us](AboutUs.md)
* [User Guide](UserGuide.md)(Read more about how to use our application!)
* [Developer Guide](DeveloperGuide.md)(Good to read for devs working on our app!)
* [About Us](AboutUs.md)(The awesome team behind this!)
16 changes: 16 additions & 0 deletions docs/UML/Architecture.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@startuml
rectangle PaperTrade
rectangle Controller
rectangle Ui
rectangle PortfolioManager
rectangle Parser
rectangle StockPriceFetcher
rectangle Storage

PaperTrade --> Controller
Controller --> Ui
Controller --> PortfolioManager
PortfolioManager --> Storage
Controller --> Parser
Controller --> StockPriceFetcher
@enduml
72 changes: 72 additions & 0 deletions docs/UML/BuyStockSequence.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@startuml
participant ":Controller" as Controller
participant ":StockPriceFetcher" as StockPriceFetcher
participant ":PortfolioManager" as PortfolioManager
participant ":Portfolio" as Portfolio
participant ":Wallet" as Wallet
participant ":Transaction" as Transaction
participant ":Stock" as Stock


[-> Controller : buyStock(symbol, quantity)
activate Controller


Controller -> StockPriceFetcher : fetchLatestPrice(symbol)
activate StockPriceFetcher

StockPriceFetcher --> Controller : price
deactivate StockPriceFetcher


Controller -> PortfolioManager : buyStock(symbol, quantity, price)
activate PortfolioManager

PortfolioManager -> Portfolio : buyStock(symbol, quantity, price)
activate Portfolio

Portfolio -> Wallet : buyStock(quantity, price)
activate Wallet

Wallet --> Portfolio :
deactivate Wallet

create Transaction
Portfolio -> Transaction : new Transaction(quantity, price, time)
activate Transaction

Transaction --> Portfolio : transaction
deactivate Transaction


alt stock not in portfolio
create Stock
Portfolio -> Stock : new Stock(symbol)
activate Stock
Stock --> Portfolio
deactivate Stock
Portfolio -> Stock : addTransaction(transaction)
activate Stock
Stock --> Portfolio :
deactivate Stock

else stock already exist in portfolio
Portfolio -> Stock : addTransaction(transaction)
activate Stock
Stock --> Portfolio :
deactivate Stock

end

Portfolio --> PortfolioManager :
deactivate Portfolio

PortfolioManager -> PortfolioManager : save()

PortfolioManager --> Controller :
deactivate PortfolioManager

[<--Controller
deactivate Controller

@enduml
Loading