Skip to content

Commit

Permalink
Fixed Utils and made Tickers all UpperCase
Browse files Browse the repository at this point in the history
  • Loading branch information
arechiga-code committed Feb 2, 2018
1 parent 02e5fb9 commit 74e0f5c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2017 Alan Arechiga
Copyright 2018 Alan Arechiga

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
8 changes: 4 additions & 4 deletions invain/Advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
class Advanced(Simple):
def __init__(self, ticker, *extras):
#Check if ticker var is a list or string then set self.ticker to a list of ticker(s)
self.ticker = ticker if is_sequence(ticker) else [ticker]
self.ticker = [symbol.upper() for symbol in ticker] if is_sequence(ticker) else [ticker.upper()]

self.add_tickers(extras)
self.add_tickers([symbol.upper() for symbol in extras])

self.field = []
del Advanced.change_ticker
Expand All @@ -19,7 +19,7 @@ def change_ticker(self):

#Add Tickers to End of List, Extend Allows for ticker to be a List
def add_ticker(self, ticker):
self.ticker.extend(ticker) if is_sequence(ticker) else self.ticker.extend([ticker])
self.ticker.extend([symbol.upper() for symbol in ticker]) if is_sequence(ticker) else self.ticker.extend([ticker.upper()])

#If Someone is Sketch About Singular Form
def add_tickers(self, tickers, *extras):
Expand All @@ -28,7 +28,7 @@ def add_tickers(self, tickers, *extras):

def remove_ticker(self, ticker):
try:
if ticker in self.ticker: self.ticker.remove(ticker)
if ticker in self.ticker: self.ticker.remove(ticker.upper())
else: raise ValueError('InVaIN.Advanced() Failed to remove ticker. Ticker not found in list')
except ValueError as err:
print(err.args,"\n Non-Fatal Error")
Expand Down
9 changes: 4 additions & 5 deletions invain/History.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class History():

#Start and End are datetime objects with start being the older of the two dates.
#Frequency has three options for interval of returned dates with daily = d, weekly = wk, and monthly = mo; All options accept any number n in the form of nd, nwk, or nmo with n being the number of days, weeks, or months
def __init__(self, ticker, start=None, end=None, frequency='1d', *extras):
def __init__(self, ticker, start=None, end=None, frequency='1d'):
now = int(time.mktime(datetime.datetime.now().timetuple()))

#Check if ticker var is a list or string then set self.ticker to a list of ticker(s)
self.ticker = ticker if is_sequence(ticker) else [ticker]
self.ticker = [symbol.upper() for symbol in ticker] if is_sequence(ticker) else [ticker]

#Check if start exists - if not default start time is 30 days from now, if start exists set start to strat.
period1 = now - 30*24*60*60 if start is None else int(time.mktime(start.timetuple()))
Expand All @@ -21,14 +21,13 @@ def __init__(self, ticker, start=None, end=None, frequency='1d', *extras):
self.period = [period1, period2]

self.interval = frequency
self.add_tickers(extras)

#Grab Historical Data
self.hist_data = hist(self.ticker, self.period, self.interval)

#Add Tickers to End of List, Extend Allows for ticker to be a List
def add_ticker(self, ticker):
self.ticker.extend(ticker) if is_sequence(ticker) else self.ticker.extend([ticker])
self.ticker.extend([symbol.upper() for symbol in ticker]) if is_sequence(ticker) else self.ticker.extend([ticker.upper()])

#If Someone is Sketch About Singular Form
def add_tickers(self, tickers, *extras):
Expand All @@ -37,7 +36,7 @@ def add_tickers(self, tickers, *extras):

def remove_ticker(self, ticker):
try:
if ticker in self.ticker: self.ticker.remove(ticker)
if ticker in self.ticker: self.ticker.remove(ticker.upper())
else: raise ValueError('InVaIN.Advanced() Failed to remove ticker. Ticker not found in list')
except ValueError as err:
print(err.args,"\n Non-Fatal Error")
Expand Down
4 changes: 2 additions & 2 deletions invain/Simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def __init__(self, symbol):
try:
if is_sequence(symbol) or not isinstance(symbol, str):
raise ValueError('InVaIN.Simple() expects a string as the only parameter')
else: self.ticker = symbol
else: self.ticker = symbol.upper()
except ValueError as err:
print(err.args,"\nQuitting")
sys.exit(1)
Expand All @@ -16,7 +16,7 @@ def change_ticker(self, symbol):
try:
if is_sequence(symbol) or not isinstance(symbol, str):
raise ValueError('InVaIN.Simple() expects a string as the only parameter')
else: self.ticker = symbol
else: self.ticker = symbol.upper()
except ValueError as err:
print(err.args,"\nQuitting")
sys.exit(1)
Expand Down
11 changes: 3 additions & 8 deletions invain/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,10 @@ def hist(tickers, period, interval):

if is_sequence(tickers):
tickers = ','.join(tickers)

if is_sequence(period):
period1 = time.mktime(period[0].timetuple())
period2 = time.mktime(period[1].timetuple()) if len(period) > 1 else time.mktime(datetime.datetime.now().timetuple())
else:
period1 = time.mktime(period.timetuple())
period2 = time.mktime(datetime.datetime.now().timetuple())
period1 = period[0]
period2 = period[1]

times = str(int(period1))+','+str((int(period2)))
times = str(period1)+','+str(period2)
#Prepare the Parameters - Period 1 is oldest date - Period 2 is newest date
temp = {'t': tickers, 'times': times , 'inter' : interval}

Expand Down

0 comments on commit 74e0f5c

Please sign in to comment.