Ejemplo n.º 1
0
        public static List <UpstoxTradeParams> ReadTradingConfigFile()
        {
            var    filesPath      = SystemUtils.GetStockFilesPath();
            string configFilePath = Path.Combine(filesPath, "stocktradingconfig.txt");
            int    Index          = -1;
            var    ctp            = new UpstoxTradeParams();

            double mktConditionBuyExtraMarkDown      = 0;
            double markDownPctForAveragingTightening = 0;
            double priceBucketWidthInPctForQty       = 0;

            double[] priceBucketsForQty = new[] { 0.0 };
            double   qtyAgressionFactor = 0;

            double[] priceBucketsForPrice = new[] { 0.0 };
            double   deliveryBrokerage    = 0;

            var lines = File.ReadAllLines(configFilePath);

            // Common config
            foreach (var line in lines.Where(l => !string.IsNullOrEmpty(l.Trim()) && l.Trim().StartsWith("@")))
            {
                var split = line.Split('=');

                switch (split[0].Trim())
                {
                case "@mktConditionBuyExtraMarkDownPct":
                    mktConditionBuyExtraMarkDown = double.Parse(split[1]) / 100;
                    break;

                case "@markDownPctForAveragingTightening":
                    markDownPctForAveragingTightening = double.Parse(split[1]);
                    break;

                case "@priceBucketWidthInPctForQty":
                    priceBucketWidthInPctForQty = double.Parse(split[1]) / 100;
                    break;

                case "@qtyAgressionFactor":
                    qtyAgressionFactor = double.Parse(split[1]);
                    break;

                case "@priceBucketsForQty":
                    priceBucketsForQty = split[1].Split(',').Select(a => double.Parse(a)).ToArray();
                    break;

                case "@priceBucketsForPrice":
                    priceBucketsForPrice = split[1].Split(',').Select(a => double.Parse(a)).ToArray();
                    break;

                case "@deliveryBrokerage":
                    deliveryBrokerage = double.Parse(split[1]) / 100;
                    break;

                case "@commonStock":
                    var common = split[1].Split(',');
                    Index            = -1;
                    ctp.stockCode    = "COMMONCONFIG";
                    ctp.baseOrderVal = double.Parse(common[++Index]);
                    ctp.maxTotalPositionValueMultiple = int.Parse(common[++Index]);
                    ctp.maxTodayPositionValueMultiple = int.Parse(common[++Index]);
                    ctp.markDownPctForBuy             = double.Parse(common[++Index]) / 100;
                    ctp.markDownPctForAveraging       = double.Parse(common[++Index]) / 100;
                    ctp.sellMarkup           = double.Parse(common[++Index]);
                    ctp.placeBuyNoLtpCompare = bool.Parse(common[++Index]);
                    ctp.startTime            = GeneralUtils.GetTodayDateTime(common[++Index]);
                    ctp.endTime   = GeneralUtils.GetTodayDateTime(common[++Index]);
                    ctp.orderType = (EquityOrderType)Enum.Parse(typeof(EquityOrderType), common[++Index]);
                    ctp.exchange  = (Exchange)Enum.Parse(typeof(Exchange), common[++Index]);
                    break;
                }
            }

            // Stocks config
            List <UpstoxTradeParams> tps = new List <UpstoxTradeParams>(lines.Length);

            foreach (var line in lines.Where(l => !string.IsNullOrEmpty(l.Trim()) && !(l.Trim().StartsWith("#") || l.Trim().StartsWith("@"))))
            {
                Index = -1;
                var stock = line.Split(',');

                var tp = new UpstoxTradeParams
                {
                    stockCode    = stock[++Index],
                    baseOrderVal = stock.Length > ++Index ? (string.IsNullOrEmpty(stock[Index]) ? ctp.baseOrderVal : double.Parse(stock[Index])) : ctp.baseOrderVal,
                    maxTotalPositionValueMultiple = stock.Length > ++Index ? (string.IsNullOrEmpty(stock[Index]) ? ctp.maxTotalPositionValueMultiple : int.Parse(stock[Index])) : ctp.maxTotalPositionValueMultiple,
                    maxTodayPositionValueMultiple = stock.Length > ++Index ? (string.IsNullOrEmpty(stock[Index]) ? ctp.maxTodayPositionValueMultiple : int.Parse(stock[Index])) : ctp.maxTodayPositionValueMultiple,
                    markDownPctForBuy             = stock.Length > ++Index ? (string.IsNullOrEmpty(stock[Index]) ? ctp.markDownPctForBuy : double.Parse(stock[Index])) / 100 : ctp.markDownPctForBuy,             //7
                    markDownPctForAveraging       = stock.Length > ++Index ? (string.IsNullOrEmpty(stock[Index]) ? ctp.markDownPctForAveraging : double.Parse(stock[Index])) / 100 : ctp.markDownPctForAveraging, //6
                    sellMarkup           = stock.Length > ++Index ? (string.IsNullOrEmpty(stock[Index]) ? ctp.sellMarkup : double.Parse(stock[Index])) : ctp.sellMarkup,                                          //8
                    placeBuyNoLtpCompare = stock.Length > ++Index ? (string.IsNullOrEmpty(stock[Index]) ? ctp.placeBuyNoLtpCompare : bool.Parse(stock[Index])) : ctp.placeBuyNoLtpCompare,                        //12
                    startTime            = stock.Length > ++Index ? (string.IsNullOrEmpty(stock[Index]) ? ctp.startTime : GeneralUtils.GetTodayDateTime(stock[Index])) : ctp.startTime,                           //15
                    endTime   = stock.Length > ++Index ? (string.IsNullOrEmpty(stock[Index]) ? ctp.endTime : GeneralUtils.GetTodayDateTime(stock[Index])) : ctp.endTime,                                          //16
                    orderType = stock.Length > ++Index ? (string.IsNullOrEmpty(stock[Index]) ? ctp.orderType : (EquityOrderType)Enum.Parse(typeof(EquityOrderType), stock[Index])) : ctp.orderType,
                    exchange  = stock.Length > ++Index ? (string.IsNullOrEmpty(stock[Index]) ? ctp.exchange : (Exchange)Enum.Parse(typeof(Exchange), stock[Index])) : ctp.exchange
                };

                tp.markDownPctForAveragingTightening = markDownPctForAveragingTightening;
                tp.mktConditionBuyExtraMarkDownPct   = mktConditionBuyExtraMarkDown;
                tp.deliveryBrokerage      = deliveryBrokerage;
                tp.priceBucketWidthForQty = priceBucketWidthInPctForQty;
                tp.priceBucketsForQty     = priceBucketsForQty;
                tp.qtyAgressionFactor     = qtyAgressionFactor;
                tp.priceBucketsForPrice   = priceBucketsForPrice;

                tps.Add(tp);
            }

            return(tps);
        }
 public UpstoxAverageTheBuyThenSell(UpstoxTradeParams tradeParams) : base(tradeParams)
 {
 }