public long GetPartialContractCount(POrder o)
        {
            RawMarketData rmd = RmdManager.Ins().GetData(o.Code);

            if (o.LongShort == TradingDirection.Long)
            {
                // 매수인데 현재 AskPrice가 매수가보다 낮다. 모두 체결되었다고 가정한다.
                if (rmd.AskPrice1 > 0 && rmd.AskPrice1 <= o.ReqPrice)
                {
                    return o.ReqCount;
                }
                else
                {
                    // 그렇지 않다면 체결되지 않았다.
                    return 0;
                }
            }
            else
            {
                // 매도인데 현재 BidPrice가 요청가보다 높다. 모두 체결되었다.
                if (rmd.BidPrice1 >= o.ReqPrice)
                {
                    return o.ReqCount;
                }
                else
                {
                    // 그렇지 않다면 체결되지 않았다.
                    return 0;
                }
            }
        }
示例#2
0
        public SweepUnit_OE(
            POrder goalOrder, 
            Account accountFO, 
            Account accountSpot, 
            OptionTribe ot,
            ISweeper parent,
            Boolean bConservativeOptionPolicyOn,
            int muteSec)
        {
            ID = SweepUnitIDManager.NextID++;

            _parent = parent;

            GoalOrder = goalOrder;

            RealOrders = new List<POrder>();
            _ot = ot;

            _mute = new Timer(muteSec, ""); // 2초

            _candidateCodes = ElwOptionUtil.GetSameCandidateCodes(goalOrder.Code);

            _accountSpot = accountSpot;
            _accountFO = accountFO;

            _bConservativeOptionPolicyOn = bConservativeOptionPolicyOn;

            if (!RequestInitOrder())
            {
                GoalOrder.Free();
            }

            _State = State._1_MuteFewSecs;
            ShowState();
        }
        public Boolean IsOK(POrder o)
        {
            if (o.LongShort == TradingDirection.Long)
            {
                // 가격이 longUpperLimit(12,000)보다 작아야 한다.
                if (o.ReqPrice < _longUpperLimit)
                {
                    // ok
                }
                else
                {
                    logger.Error("Order price {0:n2} > long upper limit {1:n2}", o.ReqPrice, _longUpperLimit);
                    Util.KillWithNotice("Order price > long upper limit");
                    return false;
                }
            }
            else
            {
                // 가격이 shortLowerLimit(8,000)보다 커야 한다.
                if (o.ReqPrice > _shortLowerLimit)
                {
                    // ok
                }
                else
                {
                    logger.Error("Order price {0:n2} < short lower limit {1:n2}", o.ReqPrice, _shortLowerLimit);
                    Util.KillWithNotice("Order price < short lower limit");
                    return false;
                }
            }

            return _orderLimit.IsOK(o);
        }
 public Boolean IsOK(POrder o)
 {
     // Pass Test
     logger.Error("여기는 실주문 프로그램에서는 오면 안되는 지점입니다.");
     Util.KillWithNotice("여기는 실주문 프로그램에서는 오면 안되는 지점입니다. 유닛테스트는 OK");
     return false;
 }
示例#5
0
        public static double GetAvgPrice(POrder o1, POrder o2)
        {
            double value = (o1.AvgContractPrice * o1.ContractedCount) + (o2.AvgContractPrice * o2.ContractedCount);
            long count = o1.ContractedCount + o2.ContractedCount;

            return value / count;
        }
示例#6
0
        public Boolean IsOK(POrder o)
        {
            if (_account == null)
            {
                logger.Error("[DefaultOrderLimit] account가 null이다. {0} != {1}", o.Code, o.RMDClone);
                Util.KillWithNotice("[DefaultOrderLimit] account가 null이다.");
                return false;
            }

            if (!Util.IsCorrectCodeMatch(o.Code, o.RMDClone))
            {
                logger.Error("[DefaultOrderLimit] Order.Code != RMD.Code, ({0} != {1})", o.Code, o.RMDClone);
                logger.Error("ERROR ORDER[{0}]", o.ToString());
                Util.KillWithNotice("[DefaultOrderLimit] error");

                return false;
            }

            if (!POrderLegalManager.Ins().IsLegalOrder(o, true))
            {
                logger.Error("[DefaultOrderLimit] Legal Problem ({0})", o.Code);
                logger.Error("ERROR ORDER[{0}]", o.ToString());
                Util.KillWithNotice("[DefaultOrderLimit] Legal Problem");

                return false;
            }

            return true;
        }
示例#7
0
 public Sweeper_Door(POrder o, SweeperController_Door parent, int roundCount)
 {
     _enteredOrder = o;
     _parent = parent;
     this.ID = IDGenerator++;
     this.RoundCount = roundCount;
 }
示例#8
0
        public SweepUnit_FO(
            long signedGoalCountFO,
            String code,
            double initEnterPrice,
            POrder initOrder,
            Account accountFO,
            ISweeper parent,
            int muteSec)
        {
            this.ID = SweepUnitIDManager.NextID++;

            this.InitEnterPrice = initEnterPrice;
            this.InitSignedGoalCount = this.CurSignedTargetCount = signedGoalCountFO;
            this.Code = code;
            this._initOrder = initOrder;
            this.AccountFO = accountFO;
            this._parent = parent;
            this._muteSec = muteSec;
            this.InitLongShort = InitSignedGoalCount > 0 ? TradingDirection.Long : TradingDirection.Short;

            this._mute = new Timer(muteSec, "");
            this._bResumed = false;
            this._bCompleteQuickly = false;

            this.RealOrders = new List<POrder>();

            RequestInitOrder();
        }
示例#9
0
        void KtbFutureTest()
        {
            String future10yrCode = KtbFutureUtil.Ins().KtbFuture_10yr_1.Code;
            {
                TradingDirection longShort = TradingDirection.Long;
                string code = future10yrCode;
                long reqCount = 10;
                double reqPrice = 105.10;
                Account account = AccountManager.Ins().CreateSimFOAccount();

                IOrderLimit orderLimit = new DefaultOrderLimit(account);
                orderLimit = new LimOrderLimit(orderLimit);

                account.SetOrderLimit(orderLimit);

                RawMarketData rmdClone = new RawMarketData(future10yrCode, Detail.ProductType.KtbFuture);
                rmdClone.BidPrice1 = 105.10;
                rmdClone.AskPrice1 = 105.15;

                POrder target = new POrder(longShort, code, reqCount, reqPrice, account, rmdClone);
                bool success = POrderUtil.RequestOrder(target, null);
                Assert.AreEqual(true, success);

                target.UpdateCancelMessage(target.ReqCount);

                POrder_UnittestUtil.ClearOrder(target);
            }
        }
        public Boolean IsOK(POrder o)
        {
            RawMarketData rmd = o.RMDClone;
            double opa = ProductUtil.Ins().GetOnePointAmount(o.Code);

            double value = Math.Abs(opa * o.ReqCount * Math.Max(rmd.CurPrice, o.ReqPrice));

            if (_maxValue < _curValue + value)
            {
                try
                {
                    logger.Error("[ValuePerMinuteOrderLimit] {0} < {1} + {2}", _maxValue, _curValue, value);
                    Util.KillWithNotice("[ValuePerMinuteOrderLimit] error");
                    logger.Error("ERROR ORDER[{0}]", o.ToString());
                    Util.KillWithNotice("ERROR ORDER");
                }
                catch (System.Exception ex)
                {
                    logger.Error(ex.ToString());
                    Util.KillWithNotice(ex.ToString());
                }
                return false;
            }

            return _decorator.IsOK(o);
        }
        public S4_CancelRemains_PositionTakerState(PositionTakerController parent, POrder thisTurnOrder)
        {
            _parent = parent;
            this.ThisTurnOrder = thisTurnOrder;

            this.ThisTurnOrder.CancelRemains();
        }
示例#12
0
        public void TestPOrderLegalData()
        {
            string code = "201EC260";
            RawMarketData rmd = new RawMarketData(code, Detail.ProductType.CallOption);
            rmd.BidPrice1 = 0.81000001F;
            rmd.BidCount1 = 1000;
            rmd.AskPrice1 = 0.81999999F;
            rmd.AskCount1 = 1000;

            Account simAccount = AccountManager.Ins().CreateSimFOAccount();

            POrder o0 = new POrder(TradingDirection.Long, code, 1, 0.81, simAccount, rmd);
            POrderLegalManager.Ins().Add(o0);

            {

                POrder o2 = new POrder(TradingDirection.Long, code, 1, 0.81, simAccount, rmd);
                Boolean success = POrderLegalManager.Ins().Remove(o2);
                Assert.AreEqual(success, false);
            }

            {
                POrder o = new POrder(TradingDirection.Short, code, 1, 0.8099998, simAccount, rmd);
                POrder_Accessor oAccessor = new POrder_Accessor(o);
                oAccessor.ReqPrice = 0.810006;

                Boolean legal = POrderLegalManager.Ins().IsLegalOrder(o, false);
                Assert.AreEqual(legal, false);

                o.SetAsLegalPrice();
                legal = POrderLegalManager.Ins().IsLegalOrder(o, false);
                Assert.AreEqual(legal, true);

                Util.LogOutCriticalError("\t\t # Non exist code search 1 permitted.");
                Boolean success = POrderLegalManager.Ins().Remove(o);
                Assert.AreEqual(success, false);

                POrderLegalManager.Ins().Add(o);

                POrder o2 = new POrder(TradingDirection.Short, code, 1, 0.8099998, simAccount, rmd);
                success = POrderLegalManager.Ins().Remove(o2);
                Assert.AreEqual(success, false);

                // test reverse
                {
                    POrder o3 = new POrder(TradingDirection.Long, code, 1, 0.83, simAccount, rmd);
                    POrder_Accessor oAccessor3 = new POrder_Accessor(o3);
                    oAccessor3.ReqPrice = 0.83;

                    legal = POrderLegalManager.Ins().IsLegalOrder(o3, false);
                    Assert.AreEqual(legal, false);

                    POrderLegalManager.Ins().Remove(o3);
                }
                POrderLegalManager.Ins().Remove(o2);
                POrderLegalManager.Ins().Remove(o);
            }
            POrderLegalManager.Ins().Remove(o0);
        }
示例#13
0
        public void AddPOrderAsCC_WithChangeSign(POrder o)
        {
            CodeCount cc = new CodeCount();
            cc.Code = o.Code;
            cc.Count = o.GetSignedContractedCount() * (-1);

            _ccs.Add(cc);
        }
示例#14
0
 public Boolean Contract_CallBack(POrder order)
 {
     if (SweepUnit.Contract_CallBack(order))
     {
         return true;
     }
     return false;
 }
示例#15
0
 public SimPOrder(POrder pOrder, long period)
 {
     _pOrder = pOrder;
     _State = State.접수;
     SchedulingTime = DateTime.Now.AddMilliseconds(period);
     PartialContractScheduledCount = 0;
     CurTotalContractedCount = 0;
 }
示例#16
0
 public Boolean Contract_CallBack(POrder order)
 {
     if (_elwOOR.Contract_CallBack(order))
     {
         return true;
     }
     return false;
 }
        public Boolean IsOK(POrder o)
        {
            RawMarketData rmd = o.RMDClone;

            if (o.TargetAccount.LineType == Account.OrderLineType.StockSpotLine)
            {
                return _decorator.IsOK(o);
            }
            else if (o.TargetAccount.LineType == Account.OrderLineType.FutureOptionSpreadLine)
            {
                Detail.ProductType dpt = ProductUtil.Ins().GetProductType(o.Code);

                double downLimitPrice = 0;
                double upLimitPrice = 0;

                if (dpt == Detail.ProductType.KospiFuture)
                {
                    downLimitPrice = KospiFutureUtil.Ins().KFI.DownLimit;
                    upLimitPrice = KospiFutureUtil.Ins().KFI.UpLimit;
                }
                else if (dpt == Detail.ProductType.CallOption || dpt == Detail.ProductType.PutOption)
                {
                    downLimitPrice = OptionUtil.GetKOI(o.Code).DownLimit;
                    upLimitPrice = OptionUtil.GetKOI(o.Code).UpLimit;
                }
                else
                {
                    logger.Error("Unknown type {0}", dpt);
                    Util.KillWithNotice("Unknown type");
                    Trace.Assert(false);
                }

                if (o.ReqPrice < downLimitPrice)
                {
                    logger.Error("[UpDownLimitPriceOrderLimit] {0} < {1}", o.ReqPrice, downLimitPrice);
                    logger.Error("ERROR ORDER[{0}]", o.ToString());
                    Util.KillWithNotice("[UpDownLimitPriceOrderLimit] error");

                    return false;
                }

                if (o.ReqPrice > upLimitPrice)
                {
                    logger.Error("[UpDownLimitPriceOrderLimit] {0} > {1}", o.ReqPrice, upLimitPrice);
                    logger.Error("ERROR ORDER[{0}]", o.ToString());
                    Util.KillWithNotice("[UpDownLimitPriceOrderLimit] error");

                    return false;
                }
            }
            else
            {
                logger.Error("Invalid pt");
                Util.KillWithNotice("Invalid pt");
            }
            return _decorator.IsOK(o);
        }
示例#18
0
        public Test_PB_HTSSweeper(
            POrder o,
            Account accountFO,
            STR_Test_PB_Fut_HTS parent)
        {
            _parent = parent;

            InitSweepUnit_FO(o, accountFO);
        }
        public MonitorController_Agroor(POrder keyOrder, Controller_Agroor parent)
        {
            this.KeyOrder = keyOrder;
            this.ElwCode = keyOrder.Code;
            this.BasePrice = keyOrder.ReqPrice;
            this.Parent = parent;

            this._monitor = new Monitor_Agroor_Ready(this);
        }
        public void RegisterContractedOrder(POrder o)
        {
            if (IsIncludedInExistSweeper(o.OrderNumber))
            {
                return;
            }

            Sweeper_Door sweeper = new Sweeper_Door(o, this, this.Parent.RoundCount);
            _sweepers.Add(sweeper.ID, sweeper);
        }
示例#21
0
 public SweepUnit_FO(
     long signedGoalCountFO,
     String code,
     double initEnterPrice,
     POrder initOrder,
     Account accountFO,
     ISweeper parent)
     : this(signedGoalCountFO, code, initEnterPrice, initOrder, accountFO, parent, 2)
 {
 }
示例#22
0
        public void CreateAgroor(POrder order)
        {
            if (IsFull())
            {
                return;
            }

            MonitorController_Agroor agroor = new MonitorController_Agroor(order, this);
            Add(agroor);
        }
示例#23
0
 public SweepUnit_OE(
     POrder goalOrder, 
     Account accountFO, 
     Account accountSpot, 
     OptionTribe ot,
     ISweeper parent,
     Boolean bConservativeOptionPolicyOn)
     : this(goalOrder, accountFO, accountSpot, ot, parent, true, 2)
 {
 }
        public Boolean IsOK(POrder o)
        {
            RawMarketData rmd = o.RMDClone;
            if (o.LongShort == TradingDirection.Long)
            {
                long askCount = Util.GetTotalAskCount(rmd);

                if (o.ReqPrice <= rmd.AskPrice1)
                {
                    return _decorator.IsOK(o);
                }

                // 사자주문이다. 사겠다는 수량이 존재하는 Ask수량의 합보다 크면 안된다.
                if (o.ReqCount > askCount)
                {
                    logger.Error(
                        String.Format("[CountBidAskRangeOrderLimit] (ReqCount({0}), AskCount({1}), {2}, BidPrice1({3}), AskPrice1({4}))",
                        o.ReqCount,
                        askCount,
                        o.LongShort,
                        rmd.BidPrice1,
                        rmd.AskPrice1));
                    Util.KillWithNotice("[CountBidAskRangeOrderLimit] error");

                    return false;
                }
            }
            else
            {
                long bidCount = Util.GetTotalBidCount(rmd);

                // 이거 위험하기는 하다. Bid가 전혀 없는데 매도 주문을 지정가로 내 놓으면 좀 위험하다.
                if (o.ReqPrice >= rmd.BidPrice1)
                {
                    return _decorator.IsOK(o);
                }

                // 팔자주문이다. 팔겠다는 수량이 존재하는 Ask수량의 합보다 작으면 이상한 경우이다.
                if (o.ReqCount > bidCount)
                {
                    logger.Error(
                        String.Format("[CountBidAskRangeOrderLimit] (ReqCount({0}), BidCount({1}), {2}, BidPrice1({3}), AskPrice1({4}))",
                        o.ReqCount,
                        bidCount,
                        o.LongShort,
                        rmd.BidPrice1,
                        rmd.AskPrice1));
                    Util.KillWithNotice("[CountBidAskRangeOrderLimit]");

                    return false;
                }
            }

            return _decorator.IsOK(o);
        }
示例#25
0
 public Boolean Contract_CallBack(POrder order)
 {
     foreach (IStrategyNode node in _nodes)
     {
         if (node.Contract_CallBack(order))
         {
             return true;
         }
     }
     return false;
 }
示例#26
0
        public void AddCancel(POrder o)
        {
            DateTime key = DateTime.Now.AddMilliseconds(PERIOD);

            if (!_cancelPOrders.ContainsKey(key))
            {
                _cancelPOrders.Add(key, new List<POrder>());
            }

            _cancelPOrders[key].Add(o);
        }
 public Boolean Contract_CallBack(POrder order)
 {
     foreach (ISweeper sweeper in _live)
     {
         if (sweeper.Contract_CallBack(order))
         {
             return true;
         }
     }
     return false;
 }
        public OrderServerPOrder_Request(OrderServerPOrder oso, POrder order, String accountName, String password, PBHTS hts)
        {
            _oso = oso;
            _order = order;
            _hts = hts;
            _accountName = accountName;
            _password = password;

            _bDone = false;
            _bGotReceiveResult = true;
            _bGotReceiveMessageCode = true;
        }
示例#29
0
        public Boolean IsOK(POrder o)
        {
            if (IsOK_Raw(o))
            {
                return _decorator.IsOK(o);
            }

            logger.Error("[OutOfRangeOrderLimit] {0}", o.ToString());
            Util.KillWithNotice("[OutOfRangeOrderLimit]");

            return false;
        }
        public Boolean IsOK(POrder o)
        {
            // Max Value잡은 것의 2배까지는 봐주도록 하자
            if (o.GetAbsBookValueIfAllIn() >= 2.0 * _maxValue)
            {
                logger.Error("[ValuePerOnceOrderLimit] {0:n0} > {1:n0}", o.GetAbsBookValueIfAllIn(), 2.0 * _maxValue);
                Util.KillWithNotice("[ValuePerOnceOrderLimit] error");
                return false;
            }

            return _decorator.IsOK(o);
        }