Last active
October 2, 2017 19:52
-
-
Save clintmjohnson/4cb45299b97b58f9e8fe4c2a39a670a7 to your computer and use it in GitHub Desktop.
This Python program Tracks Sample Stock buying and selling, using Yahoo Finance live Data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def stocktrack(stock,buysell,qty): | |
import sqlite3 | |
from yahoo_finance import Share | |
conn = sqlite3.connect('Stocks.db') | |
c = conn.cursor() | |
c.execute('''CREATE TABLE IF NOT EXISTS stocks | |
(date text, trans text, symbol text, qty real, price real, total real)''') | |
yahoo = Share(stock) | |
pricenow = float(yahoo.get_price()) | |
if buysell in ('Buy','BUY','b','B'): | |
buysell = 'BUY' | |
elif buysell == None: | |
buysell = 'BUY' | |
elif buysell in ('Sell','SELL','S','s'): | |
buysell = 'SELL' | |
c.execute("INSERT INTO stocks (date,trans,symbol,qty,price,total) values (date('now'),?,?,?,?,?)",\ | |
(buysell,stock,qty,pricenow,(int(qty)*int(pricenow)))) | |
conn.commit() | |
conn.close() | |
stocktrack(input('Stock to Buy: '),input('Buy or Sell? :'),input('Qty :')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment