Exemple #1
0
        public override void Analysis(CurrentPrice price)
        {
            try
            {
                GetSise(price);

                switch (ruleInfo.PriceType)
                {
                case "0":
                    CPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);
                    break;

                case "1":
                    CPrice = Math.Round(price.price3, RoundNum);
                    break;

                case "2":
                    CPrice = Math.Round(price.price5, RoundNum);
                    break;

                case "3":
                    CPrice = Math.Round(price.price7, RoundNum);
                    break;

                default:
                    CPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);
                    break;
                }

                if (BPrice == CPrice)
                {
                    return;
                }
                if (HPrice < CPrice)
                {
                    HPrice = Math.Round(CPrice, RoundNum);
                }
                if (LPrice > CPrice)
                {
                    LPrice = Math.Round(CPrice, RoundNum);
                }

                PriceList.Insert(CPrice);

                double touchPrice매도 = Math.Round(GetTouchPrice("매도"), RoundNum);
                double touchPrice매수 = Math.Round(GetTouchPrice("매수"), RoundNum);

                if (ruleInfo.IsUse == "N")
                {
                    return;
                }
                if (touchPrice매도 == 0)
                {
                    return;
                }
                if (touchPrice매수 == 0)
                {
                    return;
                }

                // 진입
                if (!ruleInfo.IsBuyDone)
                {
                    //기준가 터치여부 체크
                    if (!ruleInfo.IsTouchedBasePrice)
                    {
                        if (PointsUtil.IsBreakThroughUp(touchPrice매수, PriceList))
                        {
                            ruleInfo.BasePrice          = ruleInfo.BuyPrice = Math.Round(touchPrice매수, RoundNum).ToString();
                            ruleInfo.Position           = "매수";
                            ruleInfo.IsTouchedBasePrice = true;
                            ruleInfo.BasePriceTouchTime = DateTime.Now;
                            TradeEvents.Instance.OnTradeRuleHandler(AtmanName, ItemCode, $"매수라인터치::{ruleInfo.TimeType}::{touchPrice매수}::{CPrice}");
                        }

                        if (PointsUtil.IsBreakThroughDown(touchPrice매도, PriceList))
                        {
                            ruleInfo.BasePrice          = ruleInfo.BuyPrice = Math.Round(touchPrice매도, RoundNum).ToString();
                            ruleInfo.Position           = "매도";
                            ruleInfo.IsTouchedBasePrice = true;
                            ruleInfo.BasePriceTouchTime = DateTime.Now;
                            TradeEvents.Instance.OnTradeRuleHandler(AtmanName, ItemCode, $"매도라인터치::{ruleInfo.TimeType}::{touchPrice매도}::{CPrice}");
                        }
                    }

                    //매입여부 체크
                    if (ruleInfo.IsTouchedBasePrice)
                    {
                        double basePrice = Math.Round(Convert.ToDouble(ruleInfo.BasePrice), RoundNum);
                        double buyPrice  = Math.Round(GetBuyPrice(ruleInfo.Position), RoundNum);
                        //기준가 터치후 제약시간이상 넘었을 경우

                        if (ruleInfo.Position == "매수")
                        {
                            if (PointsUtil.IsBreakThroughDownUp(buyPrice, PriceList))
                            {
                                //매수진입
                                ruleInfo.IsBuyDone = true;
                                ruleInfo.BuyedTime = DateTime.Now;
                                ruleInfo.LossPrice = Math.Round(touchPrice매도, RoundNum).ToString();
                                ruleInfo.BuyPrice  = Math.Round(buyPrice, RoundNum).ToString();
                                SellBuy("신규매입", "매수");
                            }
                        }
                        else if (ruleInfo.Position == "매도")
                        {
                            if (PointsUtil.IsBreakThroughUpDown(buyPrice, PriceList))
                            {
                                //매도진입
                                ruleInfo.IsBuyDone = true;
                                ruleInfo.BuyedTime = DateTime.Now;
                                ruleInfo.LossPrice = Math.Round(touchPrice매수, RoundNum).ToString();
                                ruleInfo.BuyPrice  = Math.Round(buyPrice, RoundNum).ToString();
                                SellBuy("신규매입", "매도");
                            }
                        }
                    }
                }
                if (!ruleInfo.IsBuyDone)
                {
                    return;
                }
                double lossPrice = GetLossPrice();
                //손실체크
                if (lossPrice > 0 && ruleInfo.IsBuyDone)
                {
                    if (ruleInfo.Position == "매수")
                    {
                        if (PointsUtil.IsBreakThroughDown(lossPrice, PriceList))
                        {
                            //매도진입
                            InitRule();
                            SellBuy("손실청산", "매도");
                        }
                    }
                    else if (ruleInfo.Position == "매도")
                    {
                        if (PointsUtil.IsBreakThroughUp(lossPrice, PriceList))
                        {
                            //매수진입
                            InitRule();
                            SellBuy("손실청산", "매수");
                        }
                    }
                }
                double revenuePrice = GetRevenuePrice();
                //수익체크
                if (revenuePrice > 0 && ruleInfo.IsBuyDone && ruleInfo.IsCanRevenue)
                {
                    if (ruleInfo.Position == "매수")
                    {
                        if (PointsUtil.IsBreakThroughUpDown(revenuePrice, PriceList))
                        {
                            //매도진입
                            InitRule();
                            SellBuy("수익청산", "매도");
                        }
                    }
                    else if (ruleInfo.Position == "매도")
                    {
                        if (PointsUtil.IsBreakThroughDownUp(revenuePrice, PriceList))
                        {
                            //매수진입
                            InitRule();
                            SellBuy("수익청산", "매수");
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                BPrice = CPrice;
            }
        }
Exemple #2
0
        public override void Analysis(CurrentPrice price)
        {
            try
            {
                switch (ruleInfo.PriceType)
                {
                case "0":
                    CPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);
                    break;

                case "1":
                    CPrice = Math.Round(price.price3, RoundNum);
                    break;

                case "2":
                    CPrice = Math.Round(price.price5, RoundNum);
                    break;

                case "3":
                    CPrice = Math.Round(price.price7, RoundNum);
                    break;

                default:
                    CPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);
                    break;
                }

                if (BPrice == CPrice)
                {
                    return;
                }
                if (HPrice < CPrice)
                {
                    HPrice = Math.Round(CPrice, RoundNum);
                }
                if (LPrice > CPrice)
                {
                    LPrice = Math.Round(CPrice, RoundNum);
                }

                PriceList.Insert(CPrice);

                double basePrice = Math.Round(Convert.ToDouble(ruleInfo.BasePrice), RoundNum);
                double buyPrice  = Math.Round(GetBuyPrice(basePrice), RoundNum);

                if (ruleInfo.IsUse == "N")
                {
                    return;
                }
                if (buyPrice == 0)
                {
                    return;
                }

                // 진입
                if (!ruleInfo.IsBuyDone)
                {
                    //기준가 터치여부 체크
                    if (!ruleInfo.IsTouchedBasePrice)
                    {
                        if (ruleInfo.Position == "매수")
                        {
                            if (PointsUtil.IsBreakThroughUpDown(basePrice, PriceList))
                            {
                                ruleInfo.IsTouchedBasePrice = true;
                                ruleInfo.BasePriceTouchTime = DateTime.Now;

                                TradeEvents.Instance.OnTradeRuleHandler(AtmanName, ItemCode, $"기준가터치::{ruleInfo.Position}::{CPrice}");
                            }
                        }
                        else if (ruleInfo.Position == "매도")
                        {
                            if (PointsUtil.IsBreakThroughDownUp(basePrice, PriceList))
                            {
                                ruleInfo.IsTouchedBasePrice = true;
                                ruleInfo.BasePriceTouchTime = DateTime.Now;

                                TradeEvents.Instance.OnTradeRuleHandler(AtmanName, ItemCode, $"기준가터치::{ruleInfo.Position}::{CPrice}");
                            }
                        }
                    }

                    //매입여부 체크
                    if (ruleInfo.IsTouchedBasePrice)
                    {
                        //기준가 터치후 제약시간이상 넘었을 경우
                        if (ruleInfo.BuyLimitTime != 0 &&
                            ruleInfo.BasePriceTouchTime.AddMinutes(ruleInfo.BuyLimitTime) < DateTime.Now)
                        {
                            ruleInfo.IsUse = "N";
                            return;
                        }
                        if (ruleInfo.Position == "매수")
                        {
                            if (PointsUtil.IsBreakThroughDownUp(buyPrice, PriceList))
                            {
                                //매수진입
                                ruleInfo.IsBuyDone = true;
                                ruleInfo.BuyedTime = DateTime.Now;
                                SellBuy("신규매입", "매수");
                            }
                        }
                        else if (ruleInfo.Position == "매도")
                        {
                            if (PointsUtil.IsBreakThroughUpDown(buyPrice, PriceList))
                            {
                                //매도진입
                                ruleInfo.IsBuyDone = true;
                                ruleInfo.BuyedTime = DateTime.Now;
                                SellBuy("신규매입", "매도");
                            }
                        }
                    }
                }

                if (!ruleInfo.IsBuyDone)
                {
                    return;
                }
                double lossPrice = Math.Round(GetLossPrice(basePrice), RoundNum);
                //손실체크
                if (lossPrice > 0 && ruleInfo.IsBuyDone)
                {
                    if (ruleInfo.Position == "매수")
                    {
                        if (lossPrice >= CPrice)
                        {
                            //매도진입
                            InitRule();
                            SellBuy("손실청산", "매도");
                        }
                    }
                    else if (ruleInfo.Position == "매도")
                    {
                        if (lossPrice <= CPrice)
                        {
                            //매수진입
                            InitRule();
                            SellBuy("손실청산", "매수");
                        }
                    }
                }
                double revenuePrice = Math.Round(GetRevenuePrice(basePrice), RoundNum);
                //수익체크
                if (revenuePrice > 0 && ruleInfo.IsBuyDone)
                {
                    if (ruleInfo.RevenueLimitTime != 0 &&
                        ruleInfo.BuyedTime.AddMinutes(ruleInfo.RevenueLimitTime) < DateTime.Now)
                    {
                        //강제청산
                        if (ruleInfo.Position == "매수")
                        {
                            //매도진입
                            InitRule();
                            SellBuy("수익강제청산", "매도");
                        }
                        else if (ruleInfo.Position == "매도")
                        {
                            //매수진입
                            InitRule();
                            SellBuy("수익강제청산", "매수");
                        }
                    }
                    else
                    {
                        if (ruleInfo.Position == "매수")
                        {
                            if (revenuePrice <= CPrice)
                            {
                                //매도진입
                                InitRule();
                                SellBuy("수익청산", "매도");
                            }
                        }
                        else if (ruleInfo.Position == "매도")
                        {
                            if (revenuePrice >= CPrice)
                            {
                                //매수진입
                                InitRule();
                                SellBuy("수익청산", "매수");
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                BPrice = CPrice;
            }
        }