public int Run(EDoorCenterData centerData)
        {
            centerData.UpdateLiveOrdersForTurn();

            int runCount = 0;

            long startTotalCount = _eachControllers.Count;
            while (IsValid(centerData))
            {
                if (_eachControllers.Count > 0)
                {
                    //실행한다.
                    EDoorEachMonitorEnterController ec = _eachControllers.Dequeue();
                    ec.Run(centerData);
                    _doneQueue.Enqueue(ec);

                    ++runCount;
                }
                else
                {
                    // 한바퀴 다 돌았다.
                    break;
                }
            }

            while (_doneQueue.Count > 0)
            {
                // 다시 넣어준다.
                _eachControllers.Enqueue(_doneQueue.Dequeue());
            }

            // 유실이 있는지 여부 검사
            long endTotalCount = _eachControllers.Count;

            Trace.Assert(_doneQueue.Count == 0);
            Trace.Assert(startTotalCount == endTotalCount);

            return runCount;
        }
 public void Run(EDoorCenterData centerData)
 {
     Trace.Assert(centerData.GetAvailableChannelCount() > 0);
     _monitorEnter = _monitorEnter.Run(centerData, _data);
 }
Exemple #3
0
        void RebalanceStateTest_RebalanceRun(
            EDoorEachMonitorEnterController_Accessor each,
            RebalanceState_Accessor rsa,
            EDoorCenterData centerData)
        {
            //Run실행 후 sweeper, state, availableCount check
            MonitorState.MonitorDataThisTurn monitorData = EDoorUtil.CreateThisTurnInput(each._data);
            SetAsDefaultPrice(monitorData);

            String elwCode = each._data.LiveOrder.Code;
            double elwReqPrice = each._data.LiveOrder.ReqPrice;
            double optionPriceOfElwReqPrice = ElwOptionUtil.ConvertToOptionPrice(elwCode, elwReqPrice);

            RawMarketData rmdElw = monitorData.RmdElw;
            RawMarketData rmd_2 = monitorData.RmdKoi_2;
            RawMarketData rmd_3 = monitorData.RmdKoi_3;
            RawMarketData rmd_4 = monitorData.RmdKoi_4;

            TickValue tvElw = ProductUtil.Ins().GetTick(rmdElw.Code, elwReqPrice);

            double oneTickUpElwPrice = elwReqPrice + tvElw.UpTickValue;
            double oneTickDownElwPrice = elwReqPrice - tvElw.DownTickValue;

            double optionPriceOfOneTickUpElwReqPrice =
                ElwOptionUtil.ConvertToOptionPrice(elwCode, oneTickUpElwPrice);

            TickValue tv = ProductUtil.Ins().GetTick(rmd_3.Code, optionPriceOfOneTickUpElwReqPrice);

            double oneTickUpOptionPrice = optionPriceOfOneTickUpElwReqPrice + tv.UpTickValue;

            double oneTickDownOptionPrice = optionPriceOfOneTickUpElwReqPrice - tv.DownTickValue;

            rmd_3.BidPrice1 = oneTickUpOptionPrice;
            rmdElw.BidPrice1 = oneTickUpElwPrice;
            String log = "";
            Assert.AreEqual(true,  rsa.IsRebalanceCondition(centerData, each._data, monitorData, ref log));

            int prevChannel = centerData.GetAvailableChannelCount();
            POrder o = each._data.LiveOrder;

            IEDoorEachMonitorEnterState next = rsa.Run(centerData, each._data, monitorData);

            Assert.AreEqual(next.GetState(), EDoorEachMonitorEnterState.MonitorState);

            Assert.AreEqual(prevChannel - 1, centerData.GetAvailableChannelCount());

            Assert.AreEqual(true, o.IsCancelRemains());
        }
 Boolean IsValid(EDoorCenterData centerData)
 {
     int availableCount = centerData.GetAvailableChannelCount();
     if (availableCount > 0)
     {
         return true;
     }
     return false;
 }
Exemple #5
0
        void RebalanceStateTest_NoRebalanceCase(
            EDoorEachMonitorEnterController_Accessor each,
            RebalanceState_Accessor rsa,
            EDoorCenterData centerData)
        {
            MonitorState.MonitorDataThisTurn monitorData = EDoorUtil.CreateThisTurnInput(each._data);
            SetAsDefaultPrice(monitorData);

            String log = "";
            Boolean actual = rsa.IsRebalanceCondition(centerData, each._data, monitorData, ref log);
            Assert.AreEqual(false, actual);
        }
Exemple #6
0
        void RebalanceStateTest_RebalanceCase(
            EDoorEachMonitorEnterController_Accessor each,
            RebalanceState_Accessor rsa,
            EDoorCenterData centerData)
        {
            //1. 정상적이지 않은 시세
            InvalidRMDCase_RebalanceStateTest(each, rsa, centerData);

            //2. 2's koi 보다 높은 Elw 가격
            HigherThanKoi_2_RebalanceStateTest(each, rsa, centerData);

            //3. FrontBid가 아니고 3's koi 보다 낮은 가격
            NotFrontBidAndLowerPrice_RebalanceStateTest(each, rsa, centerData);
        }
Exemple #7
0
        void NotFrontBidAndLowerPrice_RebalanceStateTest(
            EDoorEachMonitorEnterController_Accessor each,
            RebalanceState_Accessor rsa,
            EDoorCenterData centerData)
        {
            MonitorState.MonitorDataThisTurn monitorData = EDoorUtil.CreateThisTurnInput(each._data);
            SetAsDefaultPrice(monitorData);

            String elwCode = each._data.LiveOrder.Code;
            double elwReqPrice = each._data.LiveOrder.ReqPrice;
            double optionPriceOfElwReqPrice = ElwOptionUtil.ConvertToOptionPrice(elwCode, elwReqPrice);

            RawMarketData rmdElw = monitorData.RmdElw;
            RawMarketData rmd_2 = monitorData.RmdKoi_2;
            RawMarketData rmd_3 = monitorData.RmdKoi_3;
            RawMarketData rmd_4 = monitorData.RmdKoi_4;

            TickValue tvElw = ProductUtil.Ins().GetTick(rmdElw.Code, elwReqPrice);

            double oneTickUpElwPrice = elwReqPrice + tvElw.UpTickValue;
            double oneTickDownElwPrice = elwReqPrice - tvElw.DownTickValue;

            double optionPriceOfOneTickUpElwReqPrice =
                ElwOptionUtil.ConvertToOptionPrice(elwCode, oneTickUpElwPrice);

            TickValue tv = ProductUtil.Ins().GetTick(rmd_3.Code, optionPriceOfOneTickUpElwReqPrice);

            double oneTickUpOptionPrice = optionPriceOfOneTickUpElwReqPrice + tv.UpTickValue;

            double oneTickDownOptionPrice = optionPriceOfOneTickUpElwReqPrice - tv.DownTickValue;

            // Elw가격이 FrontBid가 되도록 설정
            // 같아도 FrontBid이다.
            rmdElw.BidPrice1 = elwReqPrice;
            Assert.AreEqual(true, rsa.IsFrontBidPrice(each._data, monitorData));

            rmdElw.BidPrice1 = oneTickDownElwPrice;
            Assert.AreEqual(true, rsa.IsFrontBidPrice(each._data, monitorData));

            // Elw가격이 FrontBid가 아니도록 설정
            rmdElw.BidPrice1 = oneTickUpElwPrice;
            Assert.AreEqual(false, rsa.IsFrontBidPrice(each._data, monitorData));

            //Elw가격 + 1tick < 3's bid case
            rmd_3.BidPrice1 = oneTickUpOptionPrice;
            Assert.AreEqual(true, rsa.IsReqPricePlusOneLowerThanKoi_3(each._data, monitorData));

            //Elw가격 + 1tick == 3's bid case
            //같을 때는 기본적으로 리밸런스를 하지 않는다.
            rmd_3.BidPrice1 = optionPriceOfOneTickUpElwReqPrice;
            Assert.AreEqual(false, rsa.IsReqPricePlusOneLowerThanKoi_3(each._data, monitorData));

            //Elw가격 + 1tick > 3's bid case
            rmd_3.BidPrice1 = oneTickDownOptionPrice;
            Assert.AreEqual(false, rsa.IsReqPricePlusOneLowerThanKoi_3(each._data, monitorData));

            //1. 3's Bid > elw && Not frontBid
            // rebalance case
            rmd_3.BidPrice1 = oneTickUpOptionPrice;
            rmdElw.BidPrice1 = oneTickUpElwPrice;
            String log = "";
            Assert.AreEqual(true, rsa.IsRebalanceCondition(centerData, each._data, monitorData, ref log));

            //2. 3's Bid == elw && Not frontBid
            // No rebalance case
            rmd_3.BidPrice1 = optionPriceOfOneTickUpElwReqPrice;
            rmdElw.BidPrice1 = oneTickUpElwPrice;
            Assert.AreEqual(false, rsa.IsRebalanceCondition(centerData, each._data, monitorData, ref log));

            //3. 3's Bid < elw && Not front Bid
            rmd_3.BidPrice1 = oneTickDownOptionPrice;
            rmdElw.BidPrice1 = oneTickUpElwPrice;
            Assert.AreEqual(false, rsa.IsRebalanceCondition(centerData, each._data, monitorData, ref log));

            //4. 3's Bid > elw && frontBid
            rmd_3.BidPrice1 = oneTickUpOptionPrice;
            rmdElw.BidPrice1 = elwReqPrice;
            Assert.AreEqual(false, rsa.IsRebalanceCondition(centerData, each._data, monitorData, ref log));

            //5. 3's Bid == elw && frontBid
            rmd_3.BidPrice1 = optionPriceOfOneTickUpElwReqPrice;
            rmdElw.BidPrice1 = elwReqPrice;
            Assert.AreEqual(false, rsa.IsRebalanceCondition(centerData, each._data, monitorData, ref log));

            //6. 3's Bid < elw && frontBid
            rmd_3.BidPrice1 = oneTickDownOptionPrice;
            rmdElw.BidPrice1 = elwReqPrice;
            Assert.AreEqual(false, rsa.IsRebalanceCondition(centerData, each._data, monitorData, ref log));
        }
Exemple #8
0
        void RebalanceStateTest(EDoorEachMonitorEnterController_Accessor each, EDoorCenterData centerData)
        {
            RebalanceState rs = each._monitorEnter as RebalanceState;
            RebalanceState_Accessor rsa = new RebalanceState_Accessor(new PrivateObject(rs));

            //1. Rebalance 하지 않아도 되는 경우 테스트
            RebalanceStateTest_NoRebalanceCase(each, rsa, centerData);

            //2. Rebalance 해야 하는 경우 테스트
            RebalanceStateTest_RebalanceCase(each, rsa, centerData);

            //3. Rebalance를 Run한다.
            RebalanceStateTest_RebalanceRun(each, rsa, centerData);
        }
Exemple #9
0
        void MonitorDataThisTurnTest(
            EDoorEachMonitorEnterController_Accessor each,
            MonitorState_Accessor ms,
            EDoorCenterData centerData)
        {
            MonitorState.MonitorDataThisTurn monitorData =
                EDoorUtil.CreateThisTurnInput(each._data);

            // 1. IsAllValid test
            monitorData.RmdKoi_0.BidPrice1 = 0;
            Assert.AreEqual(EDoorUtil.IsAllValid(monitorData), false);

            MakeValidRMD(ref monitorData);
            Assert.AreEqual(EDoorUtil.IsAllValid(monitorData), true);

            // 2. IsAllRefOK test
            Assert.AreEqual(EDoorUtil.IsAllRefOK(monitorData), false);

            MakeRefOKRMD_01(ref monitorData);
            Assert.AreEqual(EDoorUtil.IsAllRefOK(monitorData), false);

            MakeRefOKRMD_2(ref monitorData);
            Assert.AreEqual(EDoorUtil.IsAllRefOK(monitorData), false);

            MakeRefOKRMD_3(ref monitorData);
            Assert.AreEqual(EDoorUtil.IsAllRefOK(monitorData), false);

            // AllRefOK case
            MakeRefOKRMD_4(ref monitorData);
            Assert.AreEqual(EDoorUtil.IsAllRefOK(monitorData), true);
        }
Exemple #10
0
        void MonitorStateRunTest(
            EDoorEachMonitorEnterController_Accessor each,
            MonitorState_Accessor ms,
            EDoorCenterData centerData)
        {
            MonitorState.MonitorDataThisTurn monitorData =
                EDoorUtil.CreateThisTurnInput(each._data);

            MakeRefOKRMD_01(ref monitorData);
            MakeRefOKRMD_2(ref monitorData);
            MakeRefOKRMD_3(ref monitorData);
            MakeRefOKRMD_4(ref monitorData);

            CalculateElwReqPriceTest(ms, monitorData, each._data);

            SetAsDefaultPrice(monitorData);
            each._monitorEnter = ms.Run(centerData, each._data, monitorData);
            Assert.AreEqual(each._monitorEnter.GetState(),
                EDoorEachMonitorEnterState.EnteringState);
        }
Exemple #11
0
 void InvalidRMDCase_RebalanceStateTest(
     EDoorEachMonitorEnterController_Accessor each,
     RebalanceState_Accessor rsa,
     EDoorCenterData centerData)
 {
     MonitorState.MonitorDataThisTurn monitorData = EDoorUtil.CreateThisTurnInput(each._data);
     String log = "";
     Boolean actual = rsa.IsRebalanceCondition(centerData, each._data, monitorData, ref log);
     Assert.AreEqual(true, actual);
 }
Exemple #12
0
        void HigherThanKoi_2_RebalanceStateTest(
            EDoorEachMonitorEnterController_Accessor each,
            RebalanceState_Accessor rsa,
            EDoorCenterData centerData)
        {
            MonitorState.MonitorDataThisTurn monitorData = EDoorUtil.CreateThisTurnInput(each._data);
            SetAsDefaultPrice(monitorData);

            String elwCode = each._data.LiveOrder.Code;
            double elwReqPrice = each._data.LiveOrder.ReqPrice;
            double optionPriceOfElwReqPrice = ElwOptionUtil.ConvertToOptionPrice(elwCode, elwReqPrice);

            RawMarketData rmd_2 = monitorData.RmdKoi_2;
            RawMarketData rmd_3 = monitorData.RmdKoi_3;
            RawMarketData rmd_4 = monitorData.RmdKoi_4;

            TickValue tv = ProductUtil.Ins().GetTick(rmd_2.Code, optionPriceOfElwReqPrice);

            double oneTickUpOptionPrice = optionPriceOfElwReqPrice + tv.UpTickValue;

            double oneTickDownOptionPrice = optionPriceOfElwReqPrice - tv.DownTickValue;

            // Elw가격보다 아직은 2's Bid가 높다.
            // Rebalance 필요 없다.
            SetAsDefaultPrice(monitorData);
            rmd_2.BidPrice1 = oneTickUpOptionPrice;
            rmd_3.BidPrice1 = rmd_2.BidPrice1 - 0.05;
            rmd_4.BidPrice1 = rmd_3.BidPrice1 - 0.05;

            String log = "";
            Boolean actual = rsa.IsRebalanceCondition(centerData, each._data, monitorData, ref log);
            Assert.AreEqual(false, actual);

            // Elw가격이 2's bid보다 높다.
            // Elw가 너무 높은 가격인 상태이므로 리밸런스 해주어야 한다.
            rmd_2.BidPrice1 = oneTickDownOptionPrice;
            rmd_3.BidPrice1 = rmd_2.BidPrice1 - 0.05;
            rmd_4.BidPrice1 = rmd_3.BidPrice1 - 0.05;

            actual = rsa.IsRebalanceCondition(centerData, each._data, monitorData, ref log);
            Assert.AreEqual(true, actual);
        }
Exemple #13
0
        void EnteringStateTest(
            EDoorEachMonitorEnterController_Accessor each,
            EDoorCenterData centerData)
        {
            EnteringState es = each._monitorEnter as EnteringState;
            EnteringState_Accessor esa = new EnteringState_Accessor(new PrivateObject(es));

            IEDoorEachMonitorEnterState state = esa.Run(centerData, each._data);
            Assert.AreEqual(EDoorEachMonitorEnterState.EnteringState, state.GetState());

            Account account = each._data.LiveOrder.TargetAccount;
            SimHTS target = account.Hts as SimHTS;

            SimPOrder simOrder = new SimPOrder(each._data.LiveOrder, 1500);
            simOrder.Execute();

            StringPacket inOrderPacket = simOrder.GetContractPacket(SimPOrder.접수);
            target.ReceiveDTRealEventHandler(inOrderPacket.GetStream());
            account.HandleCallBackData();

            state = esa.Run(centerData, each._data);
            Assert.AreEqual(EDoorEachMonitorEnterState.RebalanceState, state.GetState());
            each._monitorEnter = state;
        }
Exemple #14
0
        void EDoorCenterDataTest(EDoorCenterData centerData)
        {
            Assert.AreEqual(
                centerData.CurEnterCountType,
                EDoorCenterData.EnterCountType.Ten);

            // 기본값 2개
            Assert.AreEqual(centerData.MaxChannelCount, 2);
            Assert.AreEqual(centerData.GetAvailableChannelCount(), 2);
        }
Exemple #15
0
        void CencelOrderDoneTest(EDoorCenterData centerData, EDoorEachMonitorEnterController_Accessor each)
        {
            EDoorCenterData_Accessor cda = new EDoorCenterData_Accessor(new PrivateObject(centerData));

            foreach (POrder order in cda._liveOrders)
            {
                order.UpdateCancelMessage(order.ReqCount);
            }

            cda.UpdateLiveOrdersForTurn();
            Assert.AreEqual(2, cda.GetAvailableChannelCount());
        }