Exemplo n.º 1
0
        public void WriteAllDataToDisk()
        {
            //TO DO older 2 days

            //  if (bCopyIsBusy)
            //     return;



            bCopyIsBusy = true;


            CopyDictTFArray(ref CopyDict);

            //m_timeFrameAnalyzer.Plaza2Connector.Log("ElapsedMilliseconds=" + sw.ElapsedMilliseconds + " " + m_timeFrameAnalyzer.IsinDir);
            //    CDictTFArray cp = (CDictTFArray)  this.MemberwiseClone();



            try
            {
                foreach (KeyValuePair <string, SortedDictionary <DateTime, CTimeFrameArray> > kv in CopyDict)// this)
                {
                    string tf = kv.Key;

                    foreach (KeyValuePair <DateTime, CTimeFrameArray> kv2 in kv.Value)
                    {
                        DateTime        dt  = kv2.Key;
                        CTimeFrameArray tfa = kv2.Value;
                        if (!CUtilTime.OlderThanTwoWorkDays(dt))
                        {
                            tfa.FileName = m_timeFrameAnalyzer.GetFileName(tf, dt);

                            //   tfa.mxLockFile.WaitOne();
                            this.m_timeFrameAnalyzer.CreateDirectoriesIfNeed();
                            CSerializator.Write <CTimeFrameArray>(ref tfa);

                            tfa.DtLastWrite = DateTime.Now;

                            //    TaskCopyBackup(tfa.FileName);



                            //   tfa.mxLockFile.ReleaseMutex();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Error("WriteAllDataToDisk", e);
            }

            bCopyIsBusy = false;
        }
        private void AnalyzeDiskTF(ChangedTF changedTF, List <int> lstScale, EnmTF TF_high, EnmTF TF_low)
        {
            try
            {
                foreach (KeyValuePair <DateTime, CTimeFrameArray> kvp in m_dictTFArray[TF_low.ToString()]) //all dates of low TF array
                {
                    if (CUtilTime.OlderThanTwoWorkDays(kvp.Key))
                    {
                        continue;
                    }

                    CTimeFrameArray M_low_TF_Array = kvp.Value;
                    for (int i = 1; i < M_low_TF_Array.ListTimeFrameInfo.Count; i++) //each TF array
                    {
                        DateTime dtPrev = M_low_TF_Array.ListTimeFrameInfo[i - 1].Dt;
                        DateTime dtCurr = M_low_TF_Array.ListTimeFrameInfo[i].Dt;



                        DateTime dtFrom = new DateTime(0);
                        DateTime dtTo   = new DateTime(0);

                        if (changedTF(dtPrev, dtCurr, lstScale, ref dtFrom, ref dtTo))
                        {
                            //TO DO chek prev day etc

                            if (m_dictTFArray.IsContainTimeFrameInfo(TF_high, dtFrom))
                            {
                                continue; //if  already exists in high TF array than nothing to do and  continue
                            }
                            //exp logics
                            CTimeFrameInfo ntfi = null;
                            if (m_dictTFArray.GetLatestTFI(TF_high.ToString()) != null)
                            {
                                DateTime dtLast = (m_dictTFArray.GetLatestTFI(TF_high.ToString())).Dt;
                                if (dtLast > dtFrom)
                                {
                                    ntfi = m_dictTFArray.GetNewTFIPuttingtoWritePlace(m_isin, TF_high, dtFrom);
                                    //Error("Inserting data. TO DO check and remove");
                                }
                                else
                                {
                                    ntfi = m_dictTFArray.GetNewTimeFrameInfo(m_isin, TF_high, dtFrom);
                                }
                            }
                            else
                            {
                                ntfi = m_dictTFArray.GetNewTimeFrameInfo(m_isin, TF_high, dtFrom);
                            }



                            int j = i - 1;

                            //note: the last pos
                            ntfi.OpenedPos  = M_low_TF_Array.ListTimeFrameInfo[j].OpenedPos;
                            ntfi.ClosePrice = M_low_TF_Array.ListTimeFrameInfo[j].ClosePrice;


                            while (j >= 0 && M_low_TF_Array.ListTimeFrameInfo[j].Dt >= dtFrom)
                            {
                                CTimeFrameInfo currtfi = M_low_TF_Array.ListTimeFrameInfo[j];
                                ntfi.numOfDeals += currtfi.numOfDeals;
                                ntfi.Volume     += currtfi.Volume;

                                if (ntfi.HighPrice < currtfi.HighPrice)
                                {
                                    ntfi.HighPrice = currtfi.HighPrice;
                                }
                                if (ntfi.LowPrice > currtfi.LowPrice)
                                {
                                    ntfi.LowPrice = currtfi.LowPrice;
                                }

                                ntfi.OpenPrice = M_low_TF_Array.ListTimeFrameInfo[j].OpenPrice;

                                j--; //backward
                            }

                            DateTime dtcnd = CUtilTime.NormalizeDay(dtFrom);

                            //no need ? check !
                            CheckTFIConsistent(ntfi);
                        }
                    }
                    //TrapError(kvp.Value);
                }
            }
            catch (Exception e)
            {
                Error("AnalyzeDiskTF", e);
            }
        }