示例#1
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;
        }
        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 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);
        }
示例#4
0
        public Boolean IsOK(POrder o)
        {
            double tickSize = ProductUtil.Ins().GetTickSize(o);

            double pivot = GetPivot(o);

            if (pivot == 0)
            {
                logger.Error("[LimOrderLimit] {0} > {1} + {2} * {3}", o.ReqPrice, pivot, tickSize, _tickRange);
                logger.Error("ERROR ORDER[{0}]", o.ToString());
                Util.KillWithNotice("[LimOrderLimit] error");

                return false;
            }

            if (o.LongShort == TradingDirection.Long)
            {
                // 작은 값으로 주문내는 것은 상관 없다. 높은 값으로 주문하는 것을 조심해야 한다.
                // 현재가보다 5틱 위에 매수 주문을 내려고 한다. 안된다.
                if (o.ReqPrice > pivot + tickSize * _tickRange)
                {
                    logger.Error("[LimOrderLimit] {0} > {1} + {2} * {3}", o.ReqPrice, pivot, tickSize, _tickRange);
                    logger.Error("ERROR ORDER[{0}]", o.ToString());
                    Util.KillWithNotice("[LimOrderLimit] error");

                    return false;
                }
            }
            else
            {
                // 큰 값으로 매도 주문을 내는 것은 상관없다. 작은 값으로 주문하는 것을 조심해야 한다.
                // 현재가보다 5틱 아래 매도 주문을 내려고 한다. 안된다.
                if (o.ReqPrice < pivot - tickSize * _tickRange)
                {
                    logger.Error("[LimOrderLimit] {0} < {1} - {2} * {3}", o.ReqPrice, pivot, tickSize, _tickRange);
                    logger.Error("ERROR ORDER[{0}]", o.ToString());
                    Util.KillWithNotice("[LimOrderLimit] error");

                    return false;
                }
            }

            return _decorator.IsOK(o);
        }
        public Boolean IsOK(POrder o)
        {
            RawMarketData rmd = o.RMDClone;
            if (o.LongShort == TradingDirection.Long)
            {
                double askPrice = rmd.AskPrice1;

                // 사자주문이다. 사겠다는 가격이 존재하는 매도 호가보다도 높다면 이상한 경우이다.
                if (o.ReqPrice > askPrice)
                {
                    logger.Error("[PriceBidAskRangeOrderLimit] (ReqPrice({0}), AskPrice({1}), {2})", o.ReqPrice, askPrice, o.LongShort);
                    logger.Error("ERROR ORDER[{0}]", o.ToString());
                    Util.KillWithNotice("[PriceBidAskRangeOrderLimit] error");

                    return false;
                }
            }
            else
            {
                double bidPrice = rmd.BidPrice1;

                // 팔자주문이다. 팔겠다는 가격이 존재하는 매수 호가보다도 낮다면 이상한 경우이다.
                if (o.ReqPrice < bidPrice)
                {
                    logger.Error("[PriceBidAskRangeOrderLimit] (ReqPrice({0}), BidPrice({1}), {2})", o.ReqPrice, bidPrice, o.LongShort);
                    Util.KillWithNotice("[PriceBidAskRangeOrderLimit] error");

                    try
                    {
                        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);
        }
示例#6
0
        public Boolean IsOK(POrder o)
        {
            RawMarketData rmd = o.RMDClone;
            if (o.LongShort == TradingDirection.Long)
            {
                double bidPrice = GetPossibleMinBidPrice(rmd);

                // 사자주문이다. OOR의 경우 BidPrice 호가보다 큰 값으로 주문을 내면 이상한 것이다.
                if (o.ReqPrice > bidPrice)
                {
                    logger.Error("CRITICAL ERROR in OOROrderLimit ({0}, {1}, {2})", o.ReqPrice, bidPrice, o.LongShort);
                    logger.Error("ERROR ORDER[{0}]", o.ToString());
                    Util.KillWithNotice("CRITICAL ERROR in OOROrderLimit");

                    return false;
                }
            }
            else
            {
                double askPrice = GetPossibleMaxAskPrice(rmd);

                // 팔자주문이다. OOR의 경우 AskPrice 호가보다 작은 값으로 주문을 내면 이상한 것이다.
                if (o.ReqPrice < askPrice)
                {
                    logger.Error("CRITICAL ERROR in OOROrderLimit ({0}, {1}, {2})", o.ReqPrice, askPrice, o.LongShort);
                    Util.KillWithNotice("CRITICAL ERROR in OOROrderLimit");
                    try
                    {
                        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 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)
        {
            if (_maxCount < _curCount + o.ReqCount)
            {
                // Over Limit
                try
                {
                    logger.Error("[CountPerMinuteOrderLimit] {0} < {1} + {2}", _maxCount, _curCount, o.ReqCount);
                    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);
        }
示例#9
0
        public Boolean IsOK(POrder o)
        {
            if (!Util.IsValidRMDTimeAndPrice(o.RMDClone))
            {
                logger.Error("Invalid RMD");
                Util.KillWithNotice("Invalid RMD");
                try
                {
                    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);
        }
示例#10
0
        Boolean MakeOrder_Raw(RawMarketData rmd, long remainCount100k, Dictionary<String, long> blocksLB, ref List<POrder> newOrders, ref String log)
        {
            if (remainCount100k == 0)
            {
                log += "remainCount100k == 0";
                return true;
            }

            long signedRealCount = ElwOptionUtil.Convert100KToRealCount(rmd.Code, remainCount100k);

            if (signedRealCount == 0 || remainCount100k - ElwOptionUtil.ConvertRealToCount100k(rmd.Code, signedRealCount) != 0)
            {
                log += String.Format("signRealCount({0}) remainCount100k({1}) code({2})|", signedRealCount, remainCount100k, rmd.Code);
                return false;
            }

            long reqCount = Math.Abs(signedRealCount);

            TradingDirection ls = TradingDirection.Long;
            if (signedRealCount < 0)
            {
                ls = TradingDirection.Short;

                if (!blocksLB.ContainsKey(rmd.Code))
                {
                    log += String.Format("[22], {0}|", rmd.Code);

                    return false;
                }

                if (blocksLB[rmd.Code] < Math.Abs(signedRealCount))
                {
                    log += String.Format("[23] BlockLB[{2}]({0}) < signedRealCount({1})", blocksLB[rmd.Code], signedRealCount, rmd.Code);
                    return false;
                }

                reqCount = Math.Abs(signedRealCount);
                long tmp = ProductUtil.Ins().RoundProductCount(Math.Abs(reqCount), rmd.DPT);

                if (tmp != reqCount)
                {
                    logger.Error("tmp({0}) != reqCount({1}) in MakeOrder_Raw", tmp, reqCount);
                    Util.KillWithNotice("tmp != reqCount in MakeOrder_Raw");
                }
            }

            Account account = _accountFO;
            if (rmd.DPT == Detail.ProductType.ELW || rmd.DPT == Detail.ProductType.Stock)
            {
                account = _accountSpot;
            }

            double price = ProductUtil.Ins().GetMidPrice(rmd);
            price = AdjustPrice(ls, rmd, price);

            POrder o = new POrder(ls, rmd.Code, reqCount, price, account, rmd);
            o.AddComment("SweepUnit_OE.MakeOrder_Raw");

            log += String.Format("[23], {0}|", o.ToString());

            if (o.ReqCount > 0)
            {
                // 여기서 Reserve하고 법적 문제가 있는지 확인한다.
                o.SetAsLegalPrice();
                o.ConvertOverPriceToInRMDPriceIfNotZero();

                log += String.Format("[24], {0}|", o.ToString());

                newOrders.Add(o);
            }
            else
            {
                o.Free();

                log += String.Format("[24], ReqCount <= 0");
                return false;
            }

            long ret = remainCount100k - ElwOptionUtil.ConvertRealToCount100k(rmd.Code, signedRealCount);

            if (ret != 0)
            {
                logger.Error(
                    "CRITICAL ERROR!!! in MakeOrder_Raw ret != 0 ret({0}), remainCount100k({1}), signedRealCount({2}), Code({3})",
                    ret,
                    remainCount100k,
                    signedRealCount,
                    rmd.Code);
                Util.KillWithNotice("CRITICAL ERROR!!! in MakeOrder_Raw");

                return false;
            }

            return true;
        }
示例#11
0
 public void CancelRemains(POrder order)
 {
     logger.Debug("Cancel: {0}", order.ToString());
     this.Hts.CancelRemains(order);
 }
示例#12
0
        public Boolean Remove(POrder o)
        {
            Boolean bRemoved = false;

            double price = Math.Round(ProductUtil.Ins().RoundProductPrice(o.Code, o.ReqPrice), 2);

            if (_data.ContainsKey(price))
            {
                List<POrder> arr = _data[price];

                if (arr.Contains(o))
                {
                    arr.Remove(o);
                    bRemoved = true;
                }

                if (arr.Count == 0)
                {
                    _data.Remove(price);
                }
            }

            if (!bRemoved)
            {
                logger.Debug("Does not removed.");
                logger.Debug(o.ToString());
                logger.Debug(ToString());
            }

            return bRemoved;
        }
示例#13
0
        public static Boolean RequestOrder(POrder order, List<POrder> container)
        {
            try
            {
                order.SetAsLegalPrice();

                Boolean bSuccess = true;

                bSuccess = order.TargetAccount.RequestOrder(order);

                if (!bSuccess)
                {
                    logger.Error(order.ToString());
                    Util.KillWithNotice(order.ToString());
                    SoundManager.Ins().PlayExceptionSound();
                }
                else
                {
                    if (container != null)
                    {
                        // 성공했으면 담는다.
                        container.Add(order);
                    }
                }
                return bSuccess;
            }
            catch (System.Exception ex)
            {
                logger.Error(ex.ToString());
                Util.KillWithNotice(ex.ToString());
            }
            return false;
        }
        Boolean CancelDangerousOrders_Raw(POrder order)
        {
            String elwCode = order.Code;
            double reqPrice = order.ReqPrice;

            ElwInfo ei = ElwUtil.GetElwInfo(elwCode);

            if (ei == null)
            {
                Trace.Assert(false);
            }

            // 만기 확인
            OptionTribe ot = ElwOptionUtil.GetOptionTribeFromCode(elwCode);

            if (ot == null)
            {
                Trace.Assert(false);
            }

            double strike = ot.Strike;
            CallPutFlag cp = ot.CP;

            // 바로 옆 옵션을 reference로 사용한다.
            double doorStrike = GetDoorStrike(strike, cp, 1.0);

            KospiOptionInfo targetKOI = OptionUtil.GetKOI(strike, cp, ot.Maturity);
            KospiOptionInfo doorKOI = OptionUtil.GetKOI(doorStrike, cp, ot.Maturity);

            if (doorKOI == null)
            {
                Trace.Assert(false);
            }
            else
            {
                Boolean bDangerous = CancelDangerousOrders_Raw(order, ei, targetKOI, doorKOI);

                if (bDangerous)
                {
                    order.CancelRemains();
                    EmailManager.Ins().AddEmail(
                        String.Format("Dangerous Door Canceled... {0}", order.ToString()));
                }
                return bDangerous;
            }
            return false;
        }
示例#15
0
        public Boolean Contract_CallBack(POrder order)
        {
            if (IsFishingOrder(order))
            {
                if (GetFishingOrderType(order) == FishingOrderType.Active)
                {
                    // Fishing and no agroor상태이다.
                    // order가 일부 혹은 전부 체결이 되었다면 Agroor를 생성한다.
                    if (order.ContractedCount > 0 && order.CanceledCount == 0)
                    {
                        // 체결되었고 취소된 수량은 없는 상태이다. register해준다.
                        _sweeperController.RegisterContractedOrder(order);

                        // FishingOrderType을 변경한다.
                        Trace.Assert(_fishigOrders.ContainsKey(order) == true);
                        _fishigOrders[order] = FishingOrderType.Passive;

                        SoundManager.Ins().ForcedPlayContractSound();
                        EmailManager.Ins().AddEmail(
                            String.Format("Door Contracted... {0}", order.ToString()));
                    }
                }
            }
            else
            {
                // sweeper에서 낸 주문이거나 수동으로 파워베이스에서 낸 주문인 경우에 해당한다.
                // 특별히 해줄 일이 없다.
                logger.Info("Door에서 Fishing order가 아닌 주문에 의해 Contracted_CallBack을 호출함.");
                logger.Info(order.ToString());
            }
            return true;
        }
示例#16
0
        // 주문을 하고 정해놓은 컨테이너에 담는 역할을 수행한다.
        void RequestOrder_Raw(POrder order, List<POrder> container)
        {
            try
            {
                order.SetAsLegalPrice();
                order.ConvertOverPriceToInRMDPriceIfNotZero();

                Boolean bSuccess = true;
                if (order.TargetAccount.LineType == Account.OrderLineType.StockSpotLine)
                {
                    Trace.Assert(false);
                }
                else if (order.TargetAccount.LineType == Account.OrderLineType.FutureOptionSpreadLine)
                {
                    bSuccess = order.TargetAccount.RequestOrder(order);
                }
                else
                {
                    logger.Error("{0} unsupported ProductType", order.TargetAccount.LineType);
                    Util.KillWithNotice("unsupported ProductType");
                    Trace.Assert(false);
                }

                if (!bSuccess)
                {
                    logger.Error(order.ToString());
                    Util.KillWithNotice(order.ToString());
                    _State = State._0_Exception;
                    SoundManager.Ins().PlayExceptionSound();
                    ShowState();
                }
                else
                {
                    // 성공했으면 담는다.
                    container.Add(order);
                }
            }
            catch (System.Exception ex)
            {
                logger.Error(ex.ToString());
                Util.KillWithNotice(ex.ToString());
            }
        }
示例#17
0
        public Boolean RequestOrder(POrder order)
        {
            try
            {
                order.SetAsLegalPrice();

                if (!IsValidPT(order))
                {
                    return false;
                }

                if (!IsValidOrder(order))
                {
                    logger.Error("It is not valid order");
                    logger.Error(order.ToString());
                    Util.KillWithNotice(order.ToString());
                    return false;
                }

                order.RoundReqPrice();

                if (AccountManager.Ins().IsSingleShotWeaponMode)
                {
                    if (AccountManager.Ins().IsBulletEmpty())
                    {
                        SoundManager.Ins().PlayAlertSound();

                        DialogResult dr = MessageBox.Show(null, order.ToString(),
                            "SingleWeaponMode, Do you want reload bullets?", MessageBoxButtons.YesNoCancel);

                        if (dr == DialogResult.Yes)
                        {
                            AccountManager.Ins().ReloadBullet();
                        }
                        else
                        {
                            logger.Error("Cancel Order(Single Weapon Mode)");
                            Util.KillWithNotice("Cancel Order(Single Weapon Mode)");
                            return false;
                        }
                    }

                    AccountManager.Ins().DecreaseBullet();
                }

                if (this.Hts.SendOrder(order))
                {
                    //// 주문을 한다.
                    _requestOrders.Add(order);

                    POrderLegalManager.Ins().Add(order);

                    POrderBidAskCountManager.Ins().Register(order);

                    logger.Debug("Request: {0}", order.ToString());

                    order.IsAllocatedYetRequestOrFree = false;

                    return true;
                }
                logger.Error("Fail order");
                Util.KillWithNotice("Fail order");
                return false;
            }
            catch (System.Exception ex)
            {
                logger.Error(ex.ToString());
                Util.KillWithNotice(ex.ToString());
            }
            return false;
        }
示例#18
0
        void RequestOrder_Raw(POrder order, List<POrder> container)
        {
            try
            {
                order.SetAsLegalPrice();
                order.ConvertOverPriceToInRMDPriceIfNotZero();

                Boolean bSuccess = true;
                bSuccess = order.TargetAccount.RequestOrder(order);

                if (!bSuccess)
                {
                    logger.Error("{0} order error", order.ToString());
                    Util.KillWithNotice("order error");
                    _State = State._0_Exception;
                    SoundManager.Ins().PlayExceptionSound();
                    ShowState();
                }
                else
                {
                    // 성공했으면 담는다.
                    container.Add(order);
                }
            }
            catch (System.Exception ex)
            {
                logger.Error(ex.ToString());
                Util.KillWithNotice(ex.ToString());
            }
        }