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

# In[8]:


import pandas as pd
import datetime
import numpy as np

import CoreTraidMath 


# In[9]:


df_candle = pd.read_csv(r"../data/EURUSD_price_candlestick.csv")
df_candle.rename(columns={'timestamp': 'date'}, inplace=True)
df_candle


# In[10]:


class coreIndicator():
    
    def __init__(self,options: dict, dataType: str = None, predictType: str = None, name: str = None):
        self.options = options
        self.dataType = dataType #ochl
        self.predictType = predictType #trend
        
    
    def getAns(self, data: pd.DataFrame() ):
        return "ERROR"


# In[11]:


class ind_BB(coreIndicator):
    """
    options
        MeanType -> SMA
        window -> int
        valueType -> str: low, high, open, close
        kDev -> float
    
    """
    
    def __init__(self,options: dict,name = None):
        super().__init__(
            options = options,
            dataType = 'ochl',
            predictType = 'trend',
            name = name
        )
    
    def getAns(self, data: pd.DataFrame()):
        data=data.reset_index(drop=True)
        ans={}
        opMA={'dataType':'ohcl',
            'action':'findMean',
            'actionOptions':{
                'MeanType':self.options['MeanType'],
                'valueType':self.options['valueType'],
                'window':self.options['window']
            }
        }
        ans['BB']=CoreTraidMath.CoreMath(data,opMA).ans
        opSTD={'dataType':'ohcl',
            'action':'findSTD',
            'actionOptions':{'valueType':self.options['valueType'],'window':self.options['window']}
        }
        ans['STD']=CoreTraidMath.CoreMath(data,opSTD).ans
        ans['pSTD']=ans['BB']+ans['STD']*self.options['kDev']
        ans['mSTD']=ans['BB']-ans['STD']*self.options['kDev']
        ans['x']=np.array(data['date'][self.options['window']-1:].to_list())
        self.ans= ans
        return ans


# In[12]:


class indicatorsAgrigator:
    
    def __init__ (self,indDict={}):
        self.indDict = indDict
        self.indInst = {}
        self.ans={}
        self.createIndicatorsInstance()
    
    def createIndicatorsInstance(self):
        for i in self.indDict.keys():
            self.indInst[i]=self.indDict[i]['className'](self.indDict[i]['params'])
            
    def getAns(self,dataDict={}):
        ans={}
        for i in dataDict.keys():
            ans[i] = self.indInst[i].getAns(dataDict[i])
        return ans


# In[13]:


indicators = {
    'ind_BB':{
        'className':ind_BB,
        'params':{'MeanType':'SMA','window':15,'valueType':'close','kDev':2.5}
    }
}
dataDic={
    'ind_BB':df_candle[:1000]
}


# In[ ]:





# In[14]:


ia= indicatorsAgrigator(indicators)


# In[15]:


ia.__dict__


# In[16]:


ia.indInst['ind_BB'].__dict__


# In[17]:


ia.getAns(dataDict=dataDic)


# In[ ]:





# In[ ]:





# In[18]:


op = {'MeanType':'SMA','window':5,'valueType':'low','kDev':2}


# In[19]:


t =  ind_BB(op)


# In[20]:


t.getAns(df_candle[:100])


# In[21]:


t.__dict__


# In[ ]:





# In[ ]:




