# Example script to pull GX data
# Please contact support@general-index.com for any questions

import generalindex as gx
import pandas as pd

# instance of GxApi
api = gx.GxApi()

# for easy viewing on local
pd.set_option('display.width', 999)
pd.set_option('display.max_colwidth', 200)
pd.set_option('display.max_columns', 30)

# retrieve all available data for yesterday
data = api.index(start_from='1d',      # number of days from today, you can remove these arguments to get
                 to='1d',              # only today's data, more info https://pypi.org/project/generalindex/
                 metadata='true'
                 ).csv()

# the retrieved data can be read as a pandas dataframe
df = pd.read_csv(data)

# storing the returned data in two dataframes, one containing index data and one containing high-low-mid data
index_data = df.loc[df['Index'].notnull()].drop(columns=['High', 'Low', 'Mid']).reset_index(drop=True)
high_low_mid_data = df.loc[df['Mid'].notnull()].drop(columns=['Index']).reset_index(drop=True)

print("Here is the retrieved index data:")
print(index_data)

print("\nHere is the retrieved high-low-mid data:")
print(high_low_mid_data)