text: from trading_ig.config import config
  import logging
  
  logger = logging.getLogger(__name__)
  logger.setLevel(logging.DEBUG)
  
  # if you need to cache to DB your requests
  from datetime import timedelta
  import requests_cache
  from getting_realtime_data.data_retrieval import Data_Retrieval
  from sending_orders.order_management import Order_Management
  from management_of_position.position_management import Position_Management
  from predefined_functions.initialisation import Initialisation
  from get_data.get_market_data import Get_Market_Data
  import time
  from datetime import datetime, timedelta
  from predefined_functions.defined_functionality import Defined_Functionality
  import pandas
  import traceback
  
  # the newest one where you make market order base on price movements 5 or more and try to catch the trend
  
  class Algo0:
      def __init__(self):
          logging.basicConfig(level=logging.INFO)
          self.df = Defined_Functionality()
          # list_of_epics = [
          #                 "IX.D.SPTRD.DAILY.IP",
          #                 "IX.D.RUSSELL.DAILY.IP",
          #                 "IX.D.NASDAQ.CASH.IP",
          #                 "IX.D.DOW.DAILY.IP"]
          # # list_of_epics = [
          # #     "CS.D.ALUMINIUM.TODAY.IP",
          # #     "CS.D.AUDCAD.TODAY.IP",
          # #     "CS.D.AUDCNH.TODAY.IP",
          # #     "CS.D.AUDUSD.TODAY.IP",
          # #     "CS.D.CADCHF.TODAY.IP",
          # #     "CS.D.CADNOK.TODAY.IP",
          # #     "CS.D.CHFHUF.TODAY.IP",
          # #     "IX.D.HSCHIN.DFB.IP",
          # #     "IX.D.DEN25.DAILY.IP",
          # #     "IX.D.CAC.DAILY.IP",
          # #     "IX.D.FTSE.DAILY.IP",
          # #     "IX.D.DAX.DAILY.IP",
          # #     "IX.D.SAF.DAILY.IP",
          # #     "IX.D.SPTRD.DAILY.IP",
          # #     "IX.D.FANG.DAILY.IP",
          # #     "IX.D.RUSSELL.DAILY.IP",
          # #     "IX.D.NASDAQ.CASH.IP",
          # #     "IX.D.DOW.DAILY.IP",
          # #     "IX.D.SUNDAX.DAILY.IP",
          # #     "IX.D.SUNFUN.DAILY.IP",
          # #     "IX.D.SUNDOW.DAILY.IP"
          # # ]
  
          list_of_epics = ["EC.D.DBVFP.DAILY.IP",
                          "KA.D.3SSILN.DAILY.IP",
                          "KA.D.3SISLN.DAILY.IP",
                          "KA.D.3BALLN.DAILY.IP",
                          "KA.D.3UKLLN.DAILY.IP",
                          "KA.D.3NGLLN.DAILY.IP",
                          "ED.D.SDF.DAILY.IP",
                          "KA.D.BAY.DAILY.IP",
                          "KA.D.LUK2.DAILY.IP",
                          "KA.D.3LTSLN.DAILY.IP",
                          "KA.D.3LVOLN.DAILY.IP",
                          "KA.D.AAL.DAILY.IP",
                          "KA.D.RIO.DAILY.IP",
                          "KA.D.3LALLN.DAILY.IP",
                          "KA.D.SLLN.DAILY.IP",
                          "KA.D.3LBCLN.DAILY.IP",
                          "KA.D.GLEN.DAILY.IP",
                          "KA.D.WPP.DAILY.IP",
                          "KA.D.JMAT.DAILY.IP",
                          "ED.D.LHAG.DAILY.IP",
                          "KA.D.EZJ.DAILY.IP",
                          "KA.D.ECLNGA.DAILY.IP",
                          "KA.D.PPBLN.DAILY.IP",
                          "KA.D.LQQ3LN.DAILY.IP",
                          "KA.D.3LAZLN.DAILY.IP",
                          "KA.D.2TSLLN.DAILY.IP",
                          "EG.D.LIGHTNA.DAILY.IP",
                          "EG.D.ABNNA.DAILY.IP",
                          "KA.D.3LBPLN.DAILY.IP",
                          "KB.D.MINING.DAILY.IP",
                          "KA.D.BLT.DAILY.IP",
                          "KA.D.SSE.DAILY.IP",
                          "EE.D.PAP.DAILY.IP",
                          "KA.D.XSPRLN.DAILY.IP",
                          "KA.D.DCCLN.DAILY.IP",
                          "KA.D.TFILN.DAILY.IP",
                          "KA.D.LGEN.DAILY.IP",
                          "KA.D.BLND.DAILY.IP",
                          "KA.D.JD.DAILY.IP",
                          "KA.D.UU.DAILY.IP",
                          "EC.D.GLEFP.DAILY.IP",
                          "EC.D.CS.DAILY.IP",
                          "KA.D.WTB.DAILY.IP",
                          "ED.D.ALVGY.DAILY.IP",
                          "KA.D.RR.DAILY.IP",
                          "EC.D.ACCP.DAILY.IP",
                          "KA.D.QQQ3LN.DAILY.IP",
                          "KA.D.3LDOLN.DAILY.IP",
                          "SA.D.AIG.DAILY.IP",
                          "ED.D.SXPPEX.DAILY.IP",
                          "KA.D.SN.DAILY.IP",
                          "KA.D.AV.DAILY.IP",
                          "KA.D.MNDI.DAILY.IP",
                          "KA.D.RTO.DAILY.IP",
                          "KA.D.REL.DAILY.IP",
                          "KA.D.EXPN.DAILY.IP",
                          "KA.D.HSBA.DAILY.IP",
                          "EC.D.BREFP.DAILY.IP",
                          "KA.D.BT.DAILY.IP",
                          "KA.D.BNCLN.DAILY.IP",
                          "KA.D.ITRK.DAILY.IP",
                          "EC.D.DGFP.DAILY.IP",
                          "EC.D.KNFP.DAILY.IP",
                          "KA.D.ANTO.DAILY.IP",
                          "EG.D.AEGN.DAILY.IP",
                          "KA.D.3LDELN.DAILY.IP",
                          "KA.D.LAND.DAILY.IP",
                          "KA.D.CMX1LN.DAILY.IP",
                          "KA.D.BATS.DAILY.IP",
                          "KA.D.RDSB.DAILY.IP",
                          "KA.D.S7XPLN.DAILY.IP",
                          "KB.D.MEDIA.DAILY.IP",
                          "KA.D.EVRLN.DAILY.IP",
                          "EG.D.ING.DAILY.IP",
                          "KA.D.SMIN.DAILY.IP",
                          "KA.D.CRHLN.DAILY.IP",
                          "KB.D.TOBACCO.DAILY.IP",
                          "KA.D.CPG.DAILY.IP",
                          "KA.D.SMDS.DAILY.IP",
                          "KA.D.RDSA.DAILY.IP",
                          "KB.D.LIFE.DAILY.IP",
                          "ED.D.TKAG.DAILY.IP",
                          "EA.D.KBCBB.DAILY.IP",
                          "KA.D.3DELLN.DAILY.IP",
                          "KA.D.3EULLN.DAILY.IP",
                          "ED.D.SX7EEX.DAILY.IP",
                          "KA.D.3LZNLN.DAILY.IP",
                          "KA.D.TSCO.DAILY.IP",
                          "ED.D.BAY.DAILY.IP",
                          "KA.D.CB5LN.DAILY.IP",
                          "KA.D.HLMA.DAILY.IP",
                          "UD.D.TQQQUS.DAILY.IP",
                          "KA.D.ECSSIL.DAILY.IP",
                          "KA.D.GSK.DAILY.IP",
                          "KA.D.ABF.DAILY.IP",
                          "EJ.D.SLHN.DAILY.IP",
                          "KA.D.PRU.DAILY.IP",
                          "KA.D.PSRULN.DAILY.IP",
                          "KB.D.HOTELS.DAILY.IP",
                          "EG.D.APAM.DAILY.IP",
                          "ED.D.S7XEGY.DAILY.IP",
                          "KA.D.LLOY.DAILY.IP",
                          "KA.D.III.DAILY.IP",
                          "EG.D.RDSBNA.DAILY.IP",
                          "KA.D.HUKXLN.DAILY.IP",
                          "KA.D.S100LN.DAILY.IP",
                          "KA.D.CUKXLN.DAILY.IP",
                          "KA.D.L100LN.DAILY.IP",
                          "EC.D.LQQFP.DAILY.IP",
                          "KA.D.UB03LN.DAILY.IP",
                          "EC.D.GSZFP.DAILY.IP",
                          "KB.D.BANKS.DAILY.IP",
                          "KA.D.LGUKLN.DAILY.IP",
                          "KA.D.VUKELN.DAILY.IP",
                          "KA.D.ISF.DAILY.IP",
                          "KA.D.STAN.DAILY.IP",
                          "ED.D.CBK.DAILY.IP",
                          "EE.D.CRH.DAILY.IP",
                          "ED.D.SXIPEXGY.DAILY.IP",
                          "ED.D.CEM2GY.DAILY.IP",
                          "EG.D.ULNA.DAILY.IP",
                          "EC.D.LIFP.DAILY.IP",
                          "KA.D.HL.DAILY.IP",
                          "KA.D.VUKGLN.JUN.IP",
                          "KA.D.CWFGLN.DAILY.IP",
                          "KA.D.PNN.DAILY.IP",
                          "ED.D.SX7PEX.DAILY.IP",
                          "KB.D.BUILD.DAILY.IP",
                          "KB.D.GINDU.DAILY.IP",
                          "KA.D.CS1LN.DAILY.IP",
                          "KA.D.2AMZLN.DAILY.IP",
                          "EC.D.BNPP.DAILY.IP",
                          "KA.D.PSON.DAILY.IP",
                          "KA.D.SPAGLN.DAILY.IP",
                          "KB.D.OIL.DAILY.IP",
                          "ED.D.MUV2.DAILY.IP",
                          "KA.D.3USLLN.DAILY.IP",
                          "KA.D.MNGLN.DAILY.IP",
                          "KA.D.X7PSLN.DAILY.IP",
                          "EG.D.ASRNLNA.DAILY.IP",
                          "EC.D.EXHO.DAILY.IP",
                          "EC.D.ACA.DAILY.IP",
                          "KA.D.DL2PLN.DAILY.IP",
                          "KA.D.ANRJLN.DAILY.IP",
                          "KA.D.XLDXLN.DAILY.IP",
                          "KA.D.LCUKLN.DAILY.IP",
                          "KA.D.FTADLN.DAILY.IP",
                          "KA.D.BDEV.DAILY.IP",
                          "ED.D.DBK.DAILY.IP",
                          "KA.D.BARC.DAILY.IP",
                          "EC.D.BNKFP.DAILY.IP",
                          "KA.D.BYBGLN.DAILY.IP",
                          "KA.D.NXT.DAILY.IP",
                          "EG.D.RDSANA.DAILY.IP",
                          "KB.D.FDR.DAILY.IP",
                          "EC.D.SU.DAILY.IP",
                          "KA.D.SDR.DAILY.IP",
                          "ED.D.TOTBGY.DAILY.IP",
                          "KA.D.HIK.DAILY.IP",
                          "EC.D.FP.DAILY.IP",
                          "KA.D.IMT.DAILY.IP",
                          "ED.D.SXRWGY.DAILY.IP",
                          "ED.D.LINGY.DAILY.IP",
                          "KA.D.IUKD.DAILY.IP",
                          "KB.D.SUPPORT.DAILY.IP",
                          "ED.D.DJDVPEXGY.DAILY.IP",
                          "EJ.D.CSGN.DAILY.IP",
                          "KB.D.AERO.DAILY.IP",
                          "EC.D.EN.DAILY.IP",
                          "ED.D.TL0GY.DAILY.IP",
                          "KA.D.XLKQLN.DAILY.IP",
                          "KA.D.MRW.DAILY.IP",
                          "KA.D.XLBPLN.DAILY.IP",
                          "ED.D.RWEG.DAILY.IP",
                          "EJ.D.SREN.DAILY.IP",
                          "KA.D.WFINLN.DAILY.IP",
                          "EA.D.UMIBB.DAILY.IP",
                          "ED.D.SX6PEXGY.DAILY.IP",
                          "UD.D.TSLA.DAILY.IP",
                          "ED.D.AMESGY.DAILY.IP",
                          "EC.D.FGR.DAILY.IP",
                          "KA.D.BWY.DAILY.IP",
                          "KB.D.EE.DAILY.IP",
                          "KA.D.RB.DAILY.IP",
                          "KA.D.OCDO.DAILY.IP",
                          "KA.D.GVC.DAILY.IP",
                          "KB.D.SPECFINAN.DAILY.IP",
                          "EC.D.LVE.DAILY.IP",
                          "KA.D.IDJV.DAILY.IP",
                          "KA.D.RSVLLN.DAILY.IP",
                          "KA.D.MIBXLN.DAILY.IP",
                          "KA.D.WOS.DAILY.IP",
                          "ED.D.LEVDAX.DAILY.IP",
                          "KA.D.CNX1LN.DAILY.IP",
                          "KA.D.IMIBLN.DAILY.IP",
                          "IX.D.SUNDOW.DAILY.IP",
                          "EJ.D.HOLVX.DAILY.IP",
                          "KA.D.IEFVLN.DAILY.IP",
                          "KA.D.CMB1LN.DAILY.IP",
                          "KA.D.XRSGLN.DAILY.IP",
                          "KA.D.EQQQLN.DAILY.IP",
                          "KA.D.XLFSLN.DAILY.IP",
                          "KA.D.VOD.DAILY.IP",
                          "KB.D.CHEMS.DAILY.IP",
                          "KA.D.EUDVLN.DAILY.IP",
                          "KA.D.SGVLLN.DAILY.IP",
                          "EJ.D.ZURZ.DAILY.IP",
                          "KA.D.ULVR.DAILY.IP",
                          "KA.D.BA.DAILY.IP",
                          "KB.D.WATER.DAILY.IP",
                          "KA.D.IHG.DAILY.IP",
                          "KA.D.AMZ2LN.DAILY.IP",
                          "KB.D.HSEHLD.DAILY.IP",
                          "KB.D.PGOODS.DAILY.IP",
                          "KA.D.LSE.DAILY.IP",
                          "KB.D.PHARMA.DAILY.IP",
                          "KA.D.3LFBLN.DAILY.IP",
                          "EG.D.NN.DAILY.IP",
                          "ED.D.EOA.DAILY.IP",
                          "KA.D.SKYPLN.DAILY.IP",
                          "SI.D.SPY.DAILY.IP",
                          "EC.D.LRFP.DAILY.IP",
                          "KA.D.XS2DLN.DAILY.IP",
                          "ED.D.BAS.DAILY.IP",
                          "ED.D.XDW0GY.DAILY.IP",
                          "KA.D.RBS.DAILY.IP",
                          "EC.D.ALS.DAILY.IP",
                          "KA.D.SMRGLN.DAILY.IP",
                          "KA.D.STJ.DAILY.IP",
                          "EC.D.SGO.DAILY.IP",
                          "KA.D.TWLN.DAILY.IP",
                          "ED.D.2B78GY.DAILY.IP",
                          "KA.D.2MSFLN.DAILY.IP",
                          "ED.D.SXRYGY.DAILY.IP",
                          "KA.D.IUSA.DAILY.IP",
                          "ED.D.GOAIGY.DAILY.IP",
                          "KA.D.GLUGLN.DAILY.IP",
                          "KA.D.HSPXLN.DAILY.IP",
                          "KA.D.CSP1LN.DAILY.IP",
                          "KA.D.SPX5LN.DAILY.IP",
                          "KA.D.AUTOLN.DAILY.IP",
                          "KA.D.BP.DAILY.IP",
                          "KA.D.JETLN.DAILY.IP",
                          "EC.D.CA.DAILY.IP",
                          "KA.D.VUSALN.DAILY.IP",
                          "KA.D.3LMSLN.DAILY.IP",
                          "KA.D.IWRD.DAILY.IP",
                          "KA.D.LGUGLN.DAILY.IP",
                          "ED.D.SXEPEXGY.DAILY.IP",
                          "KA.D.IESGLN.DAILY.IP",
                          "KA.D.BKGLN.DAILY.IP",
                          "ED.D.SIEGn.DAILY.IP",
                          "ED.D.CEMSGY.DAILY.IP",
                          "KA.D.AZN.DAILY.IP",
                          "KA.D.MEUGLN.DAILY.IP",
                          "KA.D.IEVLLN.DAILY.IP",
                          "KA.D.EUE.DAILY.IP",
                          "KA.D.FRES.DAILY.IP",
                          "KA.D.XESXLN.DAILY.IP",
                          "KA.D.XESCLN.DAILY.IP",
                          "KA.D.H50ELN.DAILY.IP",
                          "KA.D.2AAPLN.DAILY.IP",
                          "KA.D.XSKRLN.DAILY.IP",
                          "KA.D.MXEULN.DAILY.IP",
                          "KA.D.SX5SLN.DAILY.IP",
                          "KA.D.SMEALN.DAILY.IP",
                          "KA.D.NGT.DAILY.IP",
                          "KA.D.SSACLN.DAILY.IP",
                          "KA.D.LCWLLN.DAILY.IP",
                          "KA.D.LGGGLN.DAILY.IP",
                          "KA.D.HMEULN.DAILY.IP",
                          "KA.D.CS51LN.DAILY.IP",
                          "EC.D.PUB.DAILY.IP",
                          "KA.D.CG1LN.DAILY.IP",
                          "KA.D.DAXXLN.DAILY.IP",
                          "KA.D.MEUDLN.DAILY.IP",
                          "ED.D.XGSDGY.DAILY.IP",
                          "KA.D.WLDLLN.DAILY.IP",
                          "KA.D.MSEDLN.DAILY.IP",
                          "KA.D.UC44LN.DAILY.IP",
                          "KA.D.SAUSLN.DAILY.IP",
                          "KA.D.XDDXLN.DAILY.IP",
                          "KA.D.S600LN.DAILY.IP",
                          "KA.D.XRSSLN.DAILY.IP",
                          "KA.D.XSX6LN.DAILY.IP",
                          "KA.D.3SOILN.DAILY.IP",
                          "KA.D.ACWILN.DAILY.IP",
                          "KA.D.EMUDLN.DAILY.IP",
                          "KA.D.PSN.DAILY.IP",
                          "EG.D.UN.DAILY.IP",
                          "KA.D.XMAWLN.DAILY.IP",
                          "KA.D.CSCALN.DAILY.IP",
                          "KA.D.BRBY.DAILY.IP",
                          "KA.D.UC99LN.DAILY.IP",
                          "KA.D.VWRLLN.DAILY.IP",
                          "KA.D.XEUMLN.DAILY.IP",
                          "ED.D.WDNRGY.DAILY.IP",
                          "ED.D.VODIGY.DAILY.IP",
                          "KA.D.IEFSLN.DAILY.IP",
                          "KA.D.EUP3LN.DAILY.IP",
                          "KA.D.VWRPLN.DAILY.IP",
                          "EC.D.LVCFP.DAILY.IP",
                          "EA.D.FOR.DAILY.IP",
                          "KA.D.3LNVLN.DAILY.IP",
                          "ED.D.SAPG.DAILY.IP",
                          "KA.D.SXLKLN.DAILY.IP",
                          "KA.D.XLUPLN.DAILY.IP",
                          "KA.D.DH2OLN.DAILY.IP",
                          "KA.D.LGAGLN.DAILY.IP",
                          "KA.D.RSGLLN.DAILY.IP",
                          "ED.D.KBXGY.DAILY.IP",
                          "KA.D.MGGT.DAILY.IP",
                          "KA.D.3LAPLN.DAILY.IP",
                          "KA.D.RMV.DAILY.IP",
                          "ED.D.ZALGY.DAILY.IP",
                          "KA.D.CPJ1LN.DAILY.IP",
                          "EC.D.FTIFP.DAILY.IP",
                          "EC.D.GAFP.DAILY.IP",
                          "KA.D.XDJPLN.DAILY.IP",
                          "KA.D.IUSULN.DAILY.IP",
                          "KA.D.LGEGLN.DAILY.IP",
                          "KA.D.DGE.DAILY.IP",
                          "KA.D.SPXJLN.DAILY.IP",
                          "KA.D.DLTMLN.DAILY.IP",
                          "ED.D.SPYDGR.DAILY.IP",
                          "KA.D.ISFRLN.DAILY.IP",
                          "KA.D.FSEULN.DAILY.IP",
                          "ED.D.D500GY.DAILY.IP",
                          "KA.D.ANXULN.DAILY.IP",
                          "ED.D.RYS1GY.JUN.IP",
                          "KA.D.SCOP.DAILY.IP",
                          "KA.D.EFIELN.DAILY.IP",
                          "KB.D.DRINKS.DAILY.IP",
                          "KA.D.DJMC.DAILY.IP",
                          "KA.D.MROLN.DAILY.IP",
                          "KA.D.IINDLN.DAILY.IP",
                          "KA.D.VAPXLN.DAILY.IP",
                          "KA.D.IEUXLN.DAILY.IP",
                          "EC.D.500FP.DAILY.IP",
                          "ED.D.SXR8GY.DAILY.IP",
                          "ED.D.XMEUGY.DAILY.IP",
                          "KA.D.KGF.DAILY.IP",
                          "EG.D.CSPXNA.DAILY.IP",
                          "KA.D.JPNYLN.DAILY.IP",
                          "KA.D.SJPALN.DAILY.IP",
                          "EA.D.UCBBB.DAILY.IP",
                          "KA.D.CACXLN.DAILY.IP",
                          "KA.D.XLEPLN.DAILY.IP",
                          "KA.D.RTYSLN.DAILY.IP",
                          "KA.D.S400LN.DAILY.IP",
                          "KA.D.MINVLN.DAILY.IP",
                          "KA.D.RTWOLN.DAILY.IP",
                          "EG.D.VUSANA.DAILY.IP",
                          "EC.D.CU2FP.DAILY.IP",
                          "KA.D.JPXGLN.DAILY.IP",
                          "EG.D.TKWYNA.DAILY.IP",
                          "KA.D.JPNLLN.DAILY.IP",
                          "KA.D.LGJGLN.DAILY.IP",
                          "KA.D.R2USLN.DAILY.IP",
                          "KA.D.BNZL.DAILY.IP",
                          "ED.D.SX4PEXGY.DAILY.IP",
                          "ED.D.SX5EEX.DAILY.IP",
                          "ED.D.E901GY.DAILY.IP",
                          "KA.D.VERXLN.DAILY.IP",
                          "ED.D.CEBPGY.DAILY.IP",
                          "ED.D.SXRPEXGY.DAILY.IP",
                          "ED.D.SXXPIEXGY.DAILY.IP",
                          "KA.D.MSEXLN.DAILY.IP",
                          "ED.D.HEI.DAILY.IP",
                          "ED.D.DXETGY.DAILY.IP",
                          "ED.D.ADSGY.DAILY.IP",
                          "EC.D.CW8FP.DAILY.IP",
                          "ED.D.XESXGY.DAILY.IP",
                          "EC.D.MSEFP.DAILY.IP",
                          "KA.D.CI2GLN.DAILY.IP",
                          "EC.D.AF.DAILY.IP",
                          "EG.D.IWDANA.DAILY.IP",
                          "ED.D.EUN2GY.DAILY.IP",
                          "KA.D.XDWTLN.DAILY.IP",
                          "KA.D.WTECLN.DAILY.IP",
                          "KA.D.MSEULN.DAILY.IP",
                          "ED.D.IQQW.DAILY.IP",
                          "KA.D.CSX5LN.DAILY.IP",
                          "ED.D.FREGY.DAILY.IP",
                          "KA.D.ROAILN.DAILY.IP",
                          "EG.D.VEURNA.DAILY.IP",
                          "KA.D.JPHGLN.DAILY.IP",
                          "ED.D.XDAXGY.DAILY.IP",
                          "ED.D.DAXEX.DAILY.IP",
                          "KA.D.XMEMLN.DAILY.IP",
                          "KA.D.CEULN.DAILY.IP",
                          "KA.D.IMVLN.DAILY.IP",
                          "KA.D.EDG2LN.DAILY.IP",
                          "ED.D.CEMTGY.DAILY.IP",
                          "KA.D.IGWDLN.DAILY.IP",
                          "EA.D.INTB.DAILY.IP",
                          "KA.D.IEEM.DAILY.IP",
                          "KA.D.XLPPLN.DAILY.IP",
                          "ED.D.NS4EGY.DAILY.IP",
                          "KA.D.SMRULN.DAILY.IP",
                          "EC.D.ECNFP.DAILY.IP",
                          "ED.D.XD5EGY.DAILY.IP",
                          "KA.D.CP9GLN.DAILY.IP",
                          "KA.D.UB0CLN.DAILY.IP",
                          "ED.D.JPNHGY.DAILY.IP",
                          "UC.D.QQQ.DAILY.IP",
                          "KA.D.IJPELN.DAILY.IP",
                          "KA.D.EMVLN.DAILY.IP",
                          "KA.D.XD5SLN.DAILY.IP",
                          "EG.D.EUEANA.DAILY.IP",
                          "KA.D.JPXXLN.DAILY.IP",
                          "KA.D.LSPULN.DAILY.IP",
                          "KA.D.XD9ULN.DAILY.IP",
                          "KA.D.IESZLN.DAILY.IP",
                          "KA.D.JPXULN.DAILY.IP",
                          "KA.D.CEA1LN.DAILY.IP",
                          "KA.D.XD5DLN.DAILY.IP",
                          "ED.D.HEN3.DAILY.IP",
                          "KA.D.UDVDLN.DAILY.IP",
                          "KA.D.XDPGLN.DAILY.IP",
                          "KA.D.SGROLN.DAILY.IP",
                          "ED.D.SXNPEXGY.DAILY.IP",
                          "KA.D.USAULN.DAILY.IP",
                          "KA.D.INRLLN.DAILY.IP",
                          "KA.D.CSPXLN.DAILY.IP",
                          "KA.D.USEFLN.DAILY.IP",
                          "ED.D.IS3GGY.DAILY.IP",
                          "KA.D.SPY5LN.DAILY.IP",
                          "KA.D.IGUSLN.DAILY.IP",
                          "KA.D.VUSDLN.DAILY.IP",
                          "KA.D.IUSELN.DAILY.IP",
                          "ED.D.FB2AGY.DAILY.IP",
                          "KA.D.SPXSLN.DAILY.IP",
                          "EC.D.DANO.DAILY.IP",
                          "KA.D.GSPXLN.DAILY.IP",
                          "KA.D.IJPHLN.DAILY.IP",
                          "KA.D.LCUDLN.DAILY.IP",
                          "KA.D.AWSGLN.DAILY.IP",
                          "KA.D.MXUSLN.DAILY.IP",
                          "KB.D.MID250.DAILY.IP",
                          "KA.D.ITWN.DAILY.IP",
                          "ED.D.SHLGY.DAILY.IP",
                          "ED.D.IS3UGY.DAILY.IP",
                          "ED.D.SXR1GY.DAILY.IP",
                          "KA.D.ACWDLN.DAILY.IP",
                          "KA.D.IWQULN.DAILY.IP",
                          "EJ.D.UBSGVX.DAILY.IP",
                          "KA.D.IDJG.DAILY.IP",
                          "KA.D.AAP2LN.DAILY.IP",
                          "ED.D.MSFGY.DAILY.IP",
                          "KA.D.IFFF.DAILY.IP",
                          "KA.D.IFSELN.DAILY.IP",
                          "KA.D.MXWOLN.DAILY.IP",
                          "KA.D.IEFMLN.DAILY.IP",
                          "KA.D.XDWDLN.DAILY.IP",
                          "KA.D.CH5LN.DAILY.IP",
                          "KA.D.3OISLN.DAILY.IP",
                          "KA.D.CINDLN.DAILY.IP",
                          "KA.D.WLDDLN.DAILY.IP",
                          "ED.D.LUKGY.DAILY.IP",
                          "KA.D.DJEULN.DAILY.IP",
                          "KA.D.IBCILN.DAILY.IP",
                          "EC.D.JPNFP.DAILY.IP",
                          "KA.D.CRDA.DAILY.IP",
                          "KA.D.IBTSLN.DAILY.IP",
                          "ED.D.XDEBGY.DAILY.IP",
                          "ED.D.APCGY.DAILY.IP",
                          "EG.D.IAEXNA.DAILY.IP",
                          "KA.D.3BRSLN.DAILY.IP",
                          "KA.D.TP05LN.DAILY.IP",
                          "KA.D.FEDGLN.DAILY.IP",
                          "KA.D.CU71LN.DAILY.IP",
                          "KA.D.VWRDLN.DAILY.IP",
                          "KA.D.CU31LN.DAILY.IP",
                          "EC.D.CACFP.DAILY.IP",
                          "KA.D.FRUCLN.DAILY.IP",
                          "KA.D.U13GLN.DAILY.IP",
                          "EC.D.SESG.DAILY.IP",
                          "KA.D.ISACLN.DAILY.IP",
                          "KA.D.AHT.DAILY.IP",
                          "KA.D.MTIXLN.DAILY.IP",
                          "EG.D.VERXNA.DAILY.IP",
                          "KA.D.HSPDLN.DAILY.IP",
                          "EC.D.EAD.DAILY.IP",
                          "ED.D.EADGY.DAILY.IP",
                          "ED.D.LCUJGY.DAILY.IP",
                          "EC.D.C40FP.DAILY.IP",
                          "KA.D.CRU1LN.DAILY.IP",
                          "EC.D.STM.DAILY.IP",
                          "KA.D.IBGZLN.DAILY.IP",
                          "KA.D.RIOULN.DAILY.IP",
                          "EG.D.GLPGNA.DAILY.IP",
                          "KA.D.IEERLN.DAILY.IP",
                          "KA.D.IBTMLN.DAILY.IP",
                          "KA.D.MVEDLN.DAILY.IP",
                          "ED.D.SXQPEXGY.DAILY.IP",
                          "ED.D.DB1.DAILY.IP",
                          "ED.D.DTE.DAILY.IP",
                          "SI.D.SVXYUS.DAILY.IP",
                          "PO.D.GALPPL.DAILY.IP",
                          "KA.D.MTXXLN.DAILY.IP",
                          "ED.D.IS3NGY.DAILY.IP",
                          "EC.D.HSIFP.DAILY.IP",
                          "KA.D.IBGMLN.DAILY.IP",
                          "KA.D.SEAGLN.DAILY.IP",
                          "EG.D.INFRNA.DAILY.IP",
                          "KA.D.CRPXLN.DAILY.IP",
                          "EG.D.EMIMNA.DAILY.IP",
                          "ED.D.XMJPGY.DAILY.IP",
                          "KA.D.INVP.DAILY.IP",
                          "EC.D.AEEMFP.DAILY.IP",
                          "KA.D.SDEULN.DAILY.IP",
                          "ED.D.DPW.DAILY.IP",
                          "EG.D.IEMMNA.DAILY.IP",
                          "KA.D.CECDLN.DAILY.IP",
                          "KA.D.IPXJLN.DAILY.IP",
                          "ED.D.SPYCGY.DAILY.IP",
                          "KA.D.IBGYLN.DAILY.IP",
                          "CC.D.LCO.USS.IP",
                          "KA.D.DISWLN.DAILY.IP",
                          "EC.D.LEMFP.DAILY.IP",
                          "EJ.D.NOV.DAILY.IP",
                          "KA.D.IBGSLN.DAILY.IP",
                          "KA.D.SXLELN.DAILY.IP",
                          "EC.D.WLNFP.DAILY.IP",
                          "KA.D.JPX4LN.DAILY.IP",
                          "EC.D.AKEFP.DAILY.IP",
                          "EC.D.EF.DAILY.IP",
                          "ED.D.FRAGY.DAILY.IP",
                          "KA.D.IEMOLN.DAILY.IP",
                          "KA.D.IDINLN.DAILY.IP",
                          "CC.D.LSU.USS.IP",
                          "EJ.D.CSSMI.DAILY.IP",
                          "EG.D.WLSNC.DAILY.IP",
                          "ED.D.CEMRGY.DAILY.IP",
                          "EG.D.TPSANA.DAILY.IP",
                          "CC.D.SM.USS.IP",
                          "ED.D.RHM.DAILY.IP",
                          "KA.D.FXC.DAILY.IP",
                          "KA.D.GBCHLN.DAILY.IP",
                          "ED.D.SXDPEX.DAILY.IP",
                          "EC.D.AI.DAILY.IP",
                          "KA.D.MCRO.DAILY.IP",
                          "KA.D.SBRT.DAILY.IP",
                          "KA.D.AEJLN.DAILY.IP",
                          "KA.D.EIMILN.DAILY.IP",
                          "KA.D.ECSOIL.DAILY.IP",
                          "KA.D.CCLLN.DAILY.IP",
                          "KA.D.IDEM.DAILY.IP",
                          "KA.D.COUKLN.DAILY.IP",
                          "KA.D.AUEMLN.DAILY.IP",
                          "KA.D.ECSUGA.DAILY.IP",
                          "ED.D.PUM.DAILY.IP",
                          "EC.D.ERFFP.DAILY.IP",
                          "ED.D.PSMGY.DAILY.IP",
                          "KA.D.VDEMLN.DAILY.IP",
                          "ED.D.LXS.DAILY.IP",
                          "KA.D.GLTLLN.DAILY.IP",
                          "KA.D.IEMALN.DAILY.IP",
                          "ED.D.LYXRUSGY.DAILY.IP",
                          "EG.D.PHG.DAILY.IP",
                          "EC.D.ASIFP.DAILY.IP",
                          "KA.D.ECCOTN.DAILY.IP",
                          "KA.D.ENEFLN.DAILY.IP",
                          "KA.D.EMMVLN.DAILY.IP",
                          "KA.D.SAEMLN.DAILY.IP",
                          "KA.D.TUILN.DAILY.IP",
                          "EC.D.PP.DAILY.IP",
                          "EG.D.DSMNA.DAILY.IP",
                          "KA.D.GILSLN.DAILY.IP",
                          "CC.D.DX.USS.IP",
                          "KA.D.IKSALN.DAILY.IP",
                          "EC.D.ATOFP.DAILY.IP",
                          "IR.D.FLG.Month2.IP",
                          "ED.D.MOR.DAILY.IP",
                          "KA.D.POLY.DAILY.IP",
                          "ED.D.EUN3GY.DAILY.IP",
                          "EG.D.MTNA.DAILY.IP",
                          "ED.D.DHERGY.DAILY.IP",
                          "EC.D.RMSFP.DAILY.IP",
                          "ED.D.XS3RGY.DAILY.IP",
                          "KA.D.ROLGLN.DAILY.IP",
                          "EC.D.FOOFP.DAILY.IP",
                          "EG.D.HEIA.DAILY.IP",
                          "KA.D.GILILN.DAILY.IP",
                          "ED.D.BEI.DAILY.IP",
                          "CC.D.CT.USS.IP",
                          "KA.D.ASIULN.DAILY.IP",
                          "ED.D.SX8PEXGY.DAILY.IP",
                          "KA.D.COMMLN.DAILY.IP",
                          "ED.D.IFX.DAILY.IP",
                          "KA.D.CSRULN.DAILY.IP",
                          "KA.D.WCOGLN.DAILY.IP",
                          "KA.D.CBU0LN.DAILY.IP",
                          "KA.D.IDEELN.DAILY.IP",
                          "KA.D.ECHEAT.DAILY.IP",
                          "KA.D.XSPSLN.DAILY.IP",
                          "EC.D.DSBFP.DAILY.IP",
                          "KA.D.AGAPLN.DAILY.IP",
                          "MT.D.PL.Month2.IP",
                          "KA.D.EMLBLN.DAILY.IP",
                          "KA.D.PCRDLN.DAILY.IP",
                          "EC.D.OR.DAILY.IP",
                          "EC.D.EEEFP.DAILY.IP",
                          "KA.D.3GISLN.DAILY.IP",
                          "KA.D.PBRTLN.DAILY.IP",
                          "KA.D.AGGPLN.DAILY.IP",
                          "KA.D.CSHDLN.DAILY.IP",
                          "KA.D.LEEDLN.DAILY.IP",
                          "KA.D.XCT9LN.DAILY.IP",
                          "KA.D.ECCRUD.DAILY.IP",
                          "KA.D.ECZINC.DAILY.IP",
                          "KA.D.SSXFLN.DAILY.IP",
                          "EC.D.ALGAUFP.DAILY.IP",
                          "ED.D.AT1GY.DAILY.IP",
                          "ED.D.DLGGY.DAILY.IP",
                          "KA.D.BRNTLN.DAILY.IP",
                          "EG.D.AKZO.DAILY.IP",
                          "ED.D.IS04GY.DAILY.IP",
                          "ED.D.TUI.DAILY.IP",
                          "KA.D.FCRULN.DAILY.IP",
                          "EJ.D.ROG.DAILY.IP",
                          "EC.D.HOFP.DAILY.IP",
                          "EC.D.UBI.DAILY.IP",
                          "EC.D.SAFFP.DAILY.IP",
                          "UA.D.AAPL.DAILY.IP",
                          "CC.D.W.USS.IP",
                          "KA.D.ECLOIL.DAILY.IP",
                          "KA.D.LBRTLN.DAILY.IP",
                          "EG.D.ASML.DAILY.IP",
                          "EC.D.RI.DAILY.IP",
                          "KA.D.IDTLLN.DAILY.IP",
                          "EC.D.SASY.DAILY.IP",
                          "KA.D.LPETLN.DAILY.IP",
                          "EJ.D.NESN.DAILY.IP",
                          "EC.D.CAPFP.DAILY.IP",
                          "ED.D.FR6GY.DAILY.IP",
                          "ED.D.QIA.DAILY.IP",
                          "KA.D.FAGRLN.DAILY.IP",
                          "EG.D.PRXNA.DAILY.IP",
                          "EC.D.MCA.DAILY.IP",
                          "KA.D.PIMTLN.DAILY.IP",
                          "KA.D.SPDMLN.DAILY.IP",
                          "KA.D.XFRMLN.DAILY.IP",
                          "ED.D.XSSXGY.DAILY.IP",
                          "KA.D.SPPPLN.DAILY.IP",
                          "KA.D.ECBULL.DAILY.IP",
                          "EC.D.RCFFP.DAILY.IP",
                          "EG.D.ASMNA.DAILY.IP",
                          "EJ.D.CFRVX.DAILY.IP",
                          "CO.D.CFI.Month3.IP",
                          "KA.D.GBSSLN.DAILY.IP",
                          "KA.D.SGLNLN.DAILY.IP",
                          "KA.D.ECPHGP.DAILY.IP",
                          "KA.D.SGLPLN.DAILY.IP",
                          "KA.D.3SFBLN.DAILY.IP",
                          "KA.D.IRSALN.DAILY.IP",
                          "EC.D.DSY.DAILY.IP",
                          "EC.D.BX4FP.DAILY.IP",
                          "ED.D.MTX.DAILY.IP",
                          "KA.D.SUD5LN.DAILY.IP",
                          "EJ.D.ZGLDSW.DAILY.IP",
                          "KA.D.LNIKLN.DAILY.IP",
                          "KA.D.XSD2LN.DAILY.IP",
                          "KA.D.DS2PLN.DAILY.IP",
                          "EJ.D.ZGLDEU.DAILY.IP",
                          "MT.D.PA.Month2.IP",
                          "KA.D.SPGPLN.DAILY.IP",
                          "KA.D.EGLNLN.DAILY.IP",
                          "EG.D.PHAUNA.DAILY.IP",
                          "KA.D.PHPT.DAILY.IP",
                          "ED.D.XAD5GY.DAILY.IP",
                          "KA.D.XPLALN.DAILY.IP",
                          "KA.D.GDGBLN.DAILY.IP",
                          "KA.D.XT2DLN.DAILY.IP",
                          "MT.D.SI.Month1.IP",
                          "EJ.D.ZGLDUS.DAILY.IP",
                          "KA.D.XGLSLN.DAILY.IP",
                          "ED.D.DWNIGY.DAILY.IP",
                          "EG.D.ADYENNA.DAILY.IP",
                          "KA.D.XGLDLN.DAILY.IP",
                          "KA.D.GBS.DAILY.IP",
                          "KA.D.ECPHAU.DAILY.IP",
                          "KA.D.PHSPLN.DAILY.IP",
                          "KA.D.IGLNLN.DAILY.IP",
                          "ED.D.LEGGY.DAILY.IP",
                          "KA.D.SLVPLN.DAILY.IP",
                          "EC.D.DSDFP.DAILY.IP",
                          "ED.D.XAD1GY.DAILY.IP",
                          "KA.D.SGBSLN.DAILY.IP",
                          "KA.D.SSLNLN.DAILY.IP",
                          "ED.D.BMW.DAILY.IP",
                          "ED.D.DES2GY.DAILY.IP",
                          "KA.D.DES2.DAILY.IP",
                          "ED.D.ANNGY.DAILY.IP",
                          "EC.D.RENA.DAILY.IP",
                          "ED.D.EVTGY.DAILY.IP",
                          "KA.D.SNGALN.DAILY.IP",
                          "KA.D.AUCOLN.DAILY.IP",
                          "EG.D.AUCONA.DAILY.IP",
                          "SI.D.SLVUS.DAILY.IP",
                          "MT.D.GC.MONTH1.IP",
                          "EC.D.AUTFP.DAILY.IP",
                          "KA.D.ECAIGP.DAILY.IP",
                          "EJ.D.ZSILSW.DAILY.IP",
                          "EJ.D.ZSILEUSW.DAILY.IP",
                          "ED.D.CON.DAILY.IP",
                          "ED.D.VOW3GY.DAILY.IP",
                          "KA.D.3SZNLN.DAILY.IP",
                          "ED.D.SXAPEXGY.DAILY.IP",
                          "KA.D.LCOPLN.DAILY.IP",
                          "KA.D.GDXLN.DAILY.IP",
                          "SI.D.GLDUS.DAILY.IP",
                          "KA.D.GJGBLN.DAILY.IP",
                          "KA.D.3SDELN.DAILY.IP",
                          "KA.D.ECSLVA.DAILY.IP",
                          "KA.D.XSILLN.DAILY.IP",
                          "KA.D.PHAG.DAILY.IP",
                          "KA.D.SSLVLN.DAILY.IP",
                          "ED.D.DCX.DAILY.IP",
                          "KA.D.XUKSLN.DAILY.IP",
                          "ED.D.UBUDGY.DAILY.IP",
                          "ED.D.PSHG_p.DAILY.IP",
                          "KA.D.AVV.DAILY.IP",
                          "UD.D.SQQQ.DAILY.IP",
                          "KA.D.3USSLN.DAILY.IP",
                          "KA.D.2PALLN.DAILY.IP",
                          "KA.D.3DESLN.DAILY.IP",
                          "KA.D.GDXJLN.DAILY.IP",
                          "CC.D.KC.USS.IP",
                          "KA.D.3HCLLN.DAILY.IP",
                          "KA.D.QQQSLN.DAILY.IP",
                          "ED.D.TMVGY.DAILY.IP",
                          "KA.D.LPLALN.DAILY.IP",
                          "KA.D.PUS5LN.DAILY.IP",
                          "EC.D.UG.DAILY.IP",
                          "EC.D.FRFP.DAILY.IP",
                          "KA.D.ECLBUL.DAILY.IP",
                          "EC.D.EOFP.DAILY.IP",
                          "KA.D.3SAZLN.DAILY.IP",
                          "KA.D.3SBPLN.DAILY.IP",
                          "KA.D.3LGOLN.DAILY.IP",
                          "KA.D.SUK2.DAILY.IP",
                          "KA.D.2UKSLN.DAILY.IP",
                          "KA.D.ECLSIL.DAILY.IP",
                          "KA.D.3SVOLN.DAILY.IP",
                          "CC.D.VIX.USS.IP",
                          "KA.D.3SLLLN.DAILY.IP",
                          "KA.D.3LSILN.DAILY.IP",
                          "KA.D.3SBCLN.DAILY.IP",
                          "KA.D.3UKSLN.DAILY.IP",
                          "KA.D.3BASLN.DAILY.IP",
                          "KA.D.3SILLN.DAILY.IP",
                          "KA.D.VILXLN.DAILY.IP",
                          "KA.D.3SRDLN.DAILY.IP",
                          "KA.D.3SGLLN.DAILY.IP",
                          "KA.D.3SRILN.DAILY.IP"]
  
          # list_of_epics = ['IX.D.FTSE.DAILY.IP']
          # list_of_epics = ['CS.D.EURUSD.TODAY.IP']
          # list_of_epics = [
          #     'CS.D.BITCOIN.TODAY.IP',
          #     'CS.D.ETHUSD.TODAY.IP',
          #     'CS.D.LTCUSD.TODAY.IP',
          #     'CS.D.BCHUSD.TODAY.IP',
          #     'CS.D.XLMUSD.TODAY.IP',
          #     'CS.D.CRYPTOB10.TODAY.IP',
          #     'CS.D.ETHXBT.TODAY.IP',
          #     'CS.D.EOSUSD.TODAY.IP',
          #     'CS.D.BCHXBT.TODAY.IP',
          #     'CS.D.NEOUSD.TODAY.IP',
          #     'CS.D.XRPUSD.TODAY.IP'
          #     ]
  
          self.df.set_epics_to_look_for(epic_list=list_of_epics)
  
          self.map_epic_data_minute={}
          # this way we can record the time the data was take for a particular instrument
          self.first_timestamp = {}
          for epic in list_of_epics:
              self.map_epic_data_minute[epic] = []
              self.first_timestamp[epic] = None
  
          self.high = None
          self.low = None
          self.time_interval = 5
  
      def setup(self):
          self.df.update_stop_level_bands()
  
  
      def run(self):
  
          while(True):
              if datetime.now().hour < 8:
                  continue
  
              try:
                  # setup is running in another program
                  # self.setup()
                  start_time = datetime.now()
  
                  for epic in self.map_epic_data_minute.keys():
                      signals_and_levels = self.signal_generation(epic=epic)
                      self.create_orders(epic=epic, signals_levels=signals_and_levels)
  
                  # because we are constantly looking and look behind for the last two 5 minutes the fetch request will find what we need
                  end_time = datetime.now() - start_time
                  print(end_time)
  
              except Exception as e:
                  print(e, "   error in the looping for the defined_functionality")
                  traceback.print_exc()
  
  
      def create_orders(self, epic, signals_levels):
          if signals_levels == None:
              return
          key = None
          if signals_levels["BUY"] != None:
              key = "BUY"
          elif signals_levels["SELL"] != None:
              key = "SELL"
  
  
          position = self.df.find_open_position_by_epic(epic=epic)
  
          if len(position) != 0:
              return position[0]
  
          create_position = self.df.create_open_position(epic=epic, direction=key, size=0.5)
  
          return create_position
          
  
      def signal_generation(self, epic):
          signals_levels = None
          # change whilst testing intervals are shorter
          minute_5 = 5*60
          datetime_now = datetime.now()
  
  
          if (self.first_timestamp[epic] != None):
              difference = (datetime_now - self.first_timestamp[epic])
  
              if (difference.seconds < minute_5):
                  return None
  
          data = self.df.get_historical_data_via_num_points(epic=epic, resolution="5Min", num_points=2)
          self.first_timestamp[epic] = datetime_now
  
          if not isinstance(data,pandas.core.frame.DataFrame):
              return
  
          self.map_epic_data_minute[epic].append(data)
  
          object_epic_data = self.map_epic_data_minute[epic][-1]
          object_epic_data["bid"]["Close"].size
  
          if object_epic_data["bid"]["Close"].size >=2:
              sell_level = None
              buy_level = None
  
              time_current = object_epic_data.index[-1]
              bid_close = object_epic_data["bid"]["Close"][-1]
              offer_close = object_epic_data["ask"]["Close"][-1]
              high = object_epic_data["bid"]["High"][-1]
              low = object_epic_data["bid"]["Low"][-1]
  
              time_current_old = object_epic_data.index[0]
              bid_close_old = object_epic_data["bid"]["Close"][0]
              offer_close_old = object_epic_data["ask"]["Close"][0]
              high_old = object_epic_data["bid"]["High"][0]
              low_old = object_epic_data["bid"]["Low"][0]
  
              if len(self.map_epic_data_minute[epic]) >= 2:
                  del(self.map_epic_data_minute[epic][0])
  
              percentage_change = ((bid_close - bid_close_old)/bid_close)*100
  
              spread_percentage = ((offer_close - bid_close)/bid_close ) *100
  
              # print(epic, percentage_change, " spread percentage: ", spread_percentage)
  
              # if abs(percentage_change) > 5:
              if abs(percentage_change) > 2:
                  #large price change has occured take a position
                  # if negative then price has dropped else if positive price has gone up
                  if percentage_change > 0:
                      #positive - price will fall
                      sell_level = 1
                  else:
                      # negative - price will rise
                      buy_level = 1
  
                  self.map_epic_data_minute[epic] = []
              # instead here we are using bid/offer
  
              if (sell_level == None) and (buy_level == None):
                  return None
  
              signals_levels = {
              "SELL": sell_level,
              "BUY": buy_level
              }
  
          return signals_levels
              
              
          
          
  
  