#!/usr/bin/env python
# coding: utf-8

# Let's try to get filepath of any candlesticks file.

# In[1]:


import market_trade.constants

candlesticks_filepaths = [filepath for filepath in market_trade.src.constants.CANDLESTICK_DATASETS_PATH.iterdir()]
candlesticks_filepath = candlesticks_filepaths[0]
candlesticks_filepath


# Let's import that file to pandas

# In[2]:


import pandas as pd

# we set two rows as multiheader, and parse dates in index
candlesticks_df = pd.read_csv(candlesticks_filepath,index_col=0, header=[0,1], parse_dates=True)
candlesticks_df['date'] = candlesticks_df.index 
candlesticks_df.reset_index(inplace=True, drop=True)
ask_candlesticks_df = candlesticks_df['ask'].copy()
ask_candlesticks_df.head()


# Everything imported beatifully, let's attach the date to it 

# In[3]:


ask_candlesticks_df['date'] = candlesticks_df['date']
ask_candlesticks_df.head()


# Let's test it

# In[4]:


"""
extract from test signal file
"""
import market_trade.signals.Signal1


ind_params = {'MeanType': 'SMA', 'window': 5, 'valueType': 'low', 'kDev': 2}
# df_candle[:3000],ind_params,True,False,True
# window 5..100 (5) | valueType: 'open', 'low' | 'kdev' : 1..4 (0.1)
indEl1 = {
    'df': ask_candlesticks_df,
    'params': ind_params,
    'needFig': False,
    'showOnlyIndex': False,
    'drawFig': True
}
a = market_trade.signals.Signal1.SignalBollingerBands1({'BB': indEl1})
a.analiz


# Let's test that i didn't broke the file. Let's import test file, and compare results.
# 
# Importing

# In[5]:


test_candlesticks = pd.read_csv(market_trade.src.constants.TEST_CANDLESTICKS_PATH)
test_candlesticks['date'] = test_candlesticks['timestamp']
test_candlesticks.drop(['timestamp'], axis=1, inplace=True)
test_candlesticks.head()


# Comparing results

# In[6]:


"""
expected results
{'chstota': 0.3555926544240401,
 'zeroNum %': 0.5963272120200334,
 't %': 0.37963272120200336,
 'f %': 0.024040066777963272,
 'toch': 0.9404466501240695}
"""

import market_trade.signals.Signal1


ind_params = {'MeanType': 'SMA', 'window': 5, 'valueType': 'low', 'kDev': 2}
# df_candle[:3000],ind_params,True,False,True
# window 5..100 (5) | valueType: 'open', 'low' | 'kdev' : 1..4 (0.1)
indEl1 = {
    'df': test_candlesticks[:3000],
    'params': ind_params,
    'needFig': False,
    'showOnlyIndex': False,
    'drawFig': True
}
a = market_trade.signals.Signal1.SignalBollingerBands1({'BB': indEl1})
a.analiz


# Nice! And lets try full file

# In[16]:


ind_params = {'MeanType': 'SMA', 'window': 5, 'valueType': 'low', 'kDev': 2}
# df_candle[:3000],ind_params,True,False,True
# window 5..100 (5) | valueType: 'open', 'low' | 'kdev' : 1..4 (0.1)
indEl1 = {
    'df': test_candlesticks[:10000],
    'params': ind_params,
    'needFig': False,
    'showOnlyIndex': False,
    'drawFig': True
}
a = market_trade.signals.Signal1.SignalBollingerBands1({'BB': indEl1})
a.analiz


# Let's test our file loading

# In[8]:


candlesticks_filepaths


# Let's choose EURUSD candletsicks

# In[11]:


candlesticks_filepath = candlesticks_filepaths[5]

candlesticks_df = pd.read_csv(candlesticks_filepath,index_col=0, header=[0,1], parse_dates=True)
candlesticks_df['date'] = candlesticks_df.index 
candlesticks_df.reset_index(inplace=True, drop=True)
ask_candlesticks_df = candlesticks_df['ask'].copy()
ask_candlesticks_df['date'] = candlesticks_df['date']
ask_candlesticks_df.head()


# Let's test

# In[15]:


ind_params = {'MeanType': 'SMA', 'window': 5, 'valueType': 'low', 'kDev': 2}
indEl1 = {
    'df': ask_candlesticks_df[:10000],
    'params': ind_params,
    'needFig': False,
    'showOnlyIndex': False,
    'drawFig': True
}
a = market_trade.signals.Signal1.SignalBollingerBands1({'BB': indEl1})
a.analiz

