Skip to content

Commit

Permalink
Updating readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jhustles committed Oct 9, 2020
1 parent 0ac6372 commit d554be5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ You will need the following installed on your computer system and import the fol

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

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

* 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/
* 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

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

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

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

* Use Regular Expressions to vet unwanted inputs

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

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

Expand Down
Binary file modified readme_pics/.DS_Store
Binary file not shown.
62 changes: 62 additions & 0 deletions sql_queries.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
CREATE TABLE IF NOT EXISTS 'users' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
,'username' TEXT NOT NULL
,'hash' TEXT NOT NULL
,'cash' NUMERIC NOT NULL DEFAULT 10000.00
);

CREATE TABLE sqlite_sequence(name,seq);

CREATE UNIQUE INDEX 'username' ON "users" ("username");

CREATE TABLE names(first_name TEXT NOT NULL,
last_name VARCHAR(255) NOT NULL,
email_address TEXT NOT NULL,
name_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
FOREIGN KEY(name_id) REFERENCES users(id)
);

CREATE TABLE IF NOT EXISTS 'companies' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
,'name' TEXT NOT NULL
,'symbol' VARCHAR(4) NOT NULL UNIQUE
,'exchange' TEXT NOT NULL
);

CREATE TABLE cash (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
datetime DATETIME NOT NULL,
debit REAL NOT NULL,
credit REAL NOT NULL,
user_id INTEGER NOT NULL
,trans_id VARCHAR(20),
FOREIGN KEY(user_id) REFERENCES users (id)
);

CREATE TABLE IF NOT EXISTS 'transactions' (trans_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
datetime DATETIME NOT NULL,
price REAL NOT NULL,
quantity INTEGER NOT NULL,
total REAL NOT NULL,
ordertype TEXT NOT NULL,
c_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
CHECK (ordertype IN ('BUY', 'SELL')),
FOREIGN KEY(c_id) REFERENCES companies (id),
FOREIGN KEY(user_id) REFERENCES users (id)
);

WITH indexSetup AS (
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
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)
,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)

, 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)

,results AS(
SELECT username, symbol, name, c_id, cash,
COALESCE(SUM(b.quantity - s.quantity), b.quantity) AS quantity,
COALESCE(SUM(b.costBasis - s.costBasis), b.costBasis) AS total
FROM buy b
LEFT JOIN sell s USING(username, symbol, name, c_id, cash)
GROUP BY 1, 2, 3, 4, 5
ORDER BY name
)
SELECT * FROM results WHERE quantity >0;

0 comments on commit d554be5

Please sign in to comment.