Skip to content

Commit d554be5

Browse files
committedOct 9, 2020
Updating readme
1 parent 0ac6372 commit d554be5

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed
 

‎.DS_Store

0 Bytes
Binary file not shown.

‎README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ You will need the following installed on your computer system and import the fol
4646

4747
* Password Hashing - this web application hashes the user's password upon account registration, so no real passwords are stored in the database
4848

49-
* Portfolio Balance - presents users current investment portfolio
49+
* Portfolio Balance - presents users current investment portfolio and cash position. Default new users start with $10,000.
5050

51-
* Quote & Buy - in a sequential three step process, the user may query for real time quotes, estimate a buy order, and execute a buy order followed buy a confirmation. Again, real-time quotes are provided by: https://iexcloud.io/
51+
* Quote & Buy - in a three step process, the user will first query for a stock ticker, perform a buy estimate, and either executes a buy order, or not, using real time API quotes provided by IEX Cloud (https://iexcloud.io/) This process is concluded with a buy order confirmation
5252

53-
* Sell - in a sequential two step process, users may estimate a sell order, and subsequently execute a sell order
53+
* Sell - in a two step process, users may estimate, and subsequently, execute a sell order
5454

5555
* Transaction History - view when all orders were place in the History page where the database displays all executed orders
5656

@@ -119,7 +119,7 @@ You will need the following installed on your computer system and import the fol
119119

120120
* Use Regular Expressions to vet unwanted inputs
121121

122-
* Update to production grade database infrastructure using PostGres SQL and deploy using Heroku
122+
* Update to production grade database infrastructure using PostGres SQL and deploy using Heroku because of it's free cost structure for dynamic data
123123

124124
* Create function to allow users to change passwords or add more money
125125

‎readme_pics/.DS_Store

0 Bytes
Binary file not shown.

‎sql_queries.txt

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
CREATE TABLE IF NOT EXISTS 'users' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
2+
,'username' TEXT NOT NULL
3+
,'hash' TEXT NOT NULL
4+
,'cash' NUMERIC NOT NULL DEFAULT 10000.00
5+
);
6+
7+
CREATE TABLE sqlite_sequence(name,seq);
8+
9+
CREATE UNIQUE INDEX 'username' ON "users" ("username");
10+
11+
CREATE TABLE names(first_name TEXT NOT NULL,
12+
last_name VARCHAR(255) NOT NULL,
13+
email_address TEXT NOT NULL,
14+
name_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
15+
FOREIGN KEY(name_id) REFERENCES users(id)
16+
);
17+
18+
CREATE TABLE IF NOT EXISTS 'companies' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
19+
,'name' TEXT NOT NULL
20+
,'symbol' VARCHAR(4) NOT NULL UNIQUE
21+
,'exchange' TEXT NOT NULL
22+
);
23+
24+
CREATE TABLE cash (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
25+
datetime DATETIME NOT NULL,
26+
debit REAL NOT NULL,
27+
credit REAL NOT NULL,
28+
user_id INTEGER NOT NULL
29+
,trans_id VARCHAR(20),
30+
FOREIGN KEY(user_id) REFERENCES users (id)
31+
);
32+
33+
CREATE TABLE IF NOT EXISTS 'transactions' (trans_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
34+
datetime DATETIME NOT NULL,
35+
price REAL NOT NULL,
36+
quantity INTEGER NOT NULL,
37+
total REAL NOT NULL,
38+
ordertype TEXT NOT NULL,
39+
c_id INTEGER NOT NULL,
40+
user_id INTEGER NOT NULL,
41+
CHECK (ordertype IN ('BUY', 'SELL')),
42+
FOREIGN KEY(c_id) REFERENCES companies (id),
43+
FOREIGN KEY(user_id) REFERENCES users (id)
44+
);
45+
46+
WITH indexSetup AS (
47+
SELECT u.username, c.symbol, c.name, t.c_id, t.ordertype, SUM(u.cash) AS cash, SUM(t.quantity) as quantity, SUM(t.quantity * t.price) AS total FROM transactions t
48+
JOIN companies c ON t.c_id = c.id JOIN users u ON t.user_id = u.id WHERE user_id =1 GROUP BY 1, 2, 3, 4, 5)
49+
,sell AS(SELECT username, symbol, name, c_id, SUM(cash) AS cash, SUM(quantity) AS quantity , SUM(total) AS costBasis FROM indexSetup WHERE ordertype = 'SELL' GROUP BY 1, 2, 3, 4)
50+
51+
, buy AS(SELECT username, symbol, name, c_id, SUM(cash) AS cash, SUM(quantity) AS quantity , SUM(total) AS costBasis FROM indexSetup WHERE ordertype = 'BUY' GROUP BY 1, 2, 3, 4)
52+
53+
,results AS(
54+
SELECT username, symbol, name, c_id, cash,
55+
COALESCE(SUM(b.quantity - s.quantity), b.quantity) AS quantity,
56+
COALESCE(SUM(b.costBasis - s.costBasis), b.costBasis) AS total
57+
FROM buy b
58+
LEFT JOIN sell s USING(username, symbol, name, c_id, cash)
59+
GROUP BY 1, 2, 3, 4, 5
60+
ORDER BY name
61+
)
62+
SELECT * FROM results WHERE quantity >0;

0 commit comments

Comments
 (0)
Please sign in to comment.