Esempio n. 1
0
 public void ProcessHighLow(TickInfo tick)
 {
     _threeMinTicks.Add(tick);
     Check3MinHighLow();
     CheckDayHigh(tick);
     CheckDayLow(tick);
 }
Esempio n. 2
0
        private void processTick(object[] args)
        {
            // Check if any clients have timed out
            foreach (Client c in clients)
            {
                if (c.CurrentState == ConnectionState.Play)
                {
                    // TODO: Check for keep alive timeouts
                }
                else
                {
                    if ((DateTime.Now - c.CreationTime) >= TimeoutPeriod)
                    {
                        ServerThread.Queue((object[] a) =>
                        {
                            c.Disconnect(DisconnectReason.TimedOutDuringHandshakeOrLogin);
                        });
                    }
                }
            }
            TimeSpan sinceLastTick = DateTime.Now - lastTick;
            TickInfo ti            = new TickInfo();

            ti.TimeSinceLastTick = sinceLastTick;
            OnServerTick?.Invoke(ti);

            lastTick = DateTime.Now;
        }
        private void CollectTick()
        {
            CurrentWindow current;

            if (!BreakTime)
            {
                current = CurrentWindow.GetActiveWindow();
                if (current.ShouldDiscard())
                {
                    return;
                }

                CurrentWindow = current;
            }
            else
            {
                current = CurrentWindow.FromString("Break time");
            }

            TickInfo info = new TickInfo()
            {
                Window = current,
                Span   = DateTime.Now.Subtract(LastTick)
            };

            CurrentTimeSlice.Add(info);

            SessionTimeSpent[current.ProgramName]
                = GetSessionTimeSpent(current.ProgramName) + info.Span.Milliseconds;
        }
Esempio n. 4
0
        public void ForceRun(int realIndex)
        {
            order1_ = Regenerate(null);
            order2_ = new List <int>();

            active_  = TickInfo.Empty();
            overlap_ = TickInfo.Empty();

            for (int i = 0; i < order1_.Count; ++i)
            {
                var ri = GetRealIndex(i, true);
                Reset(ri);

                if (ri == realIndex)
                {
                    active_.orderIndex = i;
                }
            }

            if (active_.orderIndex == -1)
            {
                LogError($"item {realIndex} not found");
                return;
            }

            Resume(realIndex);
        }
Esempio n. 5
0
        internal TickInfo ParseTextLineToTickInfo(string tickText)
        {
            TickInfo tickInfo = new TickInfo();
            var      elements = tickText.Split(',');

            if (elements.Length != 5)
            {
                Console.WriteLine($"{DateTime.Now}\tExpected Number of columns not present\tRecord:{tickText}");
                throw new Exception($"{DateTime.Now}\tExpected Number of columns not present\tRecord:{tickText}");
            }
            try
            {
                tickInfo.PriceTimeStamp = DateTime.ParseExact(elements[0], "yyyyMMdd HH:mm:ss:fff", CultureInfo.InvariantCulture);
                tickInfo.Bid            = Double.Parse(elements[1], CultureInfo.InvariantCulture);
                tickInfo.Ask            = Double.Parse(elements[2], CultureInfo.InvariantCulture);
                tickInfo.BidVolume      = Double.Parse(elements[3], CultureInfo.InvariantCulture);
                tickInfo.AskVolume      = Double.Parse(elements[4], CultureInfo.InvariantCulture);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{DateTime.Now}\tData Conversion Issue:{tickText}");
                throw new Exception($"{DateTime.Now}\tData Conversion Issue:{tickText}");
            }
            return(tickInfo);
        }
Esempio n. 6
0
    protected TickInfo MakeTick(List <GraphicsData> graphicsData, HomelandsTurnData turnData)
    {
        float    secondsUntilNextTurn = GetSecondsUntilNextTurn();
        float    percentUntilNextTurn = GetProgressToNextTurn(secondsUntilNextTurn);
        TickInfo tickInfo             = new TickInfo(graphicsData, turnData, _turnNumber, secondsUntilNextTurn, percentUntilNextTurn);

        return(tickInfo);
    }
Esempio n. 7
0
 public void AnalyzeTrades()
 {
     using (StreamReader sr = File.OpenText(_inputTradeListFilePath))
     {
         sr.ReadLine();//Ignore Header
         string   s        = String.Empty;
         TickInfo tickInfo = ParseTextLineToTickInfo(sr.ReadLine());
     }
 }
Esempio n. 8
0
        private void Check3MinHighLow()
        {
            TickInfo lastestTick  = _threeMinTicks.LastOrDefault();
            decimal  lastestPrice = lastestTick.Close / 100;
            TickInfo firstTick    = _threeMinTicks.FirstOrDefault();

            DateTime threeMinBefore = lastestTick.TickTime.AddMinutes(-3);

            if (firstTick.TickTime <= threeMinBefore)
            {
                int stopIndex = 0;
                for (int idx = 0; idx < _threeMinTicks.Count; idx++)
                {
                    TickInfo tmpItem = _threeMinTicks.ElementAt(idx);
                    if (tmpItem.TickTime > threeMinBefore)
                    {
                        stopIndex = idx;
                        break;
                    }
                }
                _threeMinTicks.RemoveRange(0, stopIndex);
            }

            decimal  currentMax = _threeMinTicks.Max(y => y.Close);
            TickInfo maxTick    = _threeMinTicks.Where(x => x.Close == currentMax).FirstOrDefault();

            if ((currentMax / 100) > ThreeMinHigh)
            {
                ThreeMinHigh     = currentMax / 100;
                ThreeMinHighTime = maxTick.TickTime;
            }
            else
            {
                if (ThreeMinHighTime < maxTick.TickTime)
                {
                    ThreeMinHigh     = currentMax / 100;
                    ThreeMinHighTime = maxTick.TickTime;
                }
            }
            decimal  currentMin = _threeMinTicks.Min(y => y.Close);
            TickInfo minTick    = _threeMinTicks.Where(x => x.Close == currentMin).FirstOrDefault();

            if ((currentMin / 100) < ThreeMinLow)
            {
                ThreeMinLow     = currentMin / 100;
                ThreeMinLowTime = minTick.TickTime;
            }
            else
            {
                if (ThreeMinLowTime < minTick.TickTime)
                {
                    ThreeMinLow     = currentMin / 100;
                    ThreeMinLowTime = minTick.TickTime;
                }
            }
        }
Esempio n. 9
0
    // Update is called once per frame
    void Update()
    {
        InputHandlerInfo inputHandlerInfo = _inputManager.GetInput();

        TickInfo tick = _game.TakeTick(inputHandlerInfo);

        _graphicsManager.Draw(tick._graphicsData);

        _hudManager.UpdateUi(tick);
    }
Esempio n. 10
0
            public static TickInfo Empty()
            {
                var ti = new TickInfo();

                ti.orderIndex = -1;
                ti.forwards   = true;
                ti.order1     = true;
                ti.mustWait   = false;
                return(ti);
            }
Esempio n. 11
0
        public void ItemsChanged()
        {
            Log("items changed, regenerating");

            active_  = TickInfo.Empty();
            overlap_ = TickInfo.Empty();

            order1_ = new List <int>();
            order2_ = new List <int>();
        }
Esempio n. 12
0
        private bool DoCheckAndEndOrder(ref VirtualOrder order, TickInfo currentTick)
        {
            bool doEndOrder = false;

            if (currentTick == null)
            {
                return(false);
            }

            if (order != null)
            {
                if (order.Direction > 0)                             //long
                {
                    if (currentTick.Close / 100 - order.Price <= -5) //停損
                    {
                        EndOrder(order.Direction, -1);
                        order      = null;
                        doEndOrder = true;
                        return(doEndOrder);
                    }

                    if (currentTick.Close / 100 - order.Price >= 10) //停利
                    {
                        EndOrder(order.Direction, 1);
                        order      = null;
                        doEndOrder = true;
                        return(doEndOrder);
                    }
                }

                if (order.Direction < 0)                             //short
                {
                    if (order.Price - currentTick.Close / 100 <= -5) //停損
                    {
                        EndOrder(order.Direction, -1);
                        order      = null;
                        doEndOrder = true;
                        return(doEndOrder);
                    }

                    if (order.Price - currentTick.Close / 100 >= 10) //停利
                    {
                        EndOrder(order.Direction, 1);
                        order      = null;
                        doEndOrder = true;
                        return(doEndOrder);
                    }
                }
            }
            else
            {
                doEndOrder = false;
            }
            return(doEndOrder);
        }
Esempio n. 13
0
        internal void OpenNewTrade(TickInfo record)
        {
            currentBuy = new InProgressTradeRecord();
            currentBuy.OrderOpenTimeStamp = record.PriceTimeStamp;
            currentBuy.EntryPrice         = record.Ask;
            currentBuy.TargetPrice        = record.Ask + 0.00030;

            currentShort = new InProgressTradeRecord();
            currentShort.OrderOpenTimeStamp = record.PriceTimeStamp;
            currentShort.EntryPrice         = record.Bid;
            currentShort.TargetPrice        = record.Bid - 0.00030;
        }
Esempio n. 14
0
        public void Tick()
        {
            if (tick.CurrentTick == 0)
            {
                OnFirstTick();
            }

            tick = tick.Next();

            OnBeforeTick(tick);
            OnTick(tick);
            OnAfterTick(tick);
        }
Esempio n. 15
0
        private void CheckHot()
        {
            TickInfo lastestTick = _30SecTicks.LastOrDefault();
            DateTime sec30Before = lastestTick.TickTime.AddSeconds(-30);
            DateTime sec15Before = lastestTick.TickTime.AddSeconds(-15);
            DateTime sec10Before = lastestTick.TickTime.AddSeconds(-10);
            DateTime sec5Before  = lastestTick.TickTime.AddSeconds(-5);
            DateTime sec3Before  = lastestTick.TickTime.AddSeconds(-3);

            bool keepRemove = true;

            do
            {
                TickInfo firstTick = _30SecTicks.FirstOrDefault();
                if (firstTick.TickTime < sec30Before)
                {
                    _30SecTicks.RemoveAt(0);
                }
                else
                {
                    keepRemove = false;
                }
            } while (keepRemove);

            this.ThirtyTradeCount  = this._30SecTicks.Count();
            this.ThirtyTicksVolume = this._30SecTicks.Select(x => x.Qty).Sum();
            this.ThirtyTickGap     = (this._30SecTicks.Select(x => x.Close).Max() - this._30SecTicks.Select(x => x.Close).Min()) / 100;

            var sec15TickList = this._30SecTicks.Where(x => x.TickTime > sec15Before).ToList();
            var sec10TickList = this._30SecTicks.Where(x => x.TickTime > sec10Before).ToList();
            var sec5TickList  = this._30SecTicks.Where(x => x.TickTime > sec5Before).ToList();
            var sec3TickList  = this._30SecTicks.Where(x => x.TickTime > sec3Before).ToList();

            this.Ten5TradeCount  = sec15TickList.Count();
            this.Ten5TicksVolume = sec15TickList.Select(x => x.Qty).Sum();
            this.Ten5TickGap     = (sec15TickList.Select(x => x.Close).Max() - sec15TickList.Select(x => x.Close).Min()) / 100;



            this.TenSecTradeCount  = sec10TickList.Count();
            this.TenSecTicksVolume = sec10TickList.Select(x => x.Qty).Sum();
            this.TenSecTickGap     = (sec10TickList.Select(x => x.Close).Max() - sec10TickList.Select(x => x.Close).Min()) / 100;

            this.FiveSecTradeCount  = sec5TickList.Count();
            this.FiveSecTicksVolume = sec5TickList.Select(x => x.Qty).Sum();
            this.FiveSecTickGap     = (sec5TickList.Select(x => x.Close).Max() - sec5TickList.Select(x => x.Close).Min()) / 100;

            this.ThreeSecTradeCount  = sec3TickList.Count();
            this.ThreeSecTicksVolume = sec3TickList.Select(x => x.Qty).Sum();
            this.ThreeSecTickGap     = (sec3TickList.Select(x => x.Close).Max() - sec3TickList.Select(x => x.Close).Min()) / 100;
        }
Esempio n. 16
0
    public TickInfo GetTick(List <GraphicsData> graphicsData, HomelandsTurnData turnData)
    {
        TickInfo tickInfo = MakeTick(graphicsData, turnData);

        if (tickInfo._secondsUntilNextTurn < 0f)
        {
            turnData._kho._keyActions[ePlayerAction.EndTurn] = true;
        }

        UpdateInternal(tickInfo);

        CheckEndCondition();

        return(tickInfo);
    }
Esempio n. 17
0
        private void CheckDayHigh(TickInfo tick)
        {
            decimal price = tick.Close / 100;

            if (DayHigh == 0)
            {
                DayHigh     = price;
                DayHighTime = tick.TickTime;
            }
            if (price > DayHigh)
            {
                DayHigh     = price;
                DayHighTime = tick.TickTime;
            }
            return;
        }
Esempio n. 18
0
        private void CheckDayLow(TickInfo tick)
        {
            decimal price = tick.Close / 100;

            if (DayLow == 0)
            {
                DayLow     = price;
                DayLowTime = tick.TickTime;
            }
            if (price < DayLow)
            {
                DayLow     = price;
                DayLowTime = tick.TickTime;
            }
            return;
        }
Esempio n. 19
0
    public virtual TickInfo TakeTick(InputHandlerInfo inputHandlerInfo)
    {
        // RESOLVE TURN
        UpdateGame();

        // RESOLVE INPUT IN GAME
        HomelandsTurnData turnData = _inputHandler.HandleInput(inputHandlerInfo);

        // DRAW GAME
        List <GraphicsData> graphicsToDraw = Draw();

        // OUTPUT TURN INFO
        TickInfo tickInfo = _tickSystem.GetTick(graphicsToDraw, turnData);

        return(tickInfo);
    }
Esempio n. 20
0
        public void ParseWithoutLosingFormat(string inputpath, string validationLog)
        {
            StreamWriter sw = new StreamWriter(validationLog);

            using (StreamReader sr = File.OpenText(inputpath))
            {
                sr.ReadLine();//Ignore Header
                string s = String.Empty;
                while ((s = sr.ReadLine()) != null)
                {
                    TickInfo record   = new TickInfo();
                    var      elements = s.Split(',');
                    if (elements.Length != 5)
                    {
                        sw.WriteLine($"{DateTime.Now}\tExpected Number of columns not present\tRecord:{s}");
                        sw.Flush();
                    }
                    try
                    {
                        record.PriceTimeStamp = DateTime.ParseExact(elements[0], "yyyyMMdd HH:mm:ss:fff", CultureInfo.InvariantCulture);
                        record.Bid            = Double.Parse(elements[1], CultureInfo.InvariantCulture);
                        record.Ask            = Double.Parse(elements[2], CultureInfo.InvariantCulture);
                        record.BidVolume      = Double.Parse(elements[3], CultureInfo.InvariantCulture);
                        record.AskVolume      = Double.Parse(elements[4], CultureInfo.InvariantCulture);
                        var formedString = $"{record.PriceTimeStamp.ToString("yyyyMMdd HH:mm:ss:fff")},{record.Bid},{record.Ask},{record.BidVolume},{record.AskVolume}";
                        if (s != formedString)
                        {
                            sw.WriteLine($"Error: Not matching\n{s}\n{formedString}");
                            Console.WriteLine($"Error: Not matching\n{s}\n{formedString}");
                        }
                        Console.Write("|");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"{DateTime.Now}\tData Conversion Issue:{s}");
                        sw.WriteLine($"{DateTime.Now}\tData Conversion Issue:{s}");
                        sw.Flush();
                    }
                }
            }

            sw.Flush();
            sw.Dispose();
            sw = null;
        }
Esempio n. 21
0
    protected void UpdateInternal(TickInfo tick)
    {
        _tickNumber++;
        if (tick._turnData._kho._keyActions[ePlayerAction.EndTurn])
        {
            if (_game._gameManager._hudManager.ScreenIsActive())
            {
                _game._gameManager._hudManager.ToggleScreen();
                TogglePause();
            }
            else
            {
                PlayerSwitchData psd = _game._playerSystem.ChangePlayer();
                if (_game._playerSystem._players.Count > 1 && !_game._gameManager._hudManager.ScreenIsActive())
                {
                    _game._gameManager._hudManager.ToggleScreen(psd);
                    TogglePause();
                }

                if (psd._isLastPlayerInQueue)
                {
                    _game.EndTurn();
                }
            }
        }

        if (tick._turnData._kho._keyActions[ePlayerAction.ChangeView])
        {
            _game._viewer.ToggleNextView();
        }

        if (tick._turnData._kho._keyActions[ePlayerAction.Help])
        {
            _game._gameManager._hudManager.ToggleHelp();
        }

        if (tick._turnData._kho._keyActions[ePlayerAction.Pause])
        {
            TogglePause();
        }
    }
Esempio n. 22
0
 protected virtual void OnBeforeTick(TickInfo tick)
 {
 }
Esempio n. 23
0
 protected HackModule(IHackContext context)
 {
     this.Context = context;
     tick         = new TickInfo(DateTime.Now, DateTime.Now, 0);
     Runner       = new ModuleRunner(this);
 }
Esempio n. 24
0
 public void UpdateUi(TickInfo tick)
 {
     _turnUi.UpdateUi(tick);
     _playerDemoUi.UpdateUi();
     _selectedUi.UpdateText(tick._turnData._mho._selected);
 }
Esempio n. 25
0
 public void ProcessVolumeHot(TickInfo tick)
 {
     _30SecTicks.Add(tick);
     CheckHot();
 }
Esempio n. 26
0
        private void NextOverlap()
        {
            Log("\nin NextOverlap");

            if (overlap_.mustWait)
            {
                Log("\nNextOverlap: must wait");
                return;
            }


            if (overlap_.orderIndex == -1)
            {
                Log(
                    "NextOverlap: no current overlap, starting from active " +
                    $"i={active_.orderIndex} fwd={active_.forwards}");

                overlap_ = active_;
            }
            else
            {
                var realIndex = GetRealIndex(active_.orderIndex, true);

                if (CanRunBackwards(realIndex))
                {
                    Log(
                        "NextOverlap: current overlap finished but active is " +
                        "half move, must wait");

                    overlap_.mustWait = true;
                    return;
                }
            }

            if (overlap_.orderIndex == -1)
            {
                Log("NextOverlap: no current active, bailing out");
                return;
            }


            bool order1      = true;
            bool reversedDir = (overlap_.forwards != active_.forwards);


            for (; ;)
            {
                if (overlap_.forwards)
                {
                    Log("NextOverlap: checking forwards");

                    ++overlap_.orderIndex;
                    Log($"NextOverlap: i now {overlap_.orderIndex}");

                    if (overlap_.orderIndex >= (order1 ? order1_ : order2_).Count)
                    {
                        Log("NextOverlap: past end, reversing");
                        overlap_.orderIndex = order1_.Count;
                        overlap_.forwards   = false;
                        reversedDir         = true;
                    }
                    else if (overlap_.orderIndex == active_.orderIndex && reversedDir)
                    {
                        Log(
                            "NextOverlap: went around, reached active " +
                            $"i={active_.orderIndex}, must wait (fw)");

                        overlap_.mustWait = true;
                        break;
                    }
                    else
                    {
                        var realIndex = GetRealIndex(overlap_.orderIndex, order1);

                        if (realIndex == -1)
                        {
                            Log("NextOverlap: GetRealIndex says it's -1, continuing");
                        }
                        else if (!CanRun(realIndex))
                        {
                            Log("NextOverlap: but it's disabled, continuing");
                        }
                        else
                        {
                            Log("NextOverlap: looks good, taking it");
                            break;
                        }
                    }
                }
                else
                {
                    Log("NextOverlap: checking backwards");

                    if (overlap_.orderIndex == 0)
                    {
                        Log("NextOverlap: past end, reversing");
                        overlap_.forwards   = true;
                        overlap_.orderIndex = -1;

                        if (reversedDir)
                        {
                            Log(
                                "NextOverlap: already reversed dir before, " +
                                "switching to order2");

                            order1 = false;
                        }
                    }
                    else if (overlap_.orderIndex <= active_.orderIndex && reversedDir)
                    {
                        var realIndex = GetRealIndex(overlap_.orderIndex, order1);

                        if (realIndex == -1)
                        {
                            Log(
                                $"NextOverlap: no element for " +
                                $"{overlap_.orderIndex}, continuing (bw)");

                            --overlap_.orderIndex;
                        }
                        else if (!overlap_.forwards && !CanRunBackwards(realIndex))
                        {
                            Log(
                                "NextOverlap: went around, reached active " +
                                $"i={active_.orderIndex}, not half move, " +
                                "continuing");

                            --overlap_.orderIndex;
                        }
                        else
                        {
                            Log(
                                "NextOverlap: went around, reached active " +
                                $"i={active_.orderIndex}, must wait (bw)");

                            overlap_.mustWait = true;

                            break;
                        }
                    }
                    else
                    {
                        --overlap_.orderIndex;

                        var realIndex = GetRealIndex(overlap_.orderIndex, order1);

                        if (realIndex == -1)
                        {
                            Log(
                                $"NextOverlap: no element for " +
                                $"{overlap_.orderIndex}, continuing");
                        }
                        else if (!CanRun(realIndex))
                        {
                            Log(
                                $"NextOverlap: index {overlap_.orderIndex} " +
                                $"disabled, continuing");
                        }
                        else if (CanRunBackwards(realIndex))
                        {
                            if (overlap_.orderIndex == active_.orderIndex)
                            {
                                Log(
                                    $"NextOverlap: index " +
                                    $"{overlap_.orderIndex} enabled but " +
                                    $"half move and is same as active; must " +
                                    $"wait");

                                overlap_.mustWait = true;
                            }
                            else
                            {
                                Log(
                                    $"NextOverlap: index " +
                                    $"{overlap_.orderIndex} enabled and " +
                                    $"half move, taking it");
                            }

                            break;
                        }
                        else
                        {
                            Log(
                                $"NextOverlap: index {overlap_.orderIndex} " +
                                $"enabled but not half move, so doesn't need " +
                                $"ticking; continuing");
                        }
                    }
                }
            }


            if (overlap_.mustWait)
            {
                return;
            }

            var newRealIndex = GetRealIndex(overlap_.orderIndex, order1);

            if (newRealIndex != -1)
            {
                Log(
                    $"NextOverlap: resuming {overlap_.orderIndex}");

                Resume(newRealIndex);
            }
        }
Esempio n. 27
0
        private void NextActive()
        {
            Log("\nin NextActive");

            if (order1_.Count == 0)
            {
                Log("NextActive: no elements");
                active_.orderIndex = -1;
                return;
            }

            if (overlap_.orderIndex == -1)
            {
                Log(
                    $"NextActive: initial fwd={active_.forwards} i={active_.orderIndex}");

                int initial = active_.orderIndex;
                if (initial < 0)
                {
                    initial = 0;
                }

                bool reversedDir = false;

                bool atOneEnd = (
                    active_.orderIndex == 0 ||
                    active_.orderIndex == order1_.Count - 1);

                for (; ;)
                {
                    if (active_.orderIndex == initial && reversedDir)
                    {
                        Log(
                            "NextActive: looped around, no valid " +
                            "element, bailing out");

                        active_.orderIndex = -1;
                        break;
                    }

                    if (active_.forwards)
                    {
                        ++active_.orderIndex;
                        Log($"NextActive: checking {active_.orderIndex}");

                        if (active_.orderIndex >= order1_.Count)
                        {
                            Log($"NextActive: {active_.orderIndex} past end, reversing");

                            active_.forwards   = false;
                            active_.orderIndex = order1_.Count - 1;

                            if (atOneEnd)
                            {
                                atOneEnd = false;
                            }
                            else
                            {
                                reversedDir = true;
                            }
                        }

                        Log($"NextActive: i now {active_.orderIndex}");
                    }
                    else
                    {
                        if (active_.orderIndex == 0)
                        {
                            Log($"NextActive: at beginning, going forwards");

                            active_.forwards = true;
                            order1_          = new List <int>(order2_);
                            order2_          = Regenerate(order2_);

                            if (atOneEnd)
                            {
                                atOneEnd = false;
                            }
                            else
                            {
                                reversedDir = true;
                            }
                        }
                        else
                        {
                            --active_.orderIndex;

                            Log($"NextActive: i now {active_.orderIndex}");
                        }
                    }

                    var realIndex = GetRealIndex(active_.orderIndex, true);

                    if (realIndex == -1)
                    {
                        Log("NextActive: GetRealIndex says it's -1, continuing");
                    }
                    else if (!CanRun(realIndex))
                    {
                        Log("NextActive: but it's disabled, continuing");
                    }
                    else if (!active_.forwards && !CanRunBackwards(realIndex))
                    {
                        Log(
                            $"NextActive: index {active_.orderIndex} " +
                            $"enabled but not half move, so doesn't need " +
                            $"ticking; continuing");
                    }
                    else
                    {
                        Log("NextActive: looks good, taking it");
                        break;
                    }
                }
            }
            else
            {
                Log("NextActive: overlap already active, taking over");

                // already an overlap, take it over
                active_ = overlap_;

                if (active_.mustWait)
                {
                    Log("NextActive: overlap was waiting, resuming");

                    var ri = GetRealIndex(active_.orderIndex, true);
                    if (ri == -1)
                    {
                        LogError(
                            $"NextActive: element {active_.orderIndex} not " +
                            $"found while trying to resume a mustWait " +
                            $"overlap");
                    }
                    else
                    {
                        Resume(ri);
                    }

                    active_.mustWait = false;
                }

                Log($"NextActive: i={active_.orderIndex}");

                if (!active_.order1)
                {
                    Log($"NextActive: was in order2, swapping");
                    order1_        = new List <int>(order2_);
                    order2_        = Regenerate(order2_);
                    active_.order1 = true;
                }

                overlap_ = TickInfo.Empty();

                return;
            }


            var newRealIndex = GetRealIndex(active_.orderIndex, true);

            if (newRealIndex != -1)
            {
                overlap_.mustWait = false;

                Log(
                    $"NextActive: resuming {active_.orderIndex}");

                Resume(newRealIndex);
            }
        }
Esempio n. 28
0
 protected virtual void OnAfterTick(TickInfo tick)
 {
 }
Esempio n. 29
0
 protected abstract void OnTick(TickInfo tick);
Esempio n. 30
0
        public void AddTwTick(TickInfo skTick)
        {
            if (this._lastKLine == null) //系統內還沒有任何K線的情況,這種情況有兩種,第一種,系統開盤後才打開,第二種,系統開盤前打開
            {
                //開市時間為0845
                DateTime tmpTime = this._marketOpenTime;
                while (skTick.TickTime >= tmpTime)
                {
                    KLineInfo kline = new KLineInfo(tmpTime);
                    this.KLineSeries.Add(kline);
                    this._lastKLine  = kline;
                    tmpTime          = tmpTime.AddMinutes(1);
                    this.KLineCount += 1;
                }

                this._lastKLine.AddTick(new Tick
                {
                    Close    = skTick.Close,
                    Qty      = skTick.Qty,
                    TickTime = skTick.TickTime
                });
            }
            else
            {
                if (skTick.TickTime > this._lastKLine.EndTime)
                {
                    KLineInfo lastK = new KLineInfo(skTick.TickTime);
                    lastK.AddTick(new Tick
                    {
                        Close    = skTick.Close,
                        Qty      = skTick.Qty,
                        TickTime = skTick.TickTime
                    });

                    this.KLineSeries.Add(lastK);
                    this._lastKLine  = lastK;
                    this.KLineCount += 1;
                }
                else if (skTick.TickTime >= this._lastKLine.StartTime && skTick.TickTime <= this._lastKLine.EndTime)
                {
                    this._lastKLine.AddTick(new Tick
                    {
                        Close    = skTick.Close,
                        Qty      = skTick.Qty,
                        TickTime = skTick.TickTime
                    });
                }
                else //這個tick屬於過去的K線
                {
                    var historyKLine = this.KLineSeries.Where(x => skTick.TickTime >= x.StartTime && skTick.TickTime <= x.EndTime).FirstOrDefault();
                    if (historyKLine != null)
                    {
                        historyKLine.AddTick(new Tick
                        {
                            Close    = skTick.Close,
                            Qty      = skTick.Qty,
                            TickTime = skTick.TickTime
                        });
                    }
                }
            }
        }