Example #1
0
 public abstract void Analysis(CurrentPrice price);
Example #2
0
        public override void Analysis(CurrentPrice price)
        {
            try
            {
                RPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);

                switch (PriceType)
                {
                case "0":
                    CPrice = RPrice;
                    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);

                if (!IsUse)
                {
                    return;
                }

                // //매수포지션 사용여부
                if (!IsBuyed)
                {
                    if (IsUseBuy)
                    {
                        //터치여부
                        if (!IsTouchedBasePrice)
                        {
                            if (PointsUtil.IsBreakThrough(BasePattern, BasePrice, PriceList))
                            {
                                IsTouchedBasePrice = true;
                                onStrategyTradeRuleHandler("터치", $"베이스 가격터치::현재가{CPrice}");
                            }
                        }
                        if (IsTouchedBasePrice && !IsBuyed)
                        {
                            //매도
                            if (Position == "1")
                            {
                                if (CPrice == BuyPrice)
                                {
                                    IsBuyed = true;
                                    SellBuy("진입", Position);
                                    onStrategyTradeRuleHandler("진입", $"매도진입::현재가{CPrice}");
                                }
                            }
                            //매수
                            if (Position == "2")
                            {
                                if (CPrice == BuyPrice)
                                {
                                    IsBuyed = true;
                                    SellBuy("진입", Position);
                                    onStrategyTradeRuleHandler("진입", $"매수진입::현재가{CPrice}");
                                }
                            }
                        }
                    }
                }
                if (IsBuyed && IsUseLosscut && !IsLosscuted && !IsRevenued)
                {
                    if (Position == "1")
                    {
                        if (RPrice == LosscutPrice)
                        {
                            IsLosscuted = true;
                            SellBuy("청산", "2");
                            onStrategyTradeRuleHandler("청산", $"매수청산::현재가{CPrice}");
                        }
                    }
                    //매수
                    if (Position == "2")
                    {
                        if (RPrice == LosscutPrice)
                        {
                            IsLosscuted = true;
                            SellBuy("청산", "1");
                            onStrategyTradeRuleHandler("청산", $"매도청산::현재가{CPrice}");
                        }
                    }
                }
                if (IsBuyed && IsUseRevenue && !IsRevenued && !IsLosscuted)
                {
                    if (Position == "1")
                    {
                        if (RPrice == RevenuePrice)
                        {
                            IsRevenued = true;
                            SellBuy("청산", "2");
                            onStrategyTradeRuleHandler("청산", $"매수청산::현재가{CPrice}");
                        }
                    }
                    //매수
                    if (Position == "2")
                    {
                        if (RPrice == RevenuePrice)
                        {
                            IsRevenued = true;
                            SellBuy("청산", "1");
                            onStrategyTradeRuleHandler("청산", $"매도청산::현재가{CPrice}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                onStrategyTradeRuleHandler("ERROR", ex.Message);
            }
            finally
            {
                BPrice = CPrice;
            }
        }
 public override string ToString()
 {
     return(String.Format("{0} [{1}] {2}", CompanyName, Symbol, CurrentPrice.ToString()));
 }
Example #4
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 (basePrice <= CPrice)
                            {
                                ruleInfo.IsTouchedBasePrice = true;
                                ruleInfo.BasePriceTouchTime = DateTime.Now;
                            }
                        }
                        else if (ruleInfo.Position == "매도")
                        {
                            if (basePrice >= CPrice)
                            {
                                ruleInfo.IsTouchedBasePrice = true;
                                ruleInfo.BasePriceTouchTime = DateTime.Now;
                            }
                        }
                    }

                    //매입여부 체크
                    if (ruleInfo.IsTouchedBasePrice)
                    {
                        //기준가 터치후 제약시간이상 넘었을 경우
                        if (ruleInfo.BuyLimitTime != 0 &&
                            ruleInfo.BasePriceTouchTime.AddMinutes(ruleInfo.BuyLimitTime) < DateTime.Now)
                        {
                            ruleInfo.IsUse = "N";
                            return;
                        }
                        if (ruleInfo.Position == "매수")
                        {
                            if (buyPrice >= CPrice)
                            {
                                //매수진입
                                ruleInfo.IsBuyDone = true;
                                ruleInfo.BuyedTime = DateTime.Now;
                                SellBuy("신규매입", "매수");
                            }
                        }
                        else if (ruleInfo.Position == "매도")
                        {
                            if (buyPrice <= CPrice)
                            {
                                //매도진입
                                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;
            }
        }
Example #5
0
        public void GetSise(CurrentPrice price = null)
        {
            try
            {
                if (candle != null && price != null)
                {
                    var nextTime = candle.DTime.AddMinutes(EnumUtil.GetIntervalValueToMinutes(ruleInfo.TimeType));

                    if (price.DTime < nextTime)
                    {
                        return;
                    }
                }

                PurushaPrakriti pp = new PurushaPrakriti();
                pp.Item         = ruleInfo.Item;
                pp.Interval     = (int)EnumUtil.GetTimeIntervalValue(ruleInfo.TimeType);
                pp.DisplayCount = 5;
                try
                {
                    Entities entities           = (Entities)pp.Collect(new Query("USP_PP_SIMPLE_LST"));
                    List <PurushaPrakriti> list = entities.Cast <PurushaPrakriti>().ToList();

                    List <int> ticks = new List <int>();
                    foreach (var k in list.GetRange(1, 4))
                    {
                        int tick = PriceTick.GetTickDiff(ItemCode
                                                         , Convert.ToDouble(k.OpenVal)
                                                         , Convert.ToDouble(k.CloseVal));

                        ticks.Add(tick);
                    }

                    int avgTick = Convert.ToInt32(ticks.Average());
                    if (avgTick < limitTicks)
                    {
                        avgTick = limitTicks;
                    }

                    var m = list[1];
                    if (candle != null)
                    {
                        if (candle.HighPrice > m.HighVal && candle.LowPrice < m.LowVal)
                        {
                            return;
                        }

                        int tick = PriceTick.GetTickDiff(ItemCode
                                                         , Convert.ToDouble(candle.OpenPrice)
                                                         , Convert.ToDouble(candle.ClosePrice));

                        if (tick < avgTick)
                        {
                            return;
                        }
                    }

                    candle = new S_CandleItemData(ItemCode, m.OpenVal, m.HighVal, m.LowVal, m.CloseVal, m.Volume, m.DT);

                    if (!ruleInfo.IsBuyDone)
                    {
                        InitRule();
                    }
                    else
                    {
                        ruleInfo.IsCanRevenue = true;
                    }
                }
                catch (Exception ex)
                {
                    string err = ex.Message;
                }
            }
            catch (Exception)
            {
            }
        }
Example #6
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;
            }
        }
Example #7
0
        public string AdminMessage()
        {
            string MenuStatus      = "Активно";
            string MainPhotoString = "";
            string CodeString      = "";
            string Url             = "";

            int?Balance = 0;

            if (Enable == false)
            {
                MenuStatus = "Скрыто от пользователей";
            }
            if (Stock.Count > 0)
            {
                Balance = Stock.OrderByDescending(s => s.Id).FirstOrDefault().Balance;
            }

            if (Unit == null)
            {
                Unit = Connection.getConnection().Units.Where(u => u.Id == UnitId).FirstOrDefault();
            }

            if (MainPhoto > 0)
            {
                MainPhotoString = "Есть";
            }

            else
            {
                MainPhotoString = "Отсутствует";
            }

            if (TelegraphUrl != null)
            {
                Url = TelegraphUrl;
            }

            if (Code != null)
            {
                CodeString = Code;
            }



            try
            {
                return(BotMessage.Bold("Название: ") + Name + BotMessage.NewLine() +
                       BotMessage.Bold("Цена: ") + CurrentPrice.ToString() + " / " + Unit.ShortName + BotMessage.NewLine() +
                       BotMessage.Bold("Категория: ") + Category.Name + BotMessage.NewLine() +
                       BotMessage.Bold("Описание: ") + Text + BotMessage.NewLine() +
                       BotMessage.Bold("В наличии: ") + Balance.ToString() + BotMessage.NewLine() +
                       BotMessage.Bold("Артикул:") + CodeString + BotMessage.NewLine() +
                       BotMessage.Bold("Ссылка на подробное описание:") + Url + BotMessage.NewLine() +
                       BotMessage.Bold("В меню: ") + MenuStatus + BotMessage.NewLine() +
                       BotMessage.Bold("Фотография:") + MainPhotoString + BotMessage.NewLine() +
                       BotMessage.Bold("Доп. фото:") + ProductPhoto.Count.ToString() + " шт.");
            }

            catch (Exception e)
            {
                return(String.Empty);
            }
        }
Example #8
0
        public override void Analysis(CurrentPrice price)
        {
            try
            {
                switch (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);
                if (!IsUse)
                {
                    return;
                }

                // //매수포지션 사용여부
                if (!IsBuyDone)
                {
                    if (IsUseP2)
                    {
                        //터치여부
                        if (!IsTouchedP2)
                        {
                            if (IsBaseLine)
                            {
                                if (PointsUtil.GetUpDownPattern(PriceList, P2BuyPrice1) == P2BuyPattern)
                                {
                                    IsTouchedP2 = true;
                                    SellBuy("가격패턴매칭", "매수");
                                }
                            }
                            else
                            {
                                if (PointsUtil.GetUpDownPattern(PriceList, P2BuyPrice1, P2BuyPrice2) == P2BuyPattern)
                                {
                                    IsTouchedP2 = true;
                                    SellBuy("가격패턴매칭", "매수");
                                }
                            }
                        }
                        if (IsTouchedP2)
                        {
                            //매수포지션 진입
                            IsBuyDone = true;
                            BuyPrice  = CPrice;
                            Position  = "매수";
                            SellBuy("신규진입", "매수");
                        }
                    }
                }
                //매도포지션 사용여부
                if (!IsBuyDone)
                {
                    if (IsUseP1)
                    {
                        //터치여부
                        if (!IsTouchedP1)
                        {
                            if (IsBaseLine)
                            {
                                if (PointsUtil.GetUpDownPattern(PriceList, P1BuyPrice1) == P1BuyPattern)
                                {
                                    IsTouchedP1 = true;
                                    SellBuy("가격패턴매칭", "매도");
                                }
                            }
                            else
                            {
                                if (PointsUtil.GetUpDownPattern(PriceList, P1BuyPrice1, P1BuyPrice2) == P1BuyPattern)
                                {
                                    IsTouchedP1 = true;
                                    SellBuy("가격패턴매칭", "매도");
                                }
                            }
                        }
                        if (IsTouchedP1)
                        {
                            IsBuyDone = true;
                            BuyPrice  = CPrice;
                            Position  = "매도";
                            SellBuy("신규진입", "매도");
                        }
                    }
                }
                if (!IsBuyDone)
                {
                    return;
                }

                if (Position == "매수" && IsMinimumRevenue2 && MinimumRevenuePrice2 > 0)
                {
                    if (MinimumRevenuePrice2 < CPrice)
                    {
                        return;
                    }
                }
                if (Position == "매도" && IsMinimumRevenue1 && MinimumRevenuePrice1 > 0)
                {
                    if (MinimumRevenuePrice1 > CPrice)
                    {
                        return;
                    }
                }

                //손실체크
                if (Position == "매수")
                {
                    if (PointsUtil.IsBreakThrough(P2LosscutPattern1, P2LosscutPrice1, PriceList))
                    {
                        InitRule();
                        SellBuy("손실청산1", "매도");
                    }

                    if (P2LosscutPrice2 > 0 && P2LosscutPrice2 >= CPrice)
                    {
                        //매도진입
                        InitRule();
                        SellBuy("손실청산2", "매도");
                    }
                }
                if (Position == "매도")
                {
                    if (PointsUtil.IsBreakThrough(P1LosscutPattern1, P1LosscutPrice1, PriceList))
                    {
                        InitRule();
                        SellBuy("손실청산1", "매수");
                    }

                    if (P1LosscutPrice2 > 0 && P1LosscutPrice2 <= CPrice)
                    {
                        //매수진입
                        InitRule();
                        SellBuy("손실청산2", "매수");
                    }
                }

                //수익체크
                if (IsUseRevenue1)
                {
                    double revenuePrice = Math.Round(GetRevenuePrice1(), RoundNum);
                    if (revenuePrice == 0)
                    {
                        return;
                    }
                    if (Position == "매수")
                    {
                        if (revenuePrice <= CPrice)
                        {
                            //매도진입
                            InitRule();
                            SellBuy("수익청산", "매도");
                        }
                    }
                    if (Position == "매도")
                    {
                        if (revenuePrice >= CPrice)
                        {
                            //매수진입
                            InitRule();
                            SellBuy("수익청산", "매수");
                        }
                    }
                }
                if (IsUseRevenue2)
                {
                    double revenuePrice = Math.Round(GetRevenuePrice2(), RoundNum);
                    if (revenuePrice == 0)
                    {
                        return;
                    }
                    if (Position == "매수")
                    {
                        if (revenuePrice <= CPrice)
                        {
                            //매도진입
                            InitRule();
                            SellBuy("수익청산", "매도");
                        }
                    }
                    if (Position == "매도")
                    {
                        if (revenuePrice >= CPrice)
                        {
                            //매수진입
                            InitRule();
                            SellBuy("수익청산", "매수");
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                BPrice = CPrice;
            }
        }
Example #9
0
        public override void Analysis(CurrentPrice price)
        {
            try
            {
                CPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);

                if (BPrice == CPrice)
                {
                    return;
                }

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

                if (IsBuyed)
                {
                    return;
                }

                if (IsUseLossPrice)
                {
                    //손실체크 매수포지션
                    if (Position == "2")
                    {
                        //if (LossPrice1 > 0 && LossPrice1 >= CPrice)
                        //{
                        //    //SellBuy("손실청산1", "매도");
                        //}

                        if (LossPrice2 > 0 && LossPrice2 >= CPrice)
                        {
                            IsBuyed = true;
                            SellBuy("청산", "1");
                        }
                    }
                    if (Position == "1")
                    {
                        //if (LossPrice1 > 0 && LossPrice1 <= CPrice)
                        //{
                        //    //SellBuy("손실청산1", "매도");
                        //}

                        if (LossPrice2 > 0 && LossPrice2 <= CPrice)
                        {
                            IsBuyed = true;
                            SellBuy("청산", "2");
                        }
                    }
                }

                if (IsUseRevenue)
                {
                    //매수포지션
                    if (Position == "2" && IsMinimumRevenue2 && MinimumRevenuePrice2 > 0)
                    {
                        if (MinimumRevenuePrice2 > CPrice)
                        {
                            return;
                        }
                    }
                    //매도포지션
                    if (Position == "1" && IsMinimumRevenue1 && MinimumRevenuePrice1 > 0)
                    {
                        if (MinimumRevenuePrice1 > CPrice)
                        {
                            return;
                        }
                    }

                    //수익체크
                    if (IsUseRevenue1)
                    {
                        double revenuePrice = Math.Round(GetRevenuePrice1(), RoundNum);
                        if (revenuePrice == 0)
                        {
                            return;
                        }
                        if (Position == "2")
                        {
                            if (revenuePrice <= CPrice)
                            {
                                //매도진입
                                IsBuyed = true;
                                SellBuy("청산", "1");
                            }
                        }
                        if (Position == "1")
                        {
                            if (revenuePrice >= CPrice)
                            {
                                //매수진입
                                IsBuyed = true;
                                SellBuy("청산", "2");
                            }
                        }
                    }
                    if (IsUseRevenue2)
                    {
                        double revenuePrice = Math.Round(GetRevenuePrice2(), RoundNum);
                        if (revenuePrice == 0)
                        {
                            return;
                        }
                        if (Position == "2")
                        {
                            if (revenuePrice <= CPrice)
                            {
                                //매도진입
                                IsBuyed = true;
                                SellBuy("청산", "1");
                            }
                        }
                        if (Position == "1")
                        {
                            if (revenuePrice >= CPrice)
                            {
                                //매수진입
                                IsBuyed = true;
                                SellBuy("청산", "2");
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                BPrice = CPrice;
            }
        }
Example #10
0
        public override void Analysis(CurrentPrice price)
        {
            try
            {
                CPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);

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

                if (IsBuyed)
                {
                    return;
                }

                if (IsUseMITBuy)
                {
                    if (BuyPrice2 > 0 && CPrice == BuyPrice2)
                    {
                        IsBuyed  = true;
                        Position = "2";
                        SellBuy("진입", Position);
                    }
                    else if (BuyPrice1 > 0 && CPrice == BuyPrice1)
                    {
                        IsBuyed  = true;
                        Position = "1";
                        SellBuy("진입", Position);
                    }
                }

                if (IsUseMITSell)
                {
                    if (SellPrice1 > 0 && CPrice == SellPrice1)
                    {
                        IsBuyed  = true;
                        Position = "1";
                        SellBuy("청산", Position);
                    }
                    else if (SellPrice2 > 0 && CPrice == SellPrice2)
                    {
                        IsBuyed  = true;
                        Position = "2";
                        SellBuy("청산", Position);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            finally
            {
                BPrice = CPrice;
            }
        }
Example #11
0
        public override void Analysis(CurrentPrice price)
        {
            try
            {
                RPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);

                switch (PriceType)
                {
                case "0":
                    CPrice = RPrice;
                    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);

                if (!IsUse)
                {
                    return;
                }

                // // 사용여부
                if (!IsBuyed)
                {
                    double hPrice  = 0;
                    double lPrice  = 0;
                    double mPrice  = 0;
                    double qPrice  = 0;
                    double qhPrice = 0;
                    double qlPrice = 0;

                    if (BaseCandleItem != null)
                    {
                        if (BaseCandleItemType == "1")
                        {
                            hPrice  = Math.Round(BaseCandleItem.PlusMinusType == PlusMinusTypeEnum.양 ? BaseCandleItem.VikalaHighPrice : BaseCandleItem.QuantumHighPrice, RoundNum);
                            lPrice  = Math.Round(BaseCandleItem.PlusMinusType == PlusMinusTypeEnum.양 ? BaseCandleItem.QuantumLowPrice : BaseCandleItem.VikalaLowPrice, RoundNum);
                            mPrice  = Math.Round(BaseCandleItem.MassPrice, RoundNum);
                            qPrice  = Math.Round(BaseCandleItem.TotalCenterPrice, RoundNum);
                            qhPrice = mPrice > qPrice ? mPrice : qPrice;
                            qlPrice = mPrice < qPrice ? mPrice : qPrice;
                        }
                        else if (BaseCandleItemType == "2")
                        {
                            hPrice  = Math.Round(BaseCandleItem.PlusMinusType == PlusMinusTypeEnum.양 ? BaseCandleItem.VikalaHighPrice : BaseCandleItem.QuantumHighPrice, RoundNum);
                            lPrice  = Math.Round(BaseCandleItem.PlusMinusType == PlusMinusTypeEnum.양 ? BaseCandleItem.QuantumLowPrice : BaseCandleItem.VikalaLowPrice, RoundNum);
                            mPrice  = Math.Round(BaseCandleItem.MassPrice, RoundNum);
                            qPrice  = Math.Round(BaseCandleItem.TotalCenterPrice, RoundNum);
                            qhPrice = mPrice > qPrice ? mPrice : qPrice;
                            qlPrice = mPrice < qPrice ? mPrice : qPrice;
                        }
                        else if (BaseCandleItemType == "3")
                        {
                            hPrice  = Math.Round(BaseCandleItem.PlusMinusType == PlusMinusTypeEnum.양 ? BaseCandleItem.VikalaHighPrice : BaseCandleItem.QuantumHighPrice, RoundNum);
                            lPrice  = Math.Round(BaseCandleItem.PlusMinusType == PlusMinusTypeEnum.양 ? BaseCandleItem.QuantumLowPrice : BaseCandleItem.VikalaLowPrice, RoundNum);
                            mPrice  = Math.Round(BaseCandleItem.MassPrice, RoundNum);
                            qPrice  = Math.Round(BaseCandleItem.TotalCenterPrice, RoundNum);
                            qhPrice = mPrice > qPrice ? mPrice : qPrice;
                            qlPrice = mPrice < qPrice ? mPrice : qPrice;
                        }
                    }

                    if (hPrice == 0 || lPrice == 0 || qhPrice == 0 || qlPrice == 0)
                    {
                        return;
                    }

                    if (StrategyDirection == "1")//추세(지지저항)
                    {
                        //매도
                        if (CPrice < lPrice && PositionType.Contains("1"))
                        {
                            Position = "1";
                            IsBuyed  = true;
                            SellBuy("진입", Position);
                            onStrategyTradeRuleHandler("진입", $"매도진입::현재가{CPrice}");
                        }
                        //매수
                        else if (CPrice > hPrice && PositionType.Contains("2"))
                        {
                            Position = "2";
                            IsBuyed  = true;
                            SellBuy("진입", Position);
                            onStrategyTradeRuleHandler("진입", $"매수진입::현재가{CPrice}");
                        }
                    }
                    else if (StrategyDirection == "2")//횡보(지지저항)
                    {
                        //매수
                        if (CPrice < lPrice && PositionType.Contains("2"))
                        {
                            Position = "2";
                            IsBuyed  = true;
                            SellBuy("진입", Position);
                            onStrategyTradeRuleHandler("진입", $"매수진입::현재가{CPrice}");
                        }
                        //매도
                        else if (CPrice > hPrice && PositionType.Contains("1"))
                        {
                            Position = "1";
                            IsBuyed  = true;
                            SellBuy("진입", Position);
                            onStrategyTradeRuleHandler("진입", $"매도진입::현재가{CPrice}");
                        }
                    }
                    else if (StrategyDirection == "3")//추세(질량)
                    {
                        //매도
                        if (CPrice == qlPrice && PositionType.Contains("1"))
                        {
                            Position = "1";
                            IsBuyed  = true;
                            SellBuy("진입", Position);
                            onStrategyTradeRuleHandler("진입", $"매도진입::현재가{CPrice}");
                        }
                        //매수
                        else if (CPrice == qhPrice && PositionType.Contains("2"))
                        {
                            Position = "2";
                            IsBuyed  = true;
                            SellBuy("진입", Position);
                            onStrategyTradeRuleHandler("진입", $"매수진입::현재가{CPrice}");
                        }
                    }
                    else if (StrategyDirection == "4")//횡보(질량)
                    {
                        //매수
                        if (CPrice == qlPrice && PositionType.Contains("2"))
                        {
                            Position = "2";
                            IsBuyed  = true;
                            SellBuy("진입", Position);
                            onStrategyTradeRuleHandler("진입", $"매수진입::현재가{CPrice}");
                        }
                        //매도
                        else if (CPrice == qhPrice && PositionType.Contains("1"))
                        {
                            Position = "1";
                            IsBuyed  = true;
                            SellBuy("진입", Position);
                            onStrategyTradeRuleHandler("진입", $"매도진입::현재가{CPrice}");
                        }
                    }
                    else if (StrategyDirection == "5")
                    {
                        //매도
                        if (CPrice == qlPrice && PositionType.Contains("1"))
                        {
                            Position = "1";
                            IsBuyed  = true;
                            SellBuy("진입", Position);
                            onStrategyTradeRuleHandler("진입", $"매도진입::현재가{CPrice}");
                        }
                        //매수
                        else if (CPrice == qhPrice && PositionType.Contains("2"))
                        {
                            Position = "2";
                            IsBuyed  = true;
                            SellBuy("진입", Position);
                            onStrategyTradeRuleHandler("진입", $"매수진입::현재가{CPrice}");
                        }
                    }
                }

                if (IsBuyed && IsUseLosscut && !IsLosscuted && !IsRevenued)
                {
                    if (Position == "1")
                    {
                        if (RPrice == LosscutPrice)
                        {
                            IsLosscuted = true;
                            SellBuy("청산", "2");
                            onStrategyTradeRuleHandler("손실컷", $"매수청산::현재가{CPrice}");
                        }
                    }
                    //매수
                    if (Position == "2")
                    {
                        if (RPrice == LosscutPrice)
                        {
                            IsLosscuted = true;
                            SellBuy("청산", "1");
                            onStrategyTradeRuleHandler("손실컷", $"매도청산::현재가{CPrice}");
                        }
                    }
                }

                if (IsBuyed && IsUseRevenue && !IsRevenued && !IsLosscuted)
                {
                    if (Position == "1")
                    {
                        if (RPrice == RevenuePrice)
                        {
                            IsRevenued = true;
                            SellBuy("청산", "2");
                            onStrategyTradeRuleHandler("수익컷", $"매수청산::현재가{CPrice}");
                        }
                    }
                    //매수
                    if (Position == "2")
                    {
                        if (RPrice == RevenuePrice)
                        {
                            IsRevenued = true;
                            SellBuy("청산", "1");
                            onStrategyTradeRuleHandler("수익컷", $"매도청산::현재가{CPrice}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                onStrategyTradeRuleHandler("ERROR", ex.Message);
            }
            finally
            {
                BPrice = CPrice;
            }
        }
Example #12
0
 public Task SetCurrentPriceAsync(DateTime date, string ticker, CurrentPrice currentPrice)
 {
     throw new NotImplementedException();
 }
Example #13
0
        public override void Analysis(CurrentPrice price)
        {
            try
            {
                CPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);
                if (!IsUse)
                {
                    return;
                }

                #region P2
                #region P2 Buy
                //P2 Buy 1
                if (IsUseP2Buy1 && !IsBuyP2Done1 && P2BuyPrice1 > 0 && P2BuyQty1 > 0)
                {
                    if (CPrice == P2BuyPrice1)
                    {
                        SellBuy("매도", P2BuyQty1.ToString(), TradeType);

                        IsBuyP2Done1 = true;
                    }
                }

                //P2 Buy 2
                if (IsUseP2Buy2 && !IsBuyP2Done2 && P2BuyPrice2 > 0 && P2BuyQty2 > 0)
                {
                    if (CPrice == P2BuyPrice2)
                    {
                        SellBuy("매도", P2BuyQty2.ToString(), TradeType);

                        IsBuyP2Done2 = true;
                    }
                }

                //P2 Buy 3
                if (IsUseP2Buy3 && !IsBuyP2Done3 && P2BuyPrice3 > 0 && P2BuyQty3 > 0)
                {
                    if (CPrice == P2BuyPrice3)
                    {
                        SellBuy("매도", P2BuyQty3.ToString(), TradeType);

                        IsBuyP2Done3 = true;
                    }
                }
                #endregion

                #region P2 Revenue
                //P2 Revenue 1
                if (IsUseP2Revenue1 && !IsRevenueP2Done1 && P2RevenuePrice1 > 0 && P2RevenueQty1 > 0)
                {
                    if (CPrice == P2RevenuePrice1)
                    {
                        SellBuy("매수", P2RevenueQty1.ToString(), TradeType);
                        IsRevenueP2Done1 = true;
                    }
                }

                //P2 Revenue 2
                if (IsUseP2Revenue2 && !IsRevenueP2Done2 && P2RevenuePrice2 > 0 && P2RevenueQty2 > 0)
                {
                    if (CPrice == P2RevenuePrice2)
                    {
                        SellBuy("매수", P2RevenueQty2.ToString(), TradeType);
                        IsRevenueP2Done2 = true;
                    }
                }

                //P2 Revenue 3
                if (IsUseP2Revenue3 && !IsRevenueP2Done3 && P2RevenuePrice3 > 0 && P2RevenueQty3 > 0)
                {
                    if (CPrice == P2RevenuePrice3)
                    {
                        SellBuy("매수", P2RevenueQty3.ToString(), TradeType);
                        IsRevenueP2Done3 = true;
                    }
                }
                #endregion

                #region P2 Losscut
                //P2 Losscut 1
                if (IsUseP2Losscut1 && !IsLosscutP2Done1 && P2LosscutPrice1 > 0 && P2LosscutQty1 > 0)
                {
                    if (CPrice == P2LosscutPrice1)
                    {
                        SellBuy("매수", P2LosscutQty1.ToString(), TradeType);
                        IsLosscutP2Done1 = true;
                    }
                }

                //P2 Losscut 2
                if (IsUseP2Losscut2 && !IsLosscutP2Done2 && P2LosscutPrice2 > 0 && P2LosscutQty2 > 0)
                {
                    if (CPrice == P2LosscutPrice2)
                    {
                        SellBuy("매수", P2LosscutQty2.ToString(), TradeType);
                        IsLosscutP2Done2 = true;
                    }
                }

                //P2 Losscut 3
                if (IsUseP2Losscut3 && !IsLosscutP2Done3 && P2LosscutPrice3 > 0 && P2LosscutQty3 > 0)
                {
                    if (CPrice == P2LosscutPrice3)
                    {
                        SellBuy("매수", P2LosscutQty3.ToString(), TradeType);
                        IsLosscutP2Done3 = true;
                    }
                }
                #endregion
                #endregion

                #region P1
                #region P1 Buy
                //P1 Buy 1
                if (IsUseP1Buy1 && !IsBuyP1Done1 && P1BuyPrice1 > 0 && P1BuyQty1 > 0)
                {
                    if (CPrice == P1BuyPrice1)
                    {
                        SellBuy("매수", P1BuyQty1.ToString(), TradeType);

                        IsBuyP1Done1 = true;
                    }
                }

                //P1 Buy 2
                if (IsUseP1Buy2 && !IsBuyP1Done2 && P1BuyPrice2 > 0 && P1BuyQty2 > 0)
                {
                    if (CPrice == P1BuyPrice2)
                    {
                        SellBuy("매수", P1BuyQty2.ToString(), TradeType);

                        IsBuyP1Done2 = true;
                    }
                }

                //P1 Buy 3
                if (IsUseP1Buy3 && !IsBuyP1Done3 && P1BuyPrice3 > 0 && P1BuyQty3 > 0)
                {
                    if (CPrice == P1BuyPrice3)
                    {
                        SellBuy("매수", P1BuyQty3.ToString(), TradeType);

                        IsBuyP1Done3 = true;
                    }
                }
                #endregion

                #region P1 Revenue
                //P1 Revenue 1
                if (IsUseP1Revenue1 && !IsRevenueP1Done1 && P1RevenuePrice1 > 0 && P1RevenueQty1 > 0)
                {
                    if (CPrice == P1RevenuePrice1)
                    {
                        SellBuy("매도", P1RevenueQty1.ToString(), TradeType);
                        IsRevenueP1Done1 = true;
                    }
                }

                //P1 Revenue 2
                if (IsUseP1Revenue2 && !IsRevenueP1Done2 && P1RevenuePrice2 > 0 && P1RevenueQty2 > 0)
                {
                    if (CPrice == P1RevenuePrice2)
                    {
                        SellBuy("매도", P1RevenueQty2.ToString(), TradeType);
                        IsRevenueP1Done2 = true;
                    }
                }

                //P1 Revenue 3
                if (IsUseP1Revenue3 && !IsRevenueP1Done3 && P1RevenuePrice3 > 0 && P1RevenueQty3 > 0)
                {
                    if (CPrice == P1RevenuePrice3)
                    {
                        SellBuy("매도", P1RevenueQty3.ToString(), TradeType);
                        IsRevenueP1Done3 = true;
                    }
                }
                #endregion

                #region P1 Losscut
                //P1 Losscut 1
                if (IsUseP1Losscut1 && !IsLosscutP1Done1 && P1LosscutPrice1 > 0 && P1LosscutQty1 > 0)
                {
                    if (CPrice == P1LosscutPrice1)
                    {
                        SellBuy("매도", P1LosscutQty1.ToString(), TradeType);
                        IsLosscutP1Done1 = true;
                    }
                }

                //P1 Losscut 2
                if (IsUseP1Losscut2 && !IsLosscutP1Done2 && P1LosscutPrice2 > 0 && P1LosscutQty2 > 0)
                {
                    if (CPrice == P1LosscutPrice2)
                    {
                        SellBuy("매도", P1LosscutQty2.ToString(), TradeType);
                        IsLosscutP1Done2 = true;
                    }
                }

                //P1 Losscut 3
                if (IsUseP1Losscut3 && !IsLosscutP1Done3 && P1LosscutPrice3 > 0 && P1LosscutQty3 > 0)
                {
                    if (CPrice == P1LosscutPrice3)
                    {
                        SellBuy("매도", P1LosscutQty3.ToString(), TradeType);
                        IsLosscutP1Done3 = true;
                    }
                }
                #endregion
                #endregion
            }
            catch (Exception)
            {
            }
        }