Exemple #1
0
        public TradingItemForSave(TradingItem item, TradingStrategyForSave ts)
        {
            this.tsSave = (ts);
            BindingFlags flags = BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;

            FieldInfo[] fieldArray = item.GetType().GetFields(flags);

            BindingFlags flagsStrategySave = BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;

            FieldInfo[] ItemSaveFieldArray = this.GetType().GetFields(flagsStrategySave);


            foreach (FieldInfo field in fieldArray)
            {
                foreach (FieldInfo SaveField in ItemSaveFieldArray)
                {
                    if (field.Name == SaveField.Name)
                    {
                        SaveField.SetValue(this, field.GetValue(item));
                    }
                }
            }
        }
Exemple #2
0
        public TrailingPercentageItemForSave(TrailingItem itemTrail, TradingStrategy ts)
        {
            strategySave = new TradingStrategyForSave(ts);

            BindingFlags flags = BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;

            FieldInfo[] fieldArray = itemTrail.GetType().GetFields(flags);

            BindingFlags flagsStrategySave = BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;

            FieldInfo[] StrategySaveFieldArray = this.GetType().GetFields(flagsStrategySave);

            foreach (FieldInfo field in fieldArray)
            {
                foreach (FieldInfo SaveField in StrategySaveFieldArray)
                {
                    if (field.Name == SaveField.Name)
                    {
                        SaveField.SetValue(this, field.GetValue(itemTrail));
                    }
                }
            }
        }
Exemple #3
0
        public void SerializeStrategy(List <TradingStrategy> tradingStrategyList)
        {
            List <TradingStrategyForSave> list = new List <TradingStrategyForSave>();

            foreach (var item in tradingStrategyList)
            {
                TradingStrategyForSave save = new TradingStrategyForSave(item);
                list.Add(save);
            }
            try
            {
                BinaryFormatter binFmt = new BinaryFormatter();

                using (FileStream fs = new FileStream(DateTime.Now.ToString("yyyy_MM_dd") + DATA_FILE_NAME, FileMode.Create))
                {
                    binFmt.Serialize(fs, list);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(3);
                Console.WriteLine(e);
            }
        }
Exemple #4
0
        private void AddStratgy(TradingStrategyForSave saved)
        {
            List <TradingStrategyADDItem> tradingStrategyItemList = new List <TradingStrategyADDItem>();

            TradingStrategy ts = new TradingStrategy(
                saved.account,
                saved.buyCondition,
                saved.buyOrderOption,
                saved.totalInvestment,
                saved.buyItemCount,
                saved.sellProfitOrderOption,
                saved.sellStopLossOrderOption,
                saved.sellDivideStopLossOrderOption,
                false,
                saved.usingRestart
                );

            //추가전략 적용
            ts.remainItemCount = saved.remainItemCount;

            //trading item load
            foreach (var item in saved.tradingSaveItemList)
            {
                TradingItem itemAdd = item.ReloadTradingItem();
                itemAdd.ts = ts;
                ts.tradingItemList.Add(itemAdd);

                string fidList = "9001;302;10;11;25;12;13"; //9001:종목코드,302:종목명
                axKHOpenAPI1.SetRealReg("9001", itemAdd.itemCode, fidList, "1");

                //매매진행 데이터 그리드뷰 표시
                form.SetTradingItemUI(itemAdd);
            }

            if (saved.usingTimeLimit)
            {
                TradingStrategyItemBuyTimeCheck timeBuyCheck =
                    new TradingStrategyItemBuyTimeCheck(
                        StrategyItemName.BUY_TIME_LIMIT,
                        CHECK_TIMING.BUY_TIME,
                        new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, saved.startDate.Hour, saved.startDate.Minute, 0),
                        new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, saved.endDate.Hour, saved.endDate.Minute, 0));
                ts.AddTradingStrategyItemList(timeBuyCheck);
                ts.usingTimeLimit = true;
                ts.startDate      = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, saved.startDate.Hour, saved.startDate.Minute, 0);
                ts.endDate        = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, saved.endDate.Hour, saved.endDate.Minute, 0);
            }

            ts.usingTickBuy = saved.usingTickBuy;
            ts.tickBuyValue = saved.tickBuyValue;

            ts.usingTrailing   = saved.usingTrailing;
            ts.trailTickValue  = saved.trailTickValue;
            ts.trailMinusValue = saved.trailMinusValue;

            ts.usingPercentageBuy = saved.usingPercentageBuy;
            ts.percentageBuyValue = saved.percentageBuyValue;

            ts.usingVwma       = saved.usingVwma;
            ts.usingEnvelope5  = saved.usingEnvelope5;
            ts.usingEnvelope7  = saved.usingEnvelope7;
            ts.usingEnvelope10 = saved.usingEnvelope10;
            ts.usingEnvelope15 = saved.usingEnvelope15;
            ts.usingCheckIndex = saved.usingCheckIndex;
            ts.trailTickValue  = saved.trailTickValue;

            if (saved.usingGapTrailBuy)
            {
                ts.usingGapTrailBuy            = true;
                ts.gapTrailCostPercentageValue = saved.gapTrailCostPercentageValue;
                ts.gapTrailBuyTimeValue        = saved.gapTrailBuyTimeValue;

                TradingStrategyItemWithUpDownPercentValue trailGapBuy =
                    new TradingStrategyItemWithUpDownPercentValue(
                        StrategyItemName.BUY_GAP_CHECK,
                        CHECK_TIMING.BUY_TIME,
                        string.Empty,
                        ts.gapTrailCostPercentageValue);

                trailGapBuy.OnReceivedTrData += form.OnReceiveTrDataCheckGapTrailBuy;
                ts.AddTradingStrategyItemList(trailGapBuy);
            }

            if (saved.takeProfitRate > 0)
            {
                double takeProfitRate = 0;
                TradingStrategyItemWithUpDownValue takeProfitStrategy = null;
                takeProfitRate     = saved.takeProfitRate;
                takeProfitStrategy =
                    new TradingStrategyItemWithUpDownValue(
                        StrategyItemName.TAKE_PROFIT_SELL,
                        CHECK_TIMING.SELL_TIME,
                        IS_TRUE_OR_FALE_TYPE.UPPER_OR_SAME,
                        takeProfitRate);
                takeProfitStrategy.OnReceivedTrData += form.OnReceiveTrDataCheckProfitSell;
                ts.AddTradingStrategyItemList(takeProfitStrategy);
                ts.takeProfitRate = takeProfitRate;
            }

            if (saved.stoplossRate < 0)
            {
                double stopLossRate = 0;
                stopLossRate = saved.stoplossRate;
                TradingStrategyItemWithUpDownValue stopLossStrategy = null;
                stopLossStrategy =
                    new TradingStrategyItemWithUpDownValue(
                        StrategyItemName.STOPLOSS_SELL,
                        CHECK_TIMING.SELL_TIME,
                        IS_TRUE_OR_FALE_TYPE.DOWN,
                        stopLossRate);

                stopLossStrategy.OnReceivedTrData += form.OnReceiveTrDataCheckStopLoss;
                ts.AddTradingStrategyItemList(stopLossStrategy);
                ts.stoplossRate = stopLossRate;
            }

            if (saved.usingBuyMore)
            {
                ts.usingBuyMore = true;
                //물타기
                TradingStrategyItemBuyingDivide buyMoreStrategy =
                    new TradingStrategyItemBuyingDivide(
                        StrategyItemName.BUY_MORE_LOSS,
                        CHECK_TIMING.SELL_TIME,
                        IS_TRUE_OR_FALE_TYPE.DOWN,
                        saved.buyMoreRateLoss,
                        saved.buyMoreMoney);

                buyMoreStrategy.OnReceivedTrData += form.OnReceiveTrDataBuyMore;
                ts.AddTradingStrategyItemList(buyMoreStrategy);
                //불타기
                TradingStrategyItemBuyingDivide buyMoreStrategyProfit =
                    new TradingStrategyItemBuyingDivide(
                        StrategyItemName.BUY_MORE_PROFIT,
                        CHECK_TIMING.SELL_TIME,
                        IS_TRUE_OR_FALE_TYPE.UPPER_OR_SAME,
                        saved.buyMoreRateProfit,
                        saved.buyMoreMoney);

                buyMoreStrategyProfit.OnReceivedTrData += form.OnReceiveTrDataBuyMore;
                ts.AddTradingStrategyItemList(buyMoreStrategyProfit);
            }

            if (saved.usingBuyCancelByTime)
            {
                ts.usingBuyCancelByTime = true;

                TradingStrategyItemCancelByTime buyCancelStrategy =
                    new TradingStrategyItemCancelByTime(
                        StrategyItemName.BUY_CANCEL_BY_TIME,
                        CHECK_TIMING.BUY_ORDER_BEFORE_CONCLUSION,
                        DateTime.Now.Ticks
                        );

                buyCancelStrategy.OnReceivedTrData += form.OnReceiveTrDataBuyCancelByTime;
                ts.AddTradingStrategyItemList(buyCancelStrategy);
            }

            if (saved.useDivideSellLoss)
            {
                ts.useDivideSellLoss     = true;
                ts.useDivideSellLossLoop = saved.useDivideSellLossLoop;
                TradingStrategyItemWithUpDownValue divideStopLossStrategy = null;
                divideStopLossStrategy =
                    new TradingStrategyItemWithUpDownValue(
                        StrategyItemName.STOPLOSS_DIVIDE_SELL,
                        CHECK_TIMING.SELL_TIME,
                        IS_TRUE_OR_FALE_TYPE.DOWN,
                        saved.divideStoplossRate);

                divideStopLossStrategy.OnReceivedTrData += form.OnReceiveTrDataCheckStopLossDivide;

                ts.AddTradingStrategyItemList(divideStopLossStrategy);
                ts.divideStoplossRate       = saved.divideStoplossRate;
                ts.divideSellLossPercentage = (saved.divideSellLossPercentage);
                ts.divideSellCount          = saved.divideSellCount;
            }

            if (saved.useDivideSellProfit)
            {
                ts.useDivideSellProfit     = true;
                ts.useDivideSellProfitLoop = saved.useDivideSellProfitLoop;
                TradingStrategyItemWithUpDownValue divideProfitStrategy = null;
                divideProfitStrategy =
                    new TradingStrategyItemWithUpDownValue(
                        StrategyItemName.TAKE_PROFIT_DIVIDE_SELL,
                        CHECK_TIMING.SELL_TIME,
                        IS_TRUE_OR_FALE_TYPE.UPPER_OR_SAME,
                        saved.divideTakeProfitRate);

                divideProfitStrategy.OnReceivedTrData += form.OnReceiveTrDataCheckProfitDivide;

                ts.AddTradingStrategyItemList(divideProfitStrategy);
                ts.divideTakeProfitRate       = saved.divideTakeProfitRate;
                ts.divideSellProfitPercentage = (saved.divideSellProfitPercentage);
                ts.divideSellCountProfit      = saved.divideSellCountProfit;
            }

            if (form.tradingStrategyList.FindAll(o => (o.buyCondition.Name == ts.buyCondition.Name)).Count > 0)
            {
                return;
            }

            form.tradingStrategyList.Add(ts);
            form.AddStrategyToDataGridView(ts);

            if (ts.buyCondition.Name.Contains("dummy") == false)
            {
                form.StartMonitoring(ts.buyCondition);
            }

            if (saved.usingDoubleCheck)
            {
                form.StartMonitoring(ts.doubleCheckCondition);
                form.doubleCheckHashTable.Add(ts.doubleCheckCondition.Name, ts);
            }
        }