예제 #1
0
 void RecalcBar(AggregateBar bar)
 {
     l.Info("RecalcBar " + bar.Number);
     Lock.AcquireWriterLock(1000);
     try
     {
         bar.Clear();
         m_TickBars.Lock.AcquireReaderLock(1000);
         try
         {
             IBar tick = m_TickBars.First;
             while (tick != null)
             {
                 if (TimeAlignment(tick.DT) == bar.DT)
                 {
                     bar.AddTick(tick);
                 }
                 tick = m_TickBars.GetNext(tick);
             }
         }
         finally
         {
             m_TickBars.Lock.ReleaseReaderLock();
         }
     }
     finally
     {
         Lock.ReleaseWriterLock();
     }
 }
예제 #2
0
        void m_TickBars_NewBarEvent(object sender, BarsEventArgs e) // TODO возможная оптимизация (слишком часто вызываю TimeAlignment(e.bar.dt))
        {
            if (l.IsDebugEnabled)
            {
                l.Debug(debKey + "m_TickBars_NewBarEvent новый тик " + e.bar);
            }
            Lock.AcquireWriterLock(1000);
            try
            {
                AggregateBar bar = FindBar(e.bar.DT) as AggregateBar;

                if (bar == null)
                {
                    int timeAlignment = TimeAlignment(e.bar.DT);

                    if (l.IsDebugEnabled)
                    {
                        l.Debug(debKey + "m_TickBars_NewBarEvent Создаю новый бар " + DateTime2Int.DateTime(timeAlignment));
                    }

                    bar = new AggregateBar(timeAlignment, timeAlignment + scale.interval - 1, e.bar.Number, e.bar.Close, e.bar.Close, e.bar.Close, e.bar.Close, e.bar.Volume);

                    bars.Add(bar);

                    EventHandler <BarsEventArgs> ev = NewBarEvent;
                    if (ev != null)
                    {
                        ev(this, new BarsEventArgs(this, bar));
                    }
                }
                else
                {
                    l.Debug(debKey + "m_TickBars_NewBarEvent Добавляю тик в бар");

                    if ((m_LastTick != null) &&
                        ((m_LastTick.DT > e.bar.DT) ||
                         ((m_LastTick.DT == e.bar.DT) && (m_LastTick.Number > e.bar.Number))))
                    {
                        l.Debug(debKey + "Тики пришли не по порядку. Пересчитываю весь бар");
                        RecalcBar(bar);
                    }
                    else
                    {
                        bar.AddTick(e.bar);
                    }

                    m_LastTick = e.bar;

                    EventHandler <BarsEventArgs> changeBarEvent = ChangeBarEvent;
                    if (changeBarEvent != null)
                    {
                        changeBarEvent(this, new BarsEventArgs(this, bar));
                    }
                }
            }
            finally
            {
                Lock.ReleaseWriterLock();
            }
        }
예제 #3
0
        void RecalcBar(AggregateBar bar)
        {
            l.Info("RecalcBar " + bar.Number);
            Lock.AcquireWriterLock(1000);
            try
            {
                bar.Clear();
                m_TickBars.Lock.AcquireReaderLock(1000);
                try
                {
                    IBar tick = m_TickBars.First;
                    while (tick != null)
                    {
                        if (TimeAlignment(tick.DT) == bar.DT)
                            bar.AddTick(tick);
                        tick = m_TickBars.GetNext(tick);
                    }

                }
                finally
                {
                    m_TickBars.Lock.ReleaseReaderLock();
                }
            }
            finally
            {
                Lock.ReleaseWriterLock();
            }
        }
예제 #4
0
        // TODO возможная оптимизация (слишком часто вызываю TimeAlignment(e.bar.dt))
        void m_TickBars_NewBarEvent(object sender, BarsEventArgs e)
        {
            if(l.IsDebugEnabled)
                l.Debug(debKey+"m_TickBars_NewBarEvent новый тик " + e.bar);
            Lock.AcquireWriterLock(1000);
            try
            {
                AggregateBar bar = FindBar(e.bar.DT) as AggregateBar;

                if (bar == null)
                {
                    int timeAlignment = TimeAlignment(e.bar.DT);

                    if (l.IsDebugEnabled)
                        l.Debug(debKey + "m_TickBars_NewBarEvent Создаю новый бар " + DateTime2Int.DateTime(timeAlignment) );

                    bar = new AggregateBar(timeAlignment, timeAlignment + scale.interval - 1, e.bar.Number, e.bar.Close, e.bar.Close, e.bar.Close, e.bar.Close, e.bar.Volume);

                    bars.Add(bar);

                    EventHandler<BarsEventArgs> ev = NewBarEvent;
                    if (ev != null)
                        ev(this, new BarsEventArgs(this,bar));
                }
                else
                {
                    l.Debug(debKey + "m_TickBars_NewBarEvent Добавляю тик в бар");

                    if ((m_LastTick != null) &&
                            ((m_LastTick.DT > e.bar.DT)
                            || ((m_LastTick.DT == e.bar.DT) && (m_LastTick.Number > e.bar.Number))))
                    {
                        l.Debug(debKey + "Тики пришли не по порядку. Пересчитываю весь бар");
                        RecalcBar(bar);
                    }
                    else
                        bar.AddTick(e.bar);

                    m_LastTick = e.bar;

                    EventHandler<BarsEventArgs> changeBarEvent = ChangeBarEvent;
                    if (changeBarEvent != null)
                        changeBarEvent(this, new BarsEventArgs(this,bar));
                }
            }
            finally
            {
                Lock.ReleaseWriterLock();
            }
        }