-
Notifications
You must be signed in to change notification settings - Fork 282
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
base: master
Are you sure you want to change the base?
Changes from all commits
3e56fab
3e38f84
0f90574
a8c55bd
f15d947
d730934
e7c0271
d7df2f3
2fa7dd0
b67bae4
9359cdf
6761268
f75e25c
f2f1655
ccd67c1
35ba821
dc95e50
c4dd49d
e850225
26f98a2
4a8ffd7
16fd128
ba63108
de5bdb1
edf2b45
11f2b57
2c18fc6
124dab7
323d3c3
4c0366a
ea38ff5
7dc7e4b
45769d2
ec549d1
da63fb5
f2d3fe9
bec7cbd
b97556f
2b0cd15
4beafe3
20c72bd
db777a8
a5bdd29
df5036b
c986fa4
8c8614e
2c4cf6d
9fc7d30
d20c5d0
b31aa09
680a654
842d730
183bb81
5e71bb2
8509d8d
3e4ab6d
a7f7a59
5d64330
701a38b
bc15eca
c946309
57806ad
3f83c83
6b4e1ee
d5d5fd9
6556990
6faa035
e07eb94
5ac1f7b
eca29e1
30a9ffe
4354743
1df0bed
7c70163
d383ecb
f099260
9ca6977
b75136e
f5f8739
c584da1
c8bb194
bbdf58d
db7bed1
086debb
3188401
9990af0
152e96f
6700ad3
db9c0c3
9ce75a9
0df0a81
eac3db9
6cc3258
b1700a0
42e8209
77fe3e1
b19ea51
afb45df
ab2fc1a
e15c2fb
a55288d
4b31655
c7ef8b9
6d415bd
fe314c1
b5a7dca
f259d24
c8ef2d4
b7c2dae
102d4b1
512c6f3
70cc7ad
0e45ed2
190104f
006dfc8
59fedc8
1bab1bd
0851b8a
57a069e
e370910
6fb0220
fc34712
28e96e0
5e1c687
335b957
34a41ab
25c8aa0
4695972
acdaba3
e5ee57c
5073836
648043f
fdcbf7d
daa552a
a44215a
0d7520c
6f9c600
177755c
7ec96ec
13dc79b
abb83f5
593a811
8212ccf
cde37b8
35224f2
9c9c2c6
52bebfa
f3b07bb
4359747
87cd14a
e02a053
d6f5570
0acf9d8
6747986
6ff60bd
57daf32
d0efc1e
9af5620
466804e
91b05da
c8a0dde
c46aa28
e593ab2
8fae8be
92b6d0a
7e529d8
9fd87b7
76d7d54
a5c6396
7567efd
387cb5e
3d10720
55f6bfc
d164446
2dca0bb
61f572f
ef0a656
9ec3f86
9ded304
9287fad
5b44903
b152ec0
800b510
95d3a0c
c8be066
c8a4b67
a75f1b3
694f1d6
be269d2
c0e913a
94c8559
b5cffaa
4fae56c
3f886d7
0503765
c2db328
e78057f
5b7cc95
8f1b9dd
7d00312
05405e1
2f2f064
24ce353
bc413fe
4bc8720
936f8b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ bin/ | |
|
||
/text-ui-test/ACTUAL.txt | ||
text-ui-test/EXPECTED-UNIX.TXT | ||
|
||
data/*.ser |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
theme: jekyll-theme-midnight |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,214 @@ | ||
# 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 | ||
|
||
![](./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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 High Level Class 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
# 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!) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@startuml | ||
rectangle PaperTrade | ||
rectangle Controller | ||
rectangle Ui | ||
rectangle PortfolioManager | ||
rectangle Parser | ||
rectangle StockPriceFetcher | ||
rectangle Portfolio | ||
rectangle Wallet | ||
|
||
PaperTrade --> Controller | ||
Controller --> Ui | ||
Controller --> PortfolioManager | ||
PortfolioManager --> Portfolio | ||
PortfolioManager --> Wallet | ||
Controller --> Parser | ||
Controller --> StockPriceFetcher | ||
@enduml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
@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() | ||
activate PortfolioManager | ||
PortfolioManager --> PortfolioManager : | ||
deactivate PortfolioManager | ||
|
||
PortfolioManager --> Controller : | ||
deactivate PortfolioManager | ||
|
||
[<--Controller | ||
deactivate Controller | ||
|
||
@enduml |
There was a problem hiding this comment.
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?