Created
April 20, 2016 20:09
-
-
Save Lvl4Sword/4ec48ef7de6e0ae8249b366004ac2ccc to your computer and use it in GitHub Desktop.
this needs worked on..
This file contains 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
import datetime | |
import os | |
import sys | |
import time | |
import urllib | |
from colored import attr | |
from colored import bg as background | |
from colored import fg as foreground | |
from googlefinance import getQuotes | |
from time import sleep | |
from urllib import error | |
select = [1, 1, 1, 1, 0, 1, 1, 1, 1] | |
stocks = ['TSLA', 'SCTY', 'AMD', 'NFLX', 'TEAM', 'NVDA', 'SQ', 'CSCO', 'ATVI'] | |
iPRICE = [217.45, 31.88, 2.26, 97.59, 23.80, 31.76, 12.13, 27.49, 32.83] | |
shares = [2, 20, 4, 2, 10, 5, 1, 5, 5] | |
MARGIN = [25, 1, 1, 1, 1, 1, 1, 1, 1] | |
Tceiling = [] # Threshold Ceiling [continue to update the maximum price] (not in use) | |
Tfloor = [] # Misc (not in use) | |
def stock(): | |
body = '' | |
for i in range(len(stocks)): | |
try: | |
cPRICE = getQuotes(stocks[i])[0]['LastTradeWithCurrency'] # Pulling info | |
except urllib.error.HTTPError: | |
print("WHY?! WHY HAVE WE BEEN THROTTLED? :(") | |
sys.exit() | |
PRFT = float(cPRICE)-float(iPRICE[i]) | |
PQ = PRFT*shares[i] | |
TOTAL = float(shares[i])*float(cPRICE) | |
ENDc = attr(0) | |
# Colorized | |
if select[i] == 1: | |
if MARGIN[i] <= PQ: | |
ACTION = "SELL " | |
body_colors = ('{0}{1}'.format(foreground(46), background(20))) | |
elif 0.00 <= PQ < MARGIN[i]: | |
ACTION = "HOLD " | |
body_colors = ('{0}{1}'.format(foreground(6), background(20))) | |
else: | |
ACTION = "SWIM " | |
body_colors = ('{0}{1}'.format(foreground(9), background(20))) | |
else: | |
body_colors = ('{0}{1}'.format(foreground(15), background(8))) | |
# End of Colorized | |
head0 = ("\n\n\033[4m\t{0}{1}SYM\tQTY\tINIT\t".format(foreground(16), | |
background(15))) | |
head1 = "CURR\tPRFT\tP*Q\tTHRES\tTOTAL\tRCMND\033[0m" | |
head2 = "{0}\n".format(attr(0) | |
head = head0 + head1 + head2 | |
body += "\t{0}{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}{10}\n".format( | |
body_colors, | |
stocks[i], | |
int(shares[i]), | |
round(float(iPRICE[i]), 2), | |
round(float(cPRICE), 2), | |
round(float(PRFT), 2), | |
round(float(PQ), 2), | |
int(MARGIN[i]), | |
round(float(TOTAL), 2), | |
ACTION, | |
ENDc) | |
tail = "\t{0}\n\n".format(time.asctime(time.localtime(time.time()))) | |
print(head, body, tail) | |
while True: | |
run = False | |
current_time = datetime.datetime.now().time() | |
if 9 <= current_time.hour <= 16: | |
if(current_time.hour == 9 and current_time.minute >= 30 or | |
current_time.hour == 16 and current_time.minute == 0): | |
run = True | |
else: | |
run = True | |
else: | |
print("The market is currently closed.") | |
time.sleep(30) | |
if run == True: | |
stock() | |
time.sleep(30) | |
os.system('clear') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment