Make sure to have registered and generated an API key on https://nasdaq-cx.ticksmith.com before starting this example.
In the following code block, replace <USER_NAME> with the email you signed up with (within quotes) and <API_KEY> with the API key you generated (also within quotes). Then, to see what data you have access to, call the 'datasets' method:
In [1]:
from tickvaultpythonapi.nasdaqcxclient import NasdaqCxClient
nasdaq = NasdaqCxClient(user_name="<USER_NAME>",
secret_key="<API_KEY>")
nasdaq.datasets()
Out[1]:
To see what columns exist in that dataset and filter by, call the 'describe' method on a dataset from above:
In [2]:
nasdaq.describe('cx_hits')
Out[2]:
To access the bid and ask prices for TD quotes when the ask and bid sizes were greater than 10, we will query the HiTS dataset (and print its length to make sure we got results):
In [6]:
result = nasdaq.query_hits(source="CHIX", tickers="TD",
fields="ts,askprice,bidprice", start_time=20150302093000, end_time=20150302160000,
predicates="ask_size > 10 and bid_size > 10 and line_type like Q",
limit=1000000)
str(len(result))
Out[6]:
Let's convert the result to a pandas DataFrame for analytics:
In [7]:
df = nasdaq.as_dataframe(result)
df.info()
Now to visualise the result:
In [8]:
%matplotlib inline
df.plot()
Out[8]: