예제 #1
0
        protected override List <OptionMinute> readFromWind(string code, DateTime date)
        {
            WindAPI  w = Platforms.GetWindAPI();
            DateTime date1 = date.Date, date2 = date.Date.AddDays(1);
            WindData wd       = w.wsi(code, "open,high,low,close,volume,amt,oi", date1, date2, "periodstart=09:30:00;periodend=15:00:00;Fill=Previous");
            int      len      = wd.timeList.Length;
            int      fieldLen = wd.fieldList.Length;

            var items = new List <OptionMinute>(len);

            if (wd.data is double[])
            {
                double[]   dataList = (double[])wd.data;
                DateTime[] timeList = wd.timeList;
                for (int k = 0; k < len; k++)
                {
                    items.Add(new OptionMinute
                    {
                        time         = timeList[k],
                        open         = (double)dataList[k * fieldLen + 0],
                        high         = (double)dataList[k * fieldLen + 1],
                        low          = (double)dataList[k * fieldLen + 2],
                        close        = (double)dataList[k * fieldLen + 3],
                        volume       = (double)dataList[k * fieldLen + 4],
                        amount       = (double)dataList[k * fieldLen + 5],
                        openInterest = (double)dataList[k * fieldLen + 6]
                    });
                }
            }

            return(items);
        }
예제 #2
0
        protected override List <StockDaily> readFromWind(string code, DateTime dateStart, DateTime dateEnd, string tag = null, IDictionary <string, object> options = null)
        {
            WindAPI  w        = Platforms.GetWindAPI();
            WindData wd       = w.wsd(code, "open,high,low,close,volume,amt,adjfactor,settle,pre_close,pre_settle", dateStart, dateEnd, "Fill=Previous");
            int      len      = wd.timeList.Length;
            int      fieldLen = wd.fieldList.Length;

            var items = new List <StockDaily>(len * fieldLen);

            if (wd.data is double[])
            {
                double[]   dataList = (double[])wd.data;
                DateTime[] timeList = wd.timeList;
                for (int k = 0; k < len; k++)
                {
                    items.Add(new StockDaily
                    {
                        time         = timeList[k],
                        open         = dataList[k * fieldLen + 0],
                        high         = dataList[k * fieldLen + 1],
                        low          = dataList[k * fieldLen + 2],
                        close        = dataList[k * fieldLen + 3],
                        volume       = dataList[k * fieldLen + 4],
                        amount       = dataList[k * fieldLen + 5],
                        adjustFactor = dataList[k * fieldLen + 6],
                        settle       = dataList[k * fieldLen + 7],
                        preClose     = dataList[k * fieldLen + 8],
                        preSettle    = dataList[k * fieldLen + 9]
                    });
                }
            }

            return(items);
        }
        public override List <FuturesDaily> readFromWind(string code, DateTime dateStart, DateTime dateEnd, string tag = null, IDictionary <string, object> options = null)
        {
            WindAPI  w        = Platforms.GetWindAPI();
            WindData wd       = w.wsd(code, "open,high,low,close,volume,amt", dateStart, dateEnd, "Fill=Previous");
            int      len      = wd.timeList.Length;
            int      fieldLen = wd.fieldList.Length;

            var items = new List <FuturesDaily>(len * fieldLen);

            if (wd.data is double[])
            {
                double[]   dataList = (double[])wd.data;
                DateTime[] timeList = wd.timeList;
                for (int k = 0; k < len; k++)
                {
                    items.Add(new FuturesDaily
                    {
                        time   = timeList[k],
                        open   = (double)dataList[k * fieldLen + 0],
                        high   = (double)dataList[k * fieldLen + 1],
                        low    = (double)dataList[k * fieldLen + 2],
                        close  = (double)dataList[k * fieldLen + 3],
                        volume = (double)dataList[k * fieldLen + 4],
                        amount = (double)dataList[k * fieldLen + 5]
                    });
                }
            }
            return(items);
        }
예제 #4
0
        public List <OptionInfo> readFromWind(string underlying = "510050.SH", string market = "sse")
        {
            string marketStr = "";

            if (market == "sse")
            {
                marketStr = ".SH";
            }
            WindAPI           wapi     = Platforms.GetWindAPI();
            WindData          wd       = wapi.wset("optioncontractbasicinfo", "exchange=" + market + ";windcode=" + underlying + ";status=all");
            int               len      = wd.codeList.Length;
            int               fieldLen = wd.fieldList.Length;
            List <OptionInfo> items    = new List <OptionInfo>(len);

            object[] dm = (object[])wd.data;
            for (int k = 0; k < len; k++)
            {
                items.Add(new OptionInfo
                {
                    optionCode         = (string)dm[k * fieldLen + 0] + marketStr,
                    optionName         = (string)dm[k * fieldLen + 1],
                    executeType        = (string)dm[k * fieldLen + 5],
                    strike             = (double)dm[k * fieldLen + 6],
                    contractMultiplier = (double)dm[k * fieldLen + 7],
                    optionType         = (string)dm[k * fieldLen + 4],
                    startDate          = (DateTime)dm[k * fieldLen + 9],
                    endDate            = (DateTime)dm[k * fieldLen + 10]
                });
            }
            return(items);
        }
예제 #5
0
        /// <summary>
        /// 从万德API获取
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        List <DateTime> readFromWind(DateTime startTime, DateTime endTime)
        {
            WindAPI  wapi = Platforms.GetWindAPI();
            WindData wd   = wapi.tdays(startTime, endTime, "");
            var      wdd  = (object[])wd.data;

            return(wdd.Select(x => (DateTime)x).ToList());
        }
예제 #6
0
        private List <FuturesMinute> readByParameters(string code, DateTime date, string paramters)
        {
            WindAPI  w     = Platforms.GetWindAPI();
            DateTime date2 = new DateTime(date.Year, date.Month, date.Day, 15, 0, 0);
            DateTime date1 = DateUtils.PreviousTradeDay(date).AddHours(17);
            //获取日盘数据
            WindData wd       = w.wsi(code, "open,high,low,close,volume,amt,oi", date1, date2, paramters);
            int      len      = wd.timeList.Length;
            int      fieldLen = wd.fieldList.Length;
            var      items    = new List <FuturesMinute>(len);

            if (wd.data is double[])
            {
                double[]   dataList = (double[])wd.data;
                DateTime[] timeList = wd.timeList;
                for (int k = 0; k < len; k++)
                {
                    items.Add(new FuturesMinute
                    {
                        tradeday     = date,
                        time         = timeList[k],
                        open         = (double)dataList[k * fieldLen + 0],
                        high         = (double)dataList[k * fieldLen + 1],
                        low          = (double)dataList[k * fieldLen + 2],
                        close        = (double)dataList[k * fieldLen + 3],
                        volume       = (double)dataList[k * fieldLen + 4],
                        amount       = (double)dataList[k * fieldLen + 5],
                        openInterest = (double)dataList[k * fieldLen + 6]
                    });
                }
            }

            //【原版】如果该时间段第1个时间点的close为NAN,则放弃该时间段的所有数据
            //if (items.Count>0 && double.IsNaN(items[0].close)==true)
            //{
            //    return new List<FuturesMinute>();
            //}

            //判断该时间段前25条数据是否含有真正的数据(至少一条数据)
            List <FuturesMinute> tempItem = items.GetRange(0, 25);
            bool haveData = items.Any(x => double.IsNaN(x.close) != true);

            //【新版1】如果该时间段前5个时间点的close为NAN,则放弃该时间段的所有数据
            //if (items.Count > 0 && double.IsNaN(items[0].close) && double.IsNaN(items[1].close) &&
            //    double.IsNaN(items[2].close) && double.IsNaN(items[3].close) && double.IsNaN(items[4].close))
            //{
            //    return new List<FuturesMinute>();
            //}

            //【新版2】如果该时间段前20个时间点的close为NAN,则放弃该时间段的所有数据
            if (items.Count > 0 && haveData == false)
            {
                return(new List <FuturesMinute>());
            }


            return(items);
        }
예제 #7
0
        protected List <OptionInfo> readFromWindOnly50ETFOption(string underlying = "510050.SH", string market = "sse")
        {
            DateTime timeOf50ETFDividend2016    = new DateTime(2016, 11, 29);//2016年50ETF分红时间
            double   standardContractMultiplier = 10000;
            string   marketStr = "";

            if (market == "sse")
            {
                marketStr = ".SH";
            }
            if (Caches.WindConnection == false)
            {
                return(null);
            }
            WindAPI           wapi     = Platforms.GetWindAPI();
            WindData          wd       = wapi.wset("optioncontractbasicinfo", "exchange=" + market + ";windcode=" + underlying + ";status=all");
            int               len      = wd.codeList.Length;
            int               fieldLen = wd.fieldList.Length;
            List <OptionInfo> items    = new List <OptionInfo>(len);

            object[] dm = (object[])wd.data;
            for (int k = 0; k < len; k++)
            {
                items.Add(new OptionInfo
                {
                    optionCode         = (string)dm[k * fieldLen + 0] + marketStr,
                    optionName         = (string)dm[k * fieldLen + 1],
                    executeType        = (string)dm[k * fieldLen + 5],
                    strike             = (double)dm[k * fieldLen + 6],
                    contractMultiplier = (double)dm[k * fieldLen + 7],
                    optionType         = (string)dm[k * fieldLen + 4],
                    startDate          = (DateTime)dm[k * fieldLen + 9],
                    endDate            = (DateTime)dm[k * fieldLen + 10]
                });
            }
            for (int i = 0; i < items.Count(); i++)
            {
                var item = items[i];
                if (item.startDate < timeOf50ETFDividend2016 && item.endDate >= timeOf50ETFDividend2016)
                {
                    item.modifiedDate         = timeOf50ETFDividend2016;
                    item.strikeBeforeModified = Math.Round(item.strike * item.contractMultiplier / standardContractMultiplier, 2);
                }
                else
                {
                    item.strikeBeforeModified = item.strike;
                }
                items[i] = item;
            }
            return(items);
        }
예제 #8
0
        protected List <OptionInfo> readFromWindOnlyByDate(string underlying, DateTime startDate, DateTime endDate)
        {
            if (Caches.WindConnection == false)
            {
                return(null);
            }
            underlying = underlying.ToUpper();
            var               tradeDays          = DateUtils.GetTradeDays(startDate, endDate);
            WindAPI           wapi               = Platforms.GetWindAPI();
            List <OptionInfo> items              = new List <OptionInfo>();
            Dictionary <string, OptionInfo> list = new Dictionary <string, OptionInfo>();

            foreach (var date in tradeDays)
            {
                string   dateStr  = date.ToString("yyyy-MM-dd");
                WindData wd       = wapi.wset("optionchain", "date=" + dateStr + ";us_code=" + underlying + ";option_var=全部;call_put=全部");
                object[] dm       = (object[])wd.data;
                int      len      = wd.codeList.Length;
                int      fieldLen = wd.fieldList.Length;
                for (int k = 0; k < len; k++)
                {
                    OptionInfo myInfo = new OptionInfo
                    {
                        optionCode         = (string)dm[k * fieldLen + 2],
                        optionName         = (string)dm[k * fieldLen + 4],
                        executeType        = (string)dm[k * fieldLen + 5],
                        strike             = (double)dm[k * fieldLen + 6],
                        contractMultiplier = (double)dm[k * fieldLen + 13],
                        optionType         = (string)dm[k * fieldLen + 8],
                        startDate          = (DateTime)dm[k * fieldLen + 9],
                        endDate            = (DateTime)dm[k * fieldLen + 10]
                    };
                    if (list.ContainsKey(myInfo.optionName) == false)
                    {
                        list.Add(myInfo.optionName, myInfo);
                        items.Add(myInfo);
                    }
                }
            }
            return(items);
        }
예제 #9
0
        protected override List <StockDailyWithFactor> readFromWind(string code, DateTime dateStart, DateTime dateEnd, string tag = null, IDictionary <string, object> options = null)
        {
            WindAPI  w        = Platforms.GetWindAPI();
            WindData wd       = w.wsd(code, "open,high,low,close,volume,amt,adjfactor,settle,pre_close,pre_settle,mkt_cap_CSRC,mkt_cap_float,pe_ttm,pb,ps_ttm,industry2", dateStart, dateEnd, "Fill=Previous;currencyType=;ruleType=3;industryType=1;industryStandard=1");
            int      len      = wd.timeList.Length;
            int      fieldLen = wd.fieldList.Length;

            var items = new List <StockDailyWithFactor>(len * fieldLen);

            // if (wd.data is double[])
            {
                object[]   dataList = (object[])wd.data;
                DateTime[] timeList = wd.timeList;

                for (int k = 0; k < len; k++)
                {
                    items.Add(new StockDailyWithFactor
                    {
                        time             = timeList[k],
                        open             = (double)dataList[k * fieldLen + 0],
                        high             = (double)dataList[k * fieldLen + 1],
                        low              = (double)dataList[k * fieldLen + 2],
                        close            = (double)dataList[k * fieldLen + 3],
                        volume           = (double)dataList[k * fieldLen + 4],
                        amount           = (double)dataList[k * fieldLen + 5],
                        adjustFactor     = (double)dataList[k * fieldLen + 6],
                        settle           = Convert.IsDBNull(dataList[k * fieldLen + 7])?0:(double)dataList[k * fieldLen + 7],
                        preClose         = (double)dataList[k * fieldLen + 8],
                        preSettle        = Convert.IsDBNull(dataList[k * fieldLen + 9])?0:(double)dataList[k * fieldLen + 9],
                        marketValue      = (double)dataList[k * fieldLen + 10],
                        floatMarketValue = (double)dataList[k * fieldLen + 11],
                        PE       = (double)dataList[k * fieldLen + 12],
                        PB       = (double)dataList[k * fieldLen + 13],
                        PS       = (double)dataList[k * fieldLen + 14],
                        industry = (string)dataList[k * fieldLen + 15]
                    });
                }
            }

            return(items);
        }
예제 #10
0
        public override List <StockDailyMarket> readFromWind(string code, DateTime startDate, DateTime endDate, string tag = null, IDictionary <string, object> options = null)
        {
            if (Caches.WindConnection == false && Caches.WindConnectionTry == true)
            {
                return(null);
            }
            WindAPI  w        = Platforms.GetWindAPI();
            WindData wd       = w.wsd(code, "pre_close,open,high,low,close,volume,amt,dealnum,chg,pct_chg,swing,vwap,adjfactor,turn,free_turn,trade_status,susp_reason,susp_days,maxupordown", startDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd"), "");
            int      len      = wd.timeList.Length;
            int      fieldLen = wd.fieldList.Length;
            var      items    = new List <StockDailyMarket>(len * fieldLen);

            DateTime[] timeList = wd.timeList;
            object[]   dataList = (object[])wd.data;
            for (int k = 0; k < len; k++)
            {
                //if (code == "000059.SZ" && k == 2049)
                //{
                //    var mycode = code;
                //    var mytime = timeList[k];
                //    var mypreClose = (double)Kit.DBNullToZero(dataList[k * fieldLen + 0]);
                //    Console.WriteLine(Kit.DBNullToZero(dataList[k * fieldLen + 1]).GetType());
                //    Console.WriteLine(Convert.ToDouble(dataList[k * fieldLen + 1]));
                //    var myopen = (double)Kit.DBNullToZero(dataList[k * fieldLen + 1]);
                //    var myhigh = (double)dataList[k * fieldLen + 2];
                //    var mylow = (double)dataList[k * fieldLen + 3];
                //    var myclose = (double)dataList[k * fieldLen + 4];
                //    var myvolume = (double)dataList[k * fieldLen + 5];
                //    var myamount = (double)dataList[k * fieldLen + 6];
                //    var mydealnum = dataList[k * fieldLen + 7] is DBNull ? 0 : (double)dataList[k * fieldLen + 7];
                //    var myupsAndDowns = (double)dataList[k * fieldLen + 8];
                //    var mypercentUpsAndDowns = (double)dataList[k * fieldLen + 9];
                //    var myswing = (double)dataList[k * fieldLen + 10];
                //    var myvwap = dataList[k * fieldLen + 11] is DBNull ? 0 : (double)dataList[k * fieldLen + 11];
                //    var myadjfactor = (double)dataList[k * fieldLen + 12];
                //    var myturn = (double)dataList[k * fieldLen + 13];
                //    var myfree_turn = (double)dataList[k * fieldLen + 14];
                //    var mytrade_status = dataList[k * fieldLen + 15] is DBNull ? string.Empty : Convert.ToString(dataList[k * fieldLen + 15]);
                //    var mysusp_reason = dataList[k * fieldLen + 16] is DBNull ? string.Empty : Convert.ToString(dataList[k * fieldLen + 16]);
                //    var mysusp_days = dataList[k * fieldLen + 17] is DBNull ? 0 : (int)dataList[k * fieldLen + 17];
                //    var mymaxUpOrDown = (int)dataList[k * fieldLen + 18];
                //}
                items.Add(new StockDailyMarket
                {
                    code               = code,
                    time               = timeList[k],
                    preClose           = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 0])),
                    open               = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 1])),
                    high               = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 2])),
                    low                = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 3])),
                    close              = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 4])),
                    volume             = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 5])),
                    amount             = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 6])),
                    dealnum            = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 7])),
                    upsAndDowns        = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 8])),
                    percentUpsAndDowns = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 9])),
                    swing              = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 10])),
                    vwap               = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 11])),
                    adjfactor          = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 12])),
                    turn               = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 13])),
                    free_turn          = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 14])),
                    trade_status       = dataList[k * fieldLen + 15] is DBNull ? string.Empty : Convert.ToString(dataList[k * fieldLen + 15]),
                    susp_reason        = dataList[k * fieldLen + 16] is DBNull ? string.Empty : Convert.ToString(dataList[k * fieldLen + 16]),
                    susp_days          = Convert.ToInt32(Kit.DBNullToZero(dataList[k * fieldLen + 17])),
                    maxUpOrDown        = Convert.ToInt32(Kit.DBNullToZero(dataList[k * fieldLen + 18]))
                });
                // Console.Write("{0}  ", k);
            }
            return(items);
        }
예제 #11
0
        public List <StockBasicInfo> readFromWind(DateTime date, string tag = null, List <string> existCode = null, List <StockBasicInfo> preList = null, IDictionary <string, object> options = null)
        {
            if (Caches.WindConnection == false && Caches.WindConnectionTry == true)
            {
                return(null);
            }
            date = DateUtils.PreviousOrCurrentTradeDay(date);//获取最近的交易日
            WindAPI       w        = Platforms.GetWindAPI();
            WindData      delist   = w.wset("sectorconstituent", "date=" + date.ToString("yyyy-MM-dd") + ";sectorid=a001010m00000000");
            WindData      list     = w.wset("sectorconstituent", "date=" + date.ToString("yyyy-MM-dd") + ";sectorid=a001010100000000");
            List <string> codeList = new List <string>();
            int           len      = delist.codeList.Length;
            int           fieldLen = delist.fieldList.Length;

            object[] dataList = (object[])delist.data;
            for (int k = 0; k < len; k++)
            {
                var code = dataList[k * fieldLen + 1].ToString();
                if ((existCode != null && existCode.Contains(code) == true) || existCode == null)
                {
                    codeList.Add(code);
                }
            }
            len      = list.codeList.Length;
            fieldLen = list.fieldList.Length;
            dataList = (object[])list.data;
            for (int k = 0; k < len; k++)
            {
                var code = dataList[k * fieldLen + 1].ToString();
                if ((existCode != null && existCode.Contains(code) == false) || existCode == null)
                {
                    codeList.Add(code);
                }
            }
            codeList.Sort();
            List <StockBasicInfo> items = new List <StockBasicInfo>();
            WindData wd = new WindData();

            foreach (var code in codeList)
            {
                wd       = w.wsd(code, "sec_name,ipo_date,delist_date", date.ToString("yyyy-MM-dd"), date.ToString("yyyy-MM-dd"), "");
                dataList = (object[])wd.data;
                items.Add(new StockBasicInfo
                {
                    code       = code,
                    name       = dataList[0].ToString(),
                    listDate   = (DateTime)dataList[1],
                    delistDate = dataList[2] is DBNull ? new DateTime(2099, 12, 31) : (DateTime)dataList[2]
                });
            }
            if (preList != null)
            {
                foreach (var stock in preList)
                {
                    if (items.Find(x => x.code == stock.code) == null)
                    {
                        items.Add(stock);
                    }
                }
            }
            return(items.OrderBy(x => x.code).ToList());
        }