In [2]:
    
# dev system path adjustment - normal usage would not include this cell
import sys
sys.path.insert(0, "/Users/jasonlewris/Desktop/after_hours/afterhours")
    
In [5]:
    
from afterhours import AfterHours
    
In [ ]:
    
# in packaged version, import follows:
# from afterhours.afterhours import AfterHours
    
In [6]:
    
# getting started is fairly quick. Simply specify the ticker symbol of interest 
# and pre or after hours trading when instantiating AfterHours
ticker = 'aapl'
AH = AfterHours(ticker=ticker, typeof='pre')
    
In [7]:
    
# there are several price types we can secure. This include highprice and lowprice
AH.getdata(datatype='highprice')
    
    Out[7]:
In [8]:
    
# and low price
AH.getdata(datatype='lowprice')
    
    Out[8]:
In [9]:
    
# securing volume data follows the same format as pricing
AH.getdata(datatype='volume')
    
    Out[9]:
In [10]:
    
# once again, very similar usage for time stamps
AH.getdata(datatype='hightime')
    
    Out[10]:
In [11]:
    
# and for low time
AH.getdata(datatype='lowtime')
    
    Out[11]:
In [12]:
    
# we can secure all the trading data for a specific symbol using the following
df = AH.secure_all_pages()
    
In [23]:
    
df.head()
    
    Out[23]:
In [24]:
    
# exmplore the data a bit
df.describe()
    
    Out[24]:
In [16]:
    
# to examine any cancelled trades - no cancelled trades for apple today
df[df['Cancelled'] != False]
    
    Out[16]:
In [18]:
    
# we can get the low and max trading price and volume
df['Price'].min()
    
    Out[18]:
In [19]:
    
df['Price'].max()
    
    Out[19]:
In [20]:
    
# and for volume
df['Volume'].min()
    
    Out[20]:
In [21]:
    
df['Volume'].max()
    
    Out[21]:
In [29]:
    
# lets filter out trades with less than 100 volume
df[df['Volume'] > 100]['Price'].mean()
    
    Out[29]:
In [28]:
    
df[df['Volume'] <= 100]['Price'].mean() # slightly higher average dollar value for low volume trades
    
    Out[28]:
In [22]:
    
df.head()
    
    Out[22]:
In [31]:
    
# to continuously monitor for updates during a high frequency trading time, we 
# can specify the package to run every n seconds for a maximum of num_iter times
AH.run_every(seconds=5, num_iter=2)
    
    
In [32]:
    
# and access the data directly 
AH.df.head()
    
    Out[32]: