Example #1
0
 public WSETClass(WindAPI w, string _Type, string strCode, DateTime dt)
     : base(w)
 {
     strType = _Type;
     SecCode = strCode;
     Date    = dt;
 }
        /// <summary>
        /// 从万德数据库中读取交易日信息数据。
        /// </summary>
        private void GetDataFromWindDataBase()
        {
            int theLastDay = 0;

            if (tradeDaysOfDataBase.Count > 0)
            {
                theLastDay = tradeDaysOfDataBase[tradeDaysOfDataBase.Count - 1];
            }
            //万德API接口的类。
            WindAPI w = new WindAPI();

            w.start();
            //从万德数据库中抓取交易日信息。
            WindData days = w.tdays("20100101", "20161231", "");

            //将万德中读取的数据转化成object数组的形式。
            object[] dayData = days.data as object[];
            foreach (object item in dayData)
            {
                DateTime today = (DateTime)item;
                int      now   = DateTimeToInt(today);
                if (now > theLastDay)
                {
                    tradeDaysOfDataBase.Add(now);
                }
            }
            w.stop();
        }
Example #3
0
 public WTDaysOffsetClass(WindAPI _w, DateTime From, int days, string strParams)
     : base(_w)
 {
     _From   = From;
     _Days   = days;
     _params = strParams;
 }
Example #4
0
        public void DoIt()
        {
            string  strErrorMsg;
            WindAPI w = new WindAPI();

            //登录WFT
            int nRetCode = w.start();

            if (0 != nRetCode)//登录失败
            {
                strErrorMsg = w.getErrorMsg(nRetCode);
                Console.Write(strErrorMsg);
                return;
            }

            //登录账号
            Console.Write("\r\ntlogon……");
            WindData wd         = w.tlogon("0000", "0", "w081496501", "******", "SHSZ");
            string   strLogonId = wd.GetLogonId();

            wd = w.tquery("Trade");

            return;

            //下单浦发银行
            wd = w.torder("600000.SH", "Buy", "12.0", "200", "OrderType=LMT;LogonID=" + strLogonId);//单账户登录可以不指定LogonId=1
            //获取下单ID
            string strRequestID1 = wd.GetOrderRequestID();

            Console.WriteLine("RequestID=" + strRequestID1);

            //下单白云机场
            wd = w.torder("600004.SH", "Buy", "12.00", "300", "OrderType=LMT;LogonID=" + strLogonId);//单账户登录可以不指定LogonId=1
            //获取下单ID
            string strRequestID2 = wd.GetOrderRequestID();

            //查询
            Console.WriteLine("query……");
            wd = w.tquery("Order", "RequestID=" + strRequestID1);
            //获取浦发银行OrderNumber
            string strOrderNumber = wd.GetOrderNumber();

            //浦发银行撤单
            Console.WriteLine("cancel……");
            wd = w.tcancel(strOrderNumber);

            //再次查询
            Console.WriteLine("query after cancel……");
            wd = w.tquery("Order");
            string strQueryInfoAfter = WindDataMethod.WindDataToString(wd, "tquery");

            Console.Write(strQueryInfoAfter);

            //登出
            Console.WriteLine("tlogout……");
            w.tlogout();

            //退出WindAPI
            w.stop();
        }
Example #5
0
        public static MTable GetMutliSetData(WindAPI w, string[] code, DateTime endt, Cycle cyc, PriceAdj prcAdj, bool IncludeBaseData, string args)
        {
            RunNoticeClass ret  = new RunNoticeClass();
            MTable         mtab = new MTable();

            if (IncludeBaseData)
            {
                BaseDataProcess bp   = new BaseDataProcess_ForWD(w, cyc, prcAdj);
                RunResultClass  bret = bp.getSetDataResult(code, endt, new object[0] {
                });
                if (!bret.Notice.Success)
                {
                    mtab.Union(bret.Result);
                    //return new BaseDataTable();
                }
            }
            Dictionary <string, HashSet <string> > guids = getMutliValueGuid(args.Split(','));

            foreach (string key in guids.Keys)
            {
                MutliValueGuidProcess_ForWD cgp = new MutliValueGuidProcess_ForWD(w, key, guids[key].ToArray <string>());
                cgp.cycle  = cyc;
                cgp.prcAdj = prcAdj;
                RunResultClass cret = cgp.getSetDataResult(code, endt, new object[0] {
                });
                mtab.Union(cret.Result);
            }
            return(mtab);
        }
Example #6
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);
        }
        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);
        }
Example #8
0
        public static DateTime[] getTradeDates(WindAPI w, string SecCode, DateTime begt, DateTime endt, Cycle cyc)
        {
            BaseDataTable tb  = CommWDToolClass.GetBaseSerialData(w, SecCode, begt, endt, cyc, PriceAdj.UnDo, BaseDataPoint.trade_status, BaseDataPoint.sec_type, BaseDataPoint.close);
            BaseDataTable ttb = tb.AvaliableData;

            return(ttb["DateTime"].ToList <DateTime>().ToArray());
        }
Example #9
0
        /// <summary>
        /// 获取股票列表的信息。
        /// </summary>
        /// <param name="market">市场</param>
        /// <returns>商品期货信息列表</returns>
        public List <stockFormat> GetStockList(string indexName)
        {
            List <stockFormat> myList = new List <stockFormat>();
            //按日期遍历,添加股票信息。
            WindAPI w = new WindAPI();

            w.start();
            string[] dateStr = { "2013-06-01", "2013-12-01", "2014-06-01", "2014-12-01", "2015-06-01", "2015-12-01", "2016-06-01", "2016-06-20" };
            foreach (var item in dateStr)
            {
                WindData wd        = w.wset("sectorconstituent", "date=" + item + ";windcode=" + indexName);
                object[] stockList = wd.data as object[];
                int      num       = stockList.Length / 3;
                for (int i = 0; i < num; i++)
                {
                    stockFormat myStock = new stockFormat();
                    myStock.market = "SH";
                    myStock.code   = Convert.ToString(stockList[i * 3 + 1]).Substring(0, 6);
                    myStock.name   = (string)stockList[i * 3 + 2];
                    if (myList.Contains(myStock) == false)
                    {
                        myList.Add(myStock);
                    }
                }
            }
            w.stop();
            return(myList);
        }
Example #10
0
        public static DateTime Offset(WindAPI w, BaseDataItemClass SecItem, DateTime dt, int N, Cycle cyc)
        {
            DateTime begt = SecItem.Ipo_date;

            if (SecItem.SecType == SecType.Index)
            {
                //指数不停牌,自然日按交易日*7/5,放大到10/2=2倍指定开始日
                switch (cyc)
                {
                case Cycle.Day:
                {
                    begt = dt.AddDays(-2 * N);
                    break;
                }

                case Cycle.Week:
                {
                    begt = dt.AddDays(-7 * N);
                    break;
                }

                case Cycle.Month:
                {
                    begt = dt.AddMonths(N);
                    break;
                }

                case Cycle.Year:
                {
                    begt = dt.AddYears(N);
                    break;
                }
                }
            }
            if (begt.CompareTo(SecItem.Ipo_date) < 0)//任何情况(index的ipo日期为1899-12-31)如果开始日期小于ipo日期,开始日期设置为Ipo日期。
            {
                begt = SecItem.Ipo_date;
            }


            BaseDataTable tb = CommWDToolClass.GetBaseSerialData(
                w,
                SecItem.WindCode,
                begt,
                dt,
                Cycle.Day,
                PriceAdj.UnDo,
                BaseDataPoint.trade_status, BaseDataPoint.sec_type);
            BaseDataTable ttb = tb.AvaliableData;

            if (ttb.Count == 0)
            {
                return(dt);              //如果数据为空,返回回览日
            }
            if (ttb.Count > N)
            {
                return(((BaseDataItemClass)ttb[ttb.Count - N]).DateTime);
            }
            return(((BaseDataItemClass)ttb[0]).DateTime);
        }
Example #11
0
 public WSSClass(WindAPI _w, string SecCodes, string Fields, string Params)
     : base(_w)
 {
     _Fields   = Fields;
     _SecCodes = SecCodes;
     _Params   = Params;
 }
Example #12
0
 public WSSClass(WindAPI w, string SecCodes, HashSet <string> Fields, string Params)
     : base(w)
 {
     _SelctFields = Fields;
     _SecCodes    = SecCodes;
     _Params      = Params;
 }
Example #13
0
        public static void test1()
        {
            WindAPI w = new WindAPI();

            w.start();
            WindData wd = w.wsi("510050.SH", "open,high,low,close", "2016-07-26 09:00:00", "2016-07-26 14:56:12", "");
        }
Example #14
0
 public WSSClass(WindAPI _w, string SecCodes, HashSet <string> Fields)
     : base(_w)
 {
     _SelctFields = Fields;
     _SecCodes    = SecCodes;
     _Params      = "";
 }
Example #15
0
        private void Excute_Click(object sender, EventArgs e)
        {
            InitializeChart();
            this.myChart.Series.Clear();

            string strStartDate = this.startDateTimePicker.Text;
            string strEndDate   = this.endDateTimePicker.Text;

            WindAPI w = new WindAPI();

            w.start();

            WindData wd = null;

            if (this.radioButton_KQ.Checked)
            {
                wd = w.edb("M5407921", strStartDate, strEndDate, "");
            }
            else
            {
                wd = w.edb("M0000272", strStartDate, strEndDate, "");
            }

            w.stop();

            UpdateChart(wd);
        }
Example #16
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);
        }
Example #17
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);
        }
Example #18
0
        public static MTable getBkList(WindAPI w, string sec, DateTime dt, bool FilterTheNoPrice)
        {
            SecIndexClass   sic = new SecIndexClass(sec);
            secIndexBuilder sib = new secIndexBuilder(w, sic);
            MTable          mt  = sib.getBkList(dt);

            if (mt == null || mt.Count == 0)
            {
                return(mt);
            }
            BaseDataProcess_ForWD bdp = new BaseDataProcess_ForWD(w);

            string[]       seccodes = mt["wind_code"].ToList <string>().ToArray();
            RunResultClass rc       = bdp.getSetDataResult(seccodes, "close", dt);
            MTable         ret      = new MTable();
            List <DataRow> NewDrs   = new List <DataRow>();

            for (int i = 0; i < rc.Result.Count; i++)
            {
                DataRow retdr = mt.GetTable().Rows[i];
                DataRow dr    = rc.Result.GetTable().Rows[i];
                if (dr.IsNull("CLOSE") && FilterTheNoPrice)
                {
                    continue;
                }
                NewDrs.Add(retdr);
            }
            ret.FillList(NewDrs.ToArray());
            return(ret);
        }
Example #19
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());
        }
Example #20
0
 private void InitializeWind()
 {
     if (w == null)
     {
         w = new WindAPI();
         w.start();
     }
 }
Example #21
0
        public static int getTradeDays(WindAPI w, DateTime begt, DateTime endt)
        {
            TDaysGuidClas          tgc = new TDaysGuidClas();
            TDayGuildBuilder_ForWD tgb = new TDayGuildBuilder_ForWD(w, tgc);
            MTable ret = tgb.getRecordsCount(begt, endt);

            return((int)ret.GetTable().Rows[0][0]);
        }
Example #22
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);
        }
Example #23
0
 public WSDClass(WindAPI w, string SecCodes, string Fields, DateTime BegT, DateTime EndT, string strParams)
     : base(w)
 {
     _Fields   = Fields;
     _SecCodes = SecCodes;
     _BegT     = BegT;
     _EndT     = EndT;
     _Params   = strParams;
 }
Example #24
0
        public WindData getDataSet()
        {
            WindAPI w = new WindAPI();

            w.start();
            WindData wd = w.wss(_SecCodes, _Fields, _Params);

            return(wd);
        }
Example #25
0
 /// <summary>
 /// 市场最后交易日
 /// </summary>
 /// <param name="w"></param>
 /// <param name="dt"></param>
 /// <returns></returns>
 public static DateTime LastTradeDay(WindAPI w, DateTime dt, Cycle cy)
 {
     DateTime[] ret = getTradeDates(w, dt.AddDays(-20), dt, cy);
     if (ret.Length > 0)
     {
         return(ret[ret.Length - 1]);
     }
     return(DateTime.MinValue);
 }
Example #26
0
        public DataTable getHQData(string strCode, DateTime begT, DateTime endT)
        {
            GLClass  globj   = new GLClass(strCode);
            WindAPI  w       = null;
            WSDClass wsetobj = new WSDClass(w, strCode, "open,high,low,close,pct_chg,volume,windcode", begT, endT, "");

            //WSDClass wsetobj = new WSDClass(strCode, "open,close,volume,windcode", begT, endT);
            return(WDDataAdapter.getRecords(wsetobj.getDataSet()));
        }
Example #27
0
        public SystemGlobal(WindAPI _w)
        {
            w = _w;
            try
            { w.start(); }
            catch
            { }

            Init();
        }
Example #28
0
        public static DateTime[] getTradeDates(WindAPI w, DateTime begt, DateTime endt, Cycle cyc)
        {
            TDaysGuidClas tgc = new TDaysGuidClas();

            tgc.cycle = cyc;
            TDayGuildBuilder_ForWD tgb = new TDayGuildBuilder_ForWD(w, tgc);
            MTable ret = tgb.getRecords(begt, endt);

            return(ret.ToList <DateTime>().ToArray());
        }
Example #29
0
        public static DateTime LastTradeDay(WindAPI w, string SecCode, DateTime dt)
        {
            BaseDataTable tb  = CommWDToolClass.GetBaseSerialData(w, SecCode, dt.AddDays(-1000), dt, Cycle.Day, PriceAdj.UnDo, BaseDataPoint.trade_status, BaseDataPoint.sec_type, BaseDataPoint.close);
            BaseDataTable ttb = tb.AvaliableData;

            if (ttb.Count == 0)
            {
                return(DateTime.MinValue);
            }
            return(((BaseDataItemClass)ttb[ttb.Count - 1]).DateTime);
        }
Example #30
0
 /// <summary>
 /// 获取可立即使用的WindAPI,如果处于未连接状态自动开启
 /// </summary>
 /// <returns></returns>
 public static WindAPI GetWindAPI()
 {
     if (_windAPI == null)
     {
         _windAPI = new WindAPI();
     }
     if (!_windAPI.isconnected())
     {
         _windAPI.start();
     }
     return(_windAPI);
 }