Exemplo n.º 1
0
        Sweeper_BondArb GetHousingSweeperNS(MonitorEnter_BondArb_Accessor me)
        {
            BondPair housingBondPair = null;
            RawMarketData rmdNormal = null;
            RawMarketData rmdSmall = null;

            SetHousingBondPairAndRmds(ref housingBondPair, ref rmdNormal, ref rmdSmall);

            SetAsZeroRMD(ref rmdNormal);
            SetAsZeroRMD(ref rmdSmall);

            int ret = 0;

            // 5000에 일반을 사서 15000에 소액을 팔 수 있는 기회이다
            SetImmeLongPart(rmdNormal, 100 * CommonConst._1_000 * CommonConst._1_000, 5000);
            SetImmeShortPart(rmdNormal, 0, 0);
            SetImmeLongPart(rmdSmall, 0, 0);
            SetImmeShortPart(rmdSmall, 100 * CommonConst._1_000 * CommonConst._1_000, 15000);

            me.BeforeEnterSweeperChance();
            ret = me.CheckArbChance(housingBondPair);
            Assert.AreEqual(0, ret);

            Sweeper_BondArb sweeper = new Sweeper_BondArb(housingBondPair, me._bondAccount);
            me._node.GetSweeperCollection().Add(sweeper);

            return sweeper;
        }
Exemplo n.º 2
0
        Sweeper_BondArb GetDoosanSweeperNR(MonitorEnter_BondArb_Accessor me)
        {
            BondPair doosanBondPair = null;
            RawMarketData rmdNormal = null;
            RawMarketData rmdRetail = null;

            SetCreditBondPairAndRmds(ref doosanBondPair, ref rmdNormal, ref rmdRetail);

            SetAsZeroRMD(ref rmdNormal);
            SetAsZeroRMD(ref rmdRetail);

            int ret = 0;

            // 5000에 일반을 사서 15000에 소매에 팔 수 있는 기회이다
            SetImmeLongPart(rmdNormal, 300 * CommonConst._1_000 * CommonConst._1_000, 5000);
            SetImmeShortPart(rmdNormal, 0, 0);
            SetImmeLongPart(rmdRetail, 0, 0);
            SetImmeShortPart(rmdRetail, 300 * CommonConst._1_000 * CommonConst._1_000, 15000);

            me.BeforeEnterSweeperChance();
            ret = me.CheckArbChance(doosanBondPair);
            Assert.AreEqual(0, ret);

            Sweeper_BondArb sweeper = new Sweeper_BondArb(doosanBondPair, me._bondAccount);
            me._node.GetSweeperCollection().Add(sweeper);

            return sweeper;
        }
Exemplo n.º 3
0
        // 기회인지 보고 기회라면 포지션을 들어간다.
        public Boolean EnterSweeperChance(long maxNewSweeperCount)
        {
            List<BondPair> pairs = BondPairManager.Ins().GetPairs();

            // Arb기회를 구한다.
            foreach (BondPair pair in pairs)
            {
                CheckArbChance(pair);

                if (!pair.IsArbChance)
                {
                    pair.LogMultiplier = 1;
                }
            }

            // 기회를 정렬하여 큰 기회부터 확인한다.
            List<BondPair> arbPairs = (from pair in pairs
                                             where pair.IsArbChance == true
                                             orderby pair.ArbChancePnL descending
                                             select pair).ToList<BondPair>();

            Boolean bArbChance = false;

            if (arbPairs.Count > maxNewSweeperCount)
            {
                logger.Info("EnterSweeperChance ArbPairs({0}) > MaxNewSweeperCount({1})", arbPairs.Count, maxNewSweeperCount);
            }

            foreach (BondPair pair in arbPairs)
            {
                // 기회다 들어가자
                if (maxNewSweeperCount <= 0)
                {
                    break;
                }

                Sweeper_BondArb sweeper = new Sweeper_BondArb(pair, _bondAccount);
                this._node.GetSweeperCollection().Add(sweeper);

                --maxNewSweeperCount;

                bArbChance = true;

                if (pair.LastLoggedDateTime.AddSeconds(pair.LogMultiplier) < DateTime.Now)
                {
                    logger.Info("BondArb Chance #({0:n0}) '{1}'", pair.LogMultiplier, pair.TextLog);
                    pair.LastLoggedDateTime = DateTime.Now;
                    pair.LogMultiplier *= 2;
                }
            }
            return bArbChance;
        }
Exemplo n.º 4
0
        void TestCheckArbChance_NoArbCase3(MonitorEnter_BondArb_Accessor me, ref int innerKillWithNoticeCallingCount)
        {
            BondPair housingBondPair = null;
            RawMarketData rmdNormal = null;
            RawMarketData rmdSmall = null;

            SetHousingBondPairAndRmds(ref housingBondPair, ref rmdNormal, ref rmdSmall);

            int ret = 0;

            // 5000에 사서 15000에 팔 수 있는 기회이다
            SetImmeLongPart(rmdNormal, 100 * CommonConst._1_000 * CommonConst._1_000, 5000);
            SetImmeShortPart(rmdNormal, 0, 0);
            SetImmeLongPart(rmdSmall, 0, 0);
            SetImmeShortPart(rmdSmall, 100 * CommonConst._1_000 * CommonConst._1_000, 15000);

            me.BeforeEnterSweeperChance();
            ret = me.CheckArbChance(housingBondPair);
            Assert.AreEqual(0, ret);

            POrder o = new POrder(TradingDirection.Long, rmdNormal.Code, 50 * CommonConst._1_000 * CommonConst._1_000, rmdNormal.AskPrice1, me._bondAccount, rmdNormal, MarketType._0_Bond_일반, false);
            POrderUtil.RequestOrder(o, null);

            me.BeforeEnterSweeperChance();
            ret = me.CheckArbChance(housingBondPair);
            Assert.AreEqual(-208, ret);

            o.Update(o.ReqCount, 0, true);
            POrderLegalManager.Ins().Remove(o);
            POrderBidAskCountManager.Ins().Unregister(o);

            me.BeforeEnterSweeperChance();
            ret = me.CheckArbChance(housingBondPair);
            Assert.AreEqual(0, ret);

            Sweeper_BondArb sweeper = new Sweeper_BondArb(housingBondPair, me._bondAccount);
            me._node.GetSweeperCollection().Add(sweeper);

            // long쪽에 많지만 sweeper에서 short쪽을 잡아주었기 때문에 이 경우 arb이 성립되지 않는다.
            SetImmeLongPart(rmdNormal, 100 * CommonConst._1_000 * CommonConst._1_000 * CommonConst._1_000, 5000);
            SetImmeShortPart(rmdNormal, 0, 0);
            SetImmeLongPart(rmdSmall, 0, 0);
            SetImmeShortPart(rmdSmall, 150 * CommonConst._1_000 * CommonConst._1_000, 15000);

            me.BeforeEnterSweeperChance();
            ret = me.CheckArbChance(housingBondPair);
            Assert.AreEqual(-208, ret);

            // 다음 테스트 등을 위해서 깨끗이 지워준다.
            Unittest_BondArbUtil.ClearBondAccount(me._bondAccount);

            // rmd도 깨끗이 정리한다.
            SetImmeLongPart(rmdNormal, 0, 0);
            SetImmeShortPart(rmdNormal, 0, 0);
            SetImmeLongPart(rmdSmall, 0, 0);
            SetImmeShortPart(rmdSmall, 0, 0);

            Unittest_BondArbUtil.ClearSweeperCollection(me);
            Unittest_BondArbUtil.ForcedClearPOrderBidAskManager();
        }
Exemplo n.º 5
0
        void TestSweeper_BondArb_SN_Running(MonitorEnter_BondArb_Accessor me, Sweeper_BondArb sweeper)
        {
            Sweeper_BondArb_Accessor accessor = new Sweeper_BondArb_Accessor(new PrivateObject(sweeper));
            Assert.AreEqual(accessor._bDone, false);

            SweepUnitTemplate longSweepUnitTemplate = accessor._sweepUnitLong;
            SweepUnitTemplate_Accessor longSweepUnitTemplate_Accessor = new SweepUnitTemplate_Accessor(new PrivateObject(longSweepUnitTemplate));
            SweepUnitContext_Bond_Long longContext = longSweepUnitTemplate_Accessor.Context as SweepUnitContext_Bond_Long;
            SweepUnitContext_Bond_Long_Accessor longContext_Accessor = new SweepUnitContext_Bond_Long_Accessor(new PrivateObject(longContext));

            SweepUnitTemplate shortSweepUnitTemplate = accessor._sweepUnitShort;
            SweepUnitTemplate_Accessor shortSweepUnitTemplate_Accessor = new SweepUnitTemplate_Accessor(new PrivateObject(shortSweepUnitTemplate));
            SweepUnitContext_Bond_Short shortContext = shortSweepUnitTemplate_Accessor.Context as SweepUnitContext_Bond_Short;
            SweepUnitContext_Bond_Short_Accessor shortContext_Accessor = new SweepUnitContext_Bond_Short_Accessor(new PrivateObject(shortContext));

            // 1. 소액 25,000,000 체결
            POrder initLongOrder0 = longContext_Accessor._initOrders[0];
            // 주문번호 0
            initLongOrder0.OrderNumber = 0;
            initLongOrder0.Update(25 * CommonConst._1_000_000, 5000, false);
            Assert.AreEqual(initLongOrder0.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder0), true);

            Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), 0);
            Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 0);

            initLongOrder0.Update(50 * CommonConst._1_000_000, 5000, true);
            Assert.AreEqual(initLongOrder0.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder0), true);

            Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), 0);
            Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 0);

            POrder initLongOrder1 = longContext_Accessor._initOrders[1];
            initLongOrder1.OrderNumber = 0;
            initLongOrder1.Update(25 * CommonConst._1_000_000, 5000, false);
            Assert.AreEqual(initLongOrder1.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder1), true);

            Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), 0);
            Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 0);

            initLongOrder1.Update(49999000, 5000, false);
            Assert.AreEqual(initLongOrder1.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder1), true);

            Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), 0);
            Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 0);

            // 1억째 되었다
            initLongOrder1.Update(50 * CommonConst._1_000_000, 5000, true);
            Assert.AreEqual(initLongOrder1.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder1), true);

            Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), (-1) * 100 * CommonConst._1_000_000);
            Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 1);

            POrder initLongOrder2 = longContext_Accessor._initOrders[2];
            initLongOrder2.OrderNumber = 0;
            initLongOrder2.Update(50 * CommonConst._1_000_000, 5000, true);
            Assert.AreEqual(initLongOrder2.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder2), true);

            Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), (-1) * 100 * CommonConst._1_000_000);
            Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 1);

            POrder initLongOrder3 = longContext_Accessor._initOrders[3];
            initLongOrder3.OrderNumber = 0;
            initLongOrder3.Update(49999000, 5000, false);
            Assert.AreEqual(initLongOrder3.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder3), true);
            Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), (-1) * 100 * CommonConst._1_000_000);
            Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 1);

            initLongOrder3.Update(50000000, 5000, true);
            Assert.AreEqual(initLongOrder3.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder3), true);
            Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), (-1) * 200 * CommonConst._1_000_000);
            Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 2);

            // balance order
            POrder balanceOrder1 = shortContext_Accessor.RealOrdersShort[0];
            Assert.AreEqual(balanceOrder1.Code, _kHousingBondCode_Normal);
            Assert.AreEqual(balanceOrder1.LongShort, TradingDirection.Short);
            Assert.AreEqual(balanceOrder1.ReqCount, 100 * CommonConst._1_000_000);
            Assert.AreEqual(balanceOrder1.ReqPrice, 15000);

            POrder balanceOrder2 = shortContext_Accessor.RealOrdersShort[1];
            Assert.AreEqual(balanceOrder2.Code, _kHousingBondCode_Normal);
            Assert.AreEqual(balanceOrder2.LongShort, TradingDirection.Short);
            Assert.AreEqual(balanceOrder2.ReqCount, 100 * CommonConst._1_000_000);
            Assert.AreEqual(balanceOrder2.ReqPrice, 15000);

            // 2. 일반을 79,900,000만큼 체결시킨다.
            balanceOrder1.Update(79900 * CommonConst._1_000, 5000, false);
            Assert.AreEqual(balanceOrder1.ShortCutTargetOfContractCallBack.Contract_CallBack(balanceOrder1), true);

            // 4. Sweep 테스트를 진행한다.

            longSweepUnitTemplate_Accessor.CurState = SweepUnitTemplate.StateEnum._2_WaitUntilGotAllOrderNumber;
            shortSweepUnitTemplate_Accessor.CurState = SweepUnitTemplate.StateEnum._2_WaitUntilGotAllOrderNumber;

            balanceOrder1.OrderNumber = 0;
            balanceOrder2.OrderNumber = 0;

            POrder initLongOrder4 = longContext_Accessor._initOrders[4];
            POrder initLongOrder5 = longContext_Accessor._initOrders[5];

            initLongOrder4.OrderNumber = 0;
            initLongOrder5.OrderNumber = 0;

            Assert.AreEqual(sweeper.Run(), false);

            Assert.AreEqual(longSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._3_WaitUntilCancelAllOrders);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._3_WaitUntilCancelAllOrders);

            initLongOrder4.Update(CommonConst._1_000, 5000, false);
            initLongOrder4.UpdateCancelMessage(initLongOrder4.ReqCount - CommonConst._1_000);
            initLongOrder5.UpdateCancelMessage(initLongOrder5.ReqCount);

            balanceOrder1.UpdateCancelMessage(balanceOrder1.ReqCount - balanceOrder1.ContractedCount);
            balanceOrder2.UpdateCancelMessage(balanceOrder2.ReqCount - balanceOrder2.ContractedCount);

            Assert.AreEqual(sweeper.Run(), false);

            Assert.AreEqual(longSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._4_WaitingRunSign);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._4_WaitingRunSign);

            Assert.AreEqual(longContext_Accessor.CurSignedTargetCount, 300 * CommonConst._1_000_000);
            Assert.AreEqual(shortContext_Accessor.CurSignedTargetCount, (-1) * 300 * CommonConst._1_000_000);

            //Resume
            Assert.AreEqual(sweeper.Run(), false);

            Assert.AreEqual(longContext_Accessor.CurSignedTargetCount, 200 * CommonConst._1_000_000 + CommonConst._1_000);
            Assert.AreEqual(shortContext_Accessor.CurSignedTargetCount, (-1) * (200 * CommonConst._1_000_000 + CommonConst._1_000));

            Assert.AreEqual(longSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._7_Done);

            POrder sweepOrder1 = shortContext_Accessor.RealOrdersShort[2];
            POrder sweepOrder2 = shortContext_Accessor.RealOrdersShort[3];
            POrder sweepOrder3 = shortContext_Accessor.RealOrdersShort[4];

            //121,001,000
            Assert.AreEqual(sweepOrder1.ReqCount, 50 * CommonConst._1_000_000);
            Assert.AreEqual(sweepOrder2.ReqCount, 50 * CommonConst._1_000_000);
            Assert.AreEqual(sweepOrder3.ReqCount, 20101000);

            Assert.AreEqual(sweepOrder1.Code, _kHousingBondCode_Small);
            Assert.AreEqual(sweepOrder2.Code, _kHousingBondCode_Small);
            Assert.AreEqual(sweepOrder3.Code, _kHousingBondCode_Small);

            Assert.AreEqual(sweepOrder1.LongShort, TradingDirection.Short);
            Assert.AreEqual(sweepOrder2.LongShort, TradingDirection.Short);
            Assert.AreEqual(sweepOrder3.LongShort, TradingDirection.Short);

            Assert.AreEqual(sweepOrder1.ReqPrice, 15000);
            Assert.AreEqual(sweepOrder2.ReqPrice, 15000);
            Assert.AreEqual(sweepOrder3.ReqPrice, 15000);

            Assert.AreEqual(shortSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._6_MonitorRequestedSweepOrders);

            Timer_Accessor mute_Accessor = new Timer_Accessor(new PrivateObject(shortSweepUnitTemplate_Accessor._mute));

            // 더이상 On이 풀리지 않는다.
            Assert.AreEqual(mute_Accessor.m_end > DateTime.Now.AddHours(1), true);

            // 여기서 많이 불러봐도 소용없다.
            Assert.AreEqual(sweeper.Run(), false);

            sweepOrder1.Update(50000000, 15000, true);
            sweepOrder2.Update(50000000, 15000, true);

            Assert.AreEqual(sweeper.Run(), false);

            sweepOrder3.Update(20101000, 15000, true);

            Assert.AreEqual(sweeper.Run(), true);
        }
Exemplo n.º 6
0
        void TestSweeper_BondArb_SN_Init(MonitorEnter_BondArb_Accessor me, Sweeper_BondArb sweeper)
        {
            Sweeper_BondArb_Accessor accessor = new Sweeper_BondArb_Accessor(new PrivateObject(sweeper));
            Assert.AreEqual(accessor._bDone, false);

            SweepUnitTemplate longSweepUnitTemplate = accessor._sweepUnitLong;
            SweepUnitTemplate_Accessor longSweepUnitTemplate_Accessor = new SweepUnitTemplate_Accessor(new PrivateObject(longSweepUnitTemplate));
            SweepUnitContext_Bond_Long longContext = longSweepUnitTemplate_Accessor.Context as SweepUnitContext_Bond_Long;
            SweepUnitContext_Bond_Long_Accessor longContext_Accessor = new SweepUnitContext_Bond_Long_Accessor(new PrivateObject(longContext));

            SweepUnitTemplate shortSweepUnitTemplate = accessor._sweepUnitShort;
            SweepUnitTemplate_Accessor shortSweepUnitTemplate_Accessor = new SweepUnitTemplate_Accessor(new PrivateObject(shortSweepUnitTemplate));
            SweepUnitContext_Bond_Short shortContext = shortSweepUnitTemplate_Accessor.Context as SweepUnitContext_Bond_Short;
            SweepUnitContext_Bond_Short_Accessor shortContext_Accessor = new SweepUnitContext_Bond_Short_Accessor(new PrivateObject(shortContext));

            // 초기 주문이 잘 들어갔는지 검사한다.

            // 템플릿 상태는 모두 _1_MuteFewSecsAfterInitOrders이고 Long쪽은 주문이 들어가 있어야 한다.

            Assert.AreEqual(longSweepUnitTemplate_Accessor._aging, 0);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor._aging, 0);

            Assert.AreEqual(longSweepUnitTemplate_Accessor._bCompleteQuickly, false);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor._bCompleteQuickly, false);

            Assert.AreEqual(longSweepUnitTemplate_Accessor._bResumed, false);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor._bResumed, false);

            Assert.AreEqual(longSweepUnitTemplate_Accessor._maxWaiting, null);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor._maxWaiting, null);

            Assert.AreEqual(longSweepUnitTemplate_Accessor._mute.On(), true);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor._mute.On(), true);

            Assert.AreEqual(longSweepUnitTemplate_Accessor._muteSec, 5);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor._muteSec, 5);

            Assert.AreEqual(longSweepUnitTemplate_Accessor._sweepMonitorSec, SweepUnitTemplate.SLOW_SWEEP_SEC);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor._sweepMonitorSec, SweepUnitTemplate.SLOW_SWEEP_SEC);

            Assert.AreEqual(longSweepUnitTemplate_Accessor.CurOverviewState, SweepUnitTemplate.OverviewState.Enter);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor.CurOverviewState, SweepUnitTemplate.OverviewState.Enter);

            Assert.AreEqual(longSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._1_MuteFewSecsAfterInitOrders);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._1_MuteFewSecsAfterInitOrders);

            Assert.AreEqual(longSweepUnitTemplate_Accessor.GetSignedPossibleContractCount(), 300 * CommonConst._1_000_000);
            // 주문 낸 것이 없으로 Short part에서는 0
            Assert.AreEqual(shortSweepUnitTemplate_Accessor.GetSignedPossibleContractCount(), 0);

            // 아직 체결된 것이 없으므로 둘다 0
            Assert.AreEqual(longSweepUnitTemplate_Accessor.GetSignedContractedCount(), 0);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor.GetSignedContractedCount(), 0);

            Assert.AreEqual(longSweepUnitTemplate_Accessor.IsException(), false);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor.IsException(), false);

            Assert.AreEqual(longSweepUnitTemplate_Accessor.IsOverAging(), false);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor.IsOverAging(), false);

            // Context를 검사한다.
            Assert.AreEqual(longContext_Accessor._bCalledAfterSetTarget, false);

            Assert.AreEqual(longContext_Accessor._dummyShortOrderForReserveBidAskCount.ReqCount, 300 * CommonConst._1_000_000);
            Assert.AreEqual(longContext_Accessor._dummyShortOrderForReserveBidAskCount.ReqPrice, 15000);
            Assert.AreEqual(longContext_Accessor._enterMarketType, MarketType._1_Bond_소액);
            Assert.AreEqual(longContext_Accessor._initEnterPrice, 5000);
            Assert.AreEqual(longContext_Accessor._initOrders.Count, 6);

            POrder initLongOrder = longContext_Accessor._initOrders[0];

            Assert.AreEqual(initLongOrder.ReqCount, 50 * CommonConst._1_000_000);
            Assert.AreEqual(initLongOrder.ReqPrice, 5000);
            Assert.AreEqual(initLongOrder.Market, MarketType._1_Bond_소액);
            Assert.AreEqual(initLongOrder.LongShort, TradingDirection.Long);
            Assert.AreEqual(initLongOrder.Code, _kHousingBondCode_Small);
            Assert.AreEqual(initLongOrder.CodeNoTail, _kHousingBondCodeNoTail);

            Assert.AreEqual(shortContext_Accessor._enterMarketType, MarketType._1_Bond_소액);
            Assert.AreEqual(shortContext_Accessor._pairMarketType, MarketType._0_Bond_일반);
            Assert.AreEqual(shortContext_Accessor.CurSignedTargetCount, (-1) * 300 * CommonConst._1_000_000);

            Assert.AreEqual(shortContext_Accessor.EnterCode, _kHousingBondCode_Small);
            Assert.AreEqual(shortContext_Accessor.LongShort, TradingDirection.Short);
            Assert.AreEqual(shortContext_Accessor.PairCode, _kHousingBondCode_Normal);
        }
Exemplo n.º 7
0
        void TestSweeper_BondArb_NR_Running(MonitorEnter_BondArb_Accessor me, Sweeper_BondArb sweeper)
        {
            Sweeper_BondArb_Accessor accessor = new Sweeper_BondArb_Accessor(new PrivateObject(sweeper));
            Assert.AreEqual(accessor._bDone, false);

            SweepUnitTemplate longSweepUnitTemplate = accessor._sweepUnitLong;
            SweepUnitTemplate_Accessor longSweepUnitTemplate_Accessor = new SweepUnitTemplate_Accessor(new PrivateObject(longSweepUnitTemplate));
            SweepUnitContext_Bond_Long longContext = longSweepUnitTemplate_Accessor.Context as SweepUnitContext_Bond_Long;
            SweepUnitContext_Bond_Long_Accessor longContext_Accessor = new SweepUnitContext_Bond_Long_Accessor(new PrivateObject(longContext));

            SweepUnitTemplate shortSweepUnitTemplate = accessor._sweepUnitShort;
            SweepUnitTemplate_Accessor shortSweepUnitTemplate_Accessor = new SweepUnitTemplate_Accessor(new PrivateObject(shortSweepUnitTemplate));
            SweepUnitContext_Bond_Short shortContext = shortSweepUnitTemplate_Accessor.Context as SweepUnitContext_Bond_Short;
            SweepUnitContext_Bond_Short_Accessor shortContext_Accessor = new SweepUnitContext_Bond_Short_Accessor(new PrivateObject(shortContext));

            // 1. 소액 25,000,000 체결
            POrder initLongOrder0 = longContext_Accessor._initOrders[0];
            // 주문번호 0
            initLongOrder0.OrderNumber = 0;
            initLongOrder0.Update(25 * CommonConst._1_000_000, 5000, false);
            Assert.AreEqual(initLongOrder0.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder0), true);

            Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), (-1) * 25000000);
            Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 1);

            initLongOrder0.Update(50 * CommonConst._1_000_000, 5000, false);
            Assert.AreEqual(initLongOrder0.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder0), true);

            Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), (-1) * 50000000);
            Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 2);

            initLongOrder0.Update(200 * CommonConst._1_000_000, 5000, false);
            Assert.AreEqual(initLongOrder0.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder0), true);

            Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), (-1) * 200 * CommonConst._1_000_000);
            Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 3);

            POrder balanceOrder0 = shortContext_Accessor.RealOrdersShort[0];
            POrder balanceOrder1 = shortContext_Accessor.RealOrdersShort[1];
            POrder balanceOrder2 = shortContext_Accessor.RealOrdersShort[2];

            balanceOrder0.OrderNumber = 0;
            balanceOrder1.OrderNumber = 0;
            balanceOrder2.OrderNumber = 0;

            // balance order
            Assert.AreEqual(balanceOrder0.Code, _kDoosanCode_Retail);
            Assert.AreEqual(balanceOrder0.LongShort, TradingDirection.Short);
            Assert.AreEqual(balanceOrder0.ReqCount, 25 * CommonConst._1_000_000);
            Assert.AreEqual(balanceOrder0.ReqPrice, 15000);

            // balance order 25,000,000 체결시킨다
            balanceOrder0.Update(25 * CommonConst._1_000_000, 15000, true);

            // 4. Sweep 테스트를 진행한다.

            longSweepUnitTemplate_Accessor.CurState = SweepUnitTemplate.StateEnum._2_WaitUntilGotAllOrderNumber;
            shortSweepUnitTemplate_Accessor.CurState = SweepUnitTemplate.StateEnum._2_WaitUntilGotAllOrderNumber;

            Assert.AreEqual(sweeper.Run(), false);

            Assert.AreEqual(longSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._3_WaitUntilCancelAllOrders);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._3_WaitUntilCancelAllOrders);

            initLongOrder0.UpdateCancelMessage(initLongOrder0.ReqCount - initLongOrder0.ContractedCount);
            balanceOrder0.UpdateCancelMessage(balanceOrder0.ReqCount - balanceOrder0.ContractedCount);
            balanceOrder1.UpdateCancelMessage(balanceOrder1.ReqCount - balanceOrder1.ContractedCount);
            balanceOrder2.UpdateCancelMessage(balanceOrder2.ReqCount - balanceOrder2.ContractedCount);

            Assert.AreEqual(sweeper.Run(), false);

            Assert.AreEqual(longSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._4_WaitingRunSign);
            Assert.AreEqual(shortSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._4_WaitingRunSign);

            Assert.AreEqual(longContext_Accessor.CurSignedTargetCount, 300 * CommonConst._1_000_000);
            Assert.AreEqual(shortContext_Accessor.CurSignedTargetCount, (-1) * 300 * CommonConst._1_000_000);

            //Resume
            Assert.AreEqual(sweeper.Run(), false);

            Assert.AreEqual(longContext_Accessor.CurSignedTargetCount, 200 * CommonConst._1_000_000);
            Assert.AreEqual(shortContext_Accessor.CurSignedTargetCount, (-1) * 200 * CommonConst._1_000_000);

            Assert.AreEqual(longSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._7_Done);

            POrder sweepOrder = shortContext_Accessor.RealOrdersShort[3];

            Assert.AreEqual(sweepOrder.ReqCount, 175 * CommonConst._1_000_000);
            Assert.AreEqual(sweepOrder.Code, _kDoosanCode_Retail);
            Assert.AreEqual(sweepOrder.LongShort, TradingDirection.Short);
            Assert.AreEqual(sweepOrder.ReqPrice, 15000);

            Assert.AreEqual(shortSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._6_MonitorRequestedSweepOrders);

            Timer_Accessor mute_Accessor = new Timer_Accessor(new PrivateObject(shortSweepUnitTemplate_Accessor._mute));

            // 더이상 On이 풀리지 않는다.
            Assert.AreEqual(mute_Accessor.m_end > DateTime.Now.AddHours(1), true);

            // 여기서 많이 불러봐도 소용없다.
            Assert.AreEqual(sweeper.Run(), false);

            sweepOrder.Update(100 * CommonConst._1_000_000, 15000, false);

            Assert.AreEqual(sweeper.Run(), false);

            sweepOrder.Update(175 * CommonConst._1_000_000, 15000, true);

            Assert.AreEqual(sweeper.Run(), true);
        }
        void CreateOneSweeperAndSaveToUnittestFolder_NR()
        {
            // STR_Arb을 생성하여 MonitorEnter_BondArbTest를 생성한다.
            STR_Arb_Accessor arb = Unittest_BondArbUtil.CreateNewStrArbAccessor();
            StrategyNode node = arb._bondArbNode as StrategyNode;
            StrategyNode_Accessor nodeAccessor = new StrategyNode_Accessor(new PrivateObject(node));
            MonitorEnter_BondArb me = nodeAccessor._monitorEnter as MonitorEnter_BondArb;
            MonitorEnter_BondArb_Accessor meAccessor = new MonitorEnter_BondArb_Accessor(new PrivateObject(me));

            // 1. Create one sweeper
            BondPair doosanBondPair = null;
            RawMarketData rmdNormal = null;
            RawMarketData rmdRetail = null;

            SetCreditBondPairAndRmds(ref doosanBondPair, ref rmdNormal, ref rmdRetail);

            SetAsZeroRMD(ref rmdNormal);
            SetAsZeroRMD(ref rmdRetail);

            int ret = 0;

            // 5000에 일반을 사서 15000에 소매에 팔 수 있는 기회이다
            SetImmeLongPart(rmdNormal, 300 * CommonConst._1_000 * CommonConst._1_000, 5000);
            SetImmeShortPart(rmdNormal, 0, 0);
            SetImmeLongPart(rmdRetail, 0, 0);
            SetImmeShortPart(rmdRetail, 300 * CommonConst._1_000 * CommonConst._1_000, 15000);

            me.BeforeEnterSweeperChance();
            ret = meAccessor.CheckArbChance(doosanBondPair);

            Sweeper_BondArb sweeper = new Sweeper_BondArb(doosanBondPair, meAccessor._bondAccount);
            meAccessor._node.GetSweeperCollection().Add(sweeper);

            {
                Sweeper_BondArb_Accessor accessor = new Sweeper_BondArb_Accessor(new PrivateObject(sweeper));
                Assert.AreEqual(accessor._bDone, false);

                SweepUnitTemplate longSweepUnitTemplate = accessor._sweepUnitLong;
                SweepUnitTemplate_Accessor longSweepUnitTemplate_Accessor = new SweepUnitTemplate_Accessor(new PrivateObject(longSweepUnitTemplate));
                SweepUnitContext_Bond_Long longContext = longSweepUnitTemplate_Accessor.Context as SweepUnitContext_Bond_Long;
                SweepUnitContext_Bond_Long_Accessor longContext_Accessor = new SweepUnitContext_Bond_Long_Accessor(new PrivateObject(longContext));

                SweepUnitTemplate shortSweepUnitTemplate = accessor._sweepUnitShort;
                SweepUnitTemplate_Accessor shortSweepUnitTemplate_Accessor = new SweepUnitTemplate_Accessor(new PrivateObject(shortSweepUnitTemplate));
                SweepUnitContext_Bond_Short shortContext = shortSweepUnitTemplate_Accessor.Context as SweepUnitContext_Bond_Short;
                SweepUnitContext_Bond_Short_Accessor shortContext_Accessor = new SweepUnitContext_Bond_Short_Accessor(new PrivateObject(shortContext));

                POrder initLongOrder0 = longContext_Accessor._initOrders[0];
                // 주문번호 0
                initLongOrder0.OrderNumber = 0;
                initLongOrder0.Update(25 * CommonConst._1_000_000, 5000, false);
                Assert.AreEqual(initLongOrder0.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder0), true);

                Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), (-1) * 25000000);
                Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 1);

                initLongOrder0.Update(50 * CommonConst._1_000_000, 5000, false);
                Assert.AreEqual(initLongOrder0.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder0), true);

                Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), (-1) * 50000000);
                Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 2);

                // 2억 체결
                initLongOrder0.Update(200 * CommonConst._1_000_000, 5000, false);
                Assert.AreEqual(initLongOrder0.ShortCutTargetOfContractCallBack.Contract_CallBack(initLongOrder0), true);

                Assert.AreEqual(shortSweepUnitTemplate.GetSignedPossibleContractCount(), (-1) * 200 * CommonConst._1_000_000);
                Assert.AreEqual(shortContext_Accessor.RealOrdersShort.Count, 3);

                POrder balanceOrder0 = shortContext_Accessor.RealOrdersShort[0];
                POrder balanceOrder1 = shortContext_Accessor.RealOrdersShort[1];
                POrder balanceOrder2 = shortContext_Accessor.RealOrdersShort[2];

                balanceOrder0.OrderNumber = 0;
                balanceOrder1.OrderNumber = 0;
                balanceOrder2.OrderNumber = 0;

                // balance order
                Assert.AreEqual(balanceOrder0.Code, _kDoosanCode_Retail);
                Assert.AreEqual(balanceOrder0.LongShort, TradingDirection.Short);
                Assert.AreEqual(balanceOrder0.ReqCount, 25 * CommonConst._1_000_000);
                Assert.AreEqual(balanceOrder0.ReqPrice, 15000);

                // balance order 25,000,000 체결시킨다
                balanceOrder0.Update(25 * CommonConst._1_000_000, 15000, true);

                // Sweep
                longSweepUnitTemplate_Accessor.CurState = SweepUnitTemplate.StateEnum._2_WaitUntilGotAllOrderNumber;
                shortSweepUnitTemplate_Accessor.CurState = SweepUnitTemplate.StateEnum._2_WaitUntilGotAllOrderNumber;

                Assert.AreEqual(sweeper.Run(), false);

                Assert.AreEqual(longSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._3_WaitUntilCancelAllOrders);
                Assert.AreEqual(shortSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._3_WaitUntilCancelAllOrders);

                initLongOrder0.UpdateCancelMessage(initLongOrder0.ReqCount - initLongOrder0.ContractedCount);
                balanceOrder0.UpdateCancelMessage(balanceOrder0.ReqCount - balanceOrder0.ContractedCount);
                balanceOrder1.UpdateCancelMessage(balanceOrder1.ReqCount - balanceOrder1.ContractedCount);
                balanceOrder2.UpdateCancelMessage(balanceOrder2.ReqCount - balanceOrder2.ContractedCount);

                Assert.AreEqual(sweeper.Run(), false);

                Assert.AreEqual(longSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._4_WaitingRunSign);
                Assert.AreEqual(shortSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._4_WaitingRunSign);

                Assert.AreEqual(longContext_Accessor.CurSignedTargetCount, 300 * CommonConst._1_000_000);
                Assert.AreEqual(shortContext_Accessor.CurSignedTargetCount, (-1) * 300 * CommonConst._1_000_000);

                //Resume
                Assert.AreEqual(sweeper.Run(), false);

                Assert.AreEqual(longContext_Accessor.CurSignedTargetCount, 200 * CommonConst._1_000_000);
                Assert.AreEqual(shortContext_Accessor.CurSignedTargetCount, (-1) * 200 * CommonConst._1_000_000);

                Assert.AreEqual(longSweepUnitTemplate_Accessor.CurState, SweepUnitTemplate.StateEnum._7_Done);
            }

            // 2. save to unittest folder
            arb.SaveBondArbRemainPosition(Const.UNITTEST_BOND_ARB_REMAIN_POSITION_PATH);

            SetAsZeroAllCodes();
        }
Exemplo n.º 9
0
        void TakeOverBondArbYesterdayPosition(String path)
        {
            // 포지션 승계는 한번만 해야 되고 포지션 저장을 한 뒤에는 못한다.
            // 포지션 저장을 먼저 한 뒤에 승계를 해버리면 중복해서 매도 주문이 나갈 가능성이 생기는 데, 이건 큰 문제이다.
            if (_bTakeOverBondArbYesterdayPosition)
            {
                logger.Warn("You already TakeOverBondArbYesterdayPosition");
                return;
            }
            _bTakeOverBondArbYesterdayPosition = true;

            if (_bSaveBondArbPosition)
            {
                logger.Warn("You already SaveBondArbPosition. If you continue this process, remain position data will be broken, so I jump out this process for safety...");
                return;
            }

            // file에서 값을 읽어온다.
            RemainBondArbPositionDataManager.Ins().ReloadData(path);
            List<RemainPositionDatum> data = RemainBondArbPositionDataManager.Ins().GetData();

            foreach (RemainPositionDatum datum in data)
            {
                RmdManager.Ins().BondSpot.Register(datum.EnterCodeWithMarketType);
                RmdManager.Ins().BondSpot.Register(datum.PairCodeWithMarketType);

                RawMarketData rmdEnter = RmdManager.Ins().BondSpot.GetDataClone(datum.EnterCodeWithMarketType);

                POrder o = new POrder(
                    TradingDirection.Long,
                    datum.EnterCodeWithMarketType,
                    datum.CurTargetCount,
                    datum.EnterPrice,
                    this.BondAccount,
                    rmdEnter,
                    BondUtil.GetMarketType(datum.EnterCodeWithMarketType),
                    false);

                this.BondAccount.RegisterAsAllContract(o);

                Sweeper_BondArb sweeper = new Sweeper_BondArb();
                sweeper.SetAsSweeperMode(this.BondAccount, datum);
                this._bondArbNode.GetSweeperCollection().Add(sweeper);
            }
        }