Ejemplo n.º 1
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", "w088801001", "******", "SHSZ");
            string   strLogonId = wd.GetLogonId();

            //下单浦发银行
            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();
        }
Ejemplo n.º 2
0
        public SystemGlobal(WindAPI _w)
        {
            w = _w;
            try
            { w.start(); }
            catch
            { }

            Init();
        }
Ejemplo n.º 3
0
        public void Execute()
        {
            //从万得提取数据
            WindAPI w = new WindAPI();

            w.start();
            WindData wd = w.wsi("510050.SH", "open,high,low,close,volume"
                                , "2016-07-01 09:00:00", "2016-07-22 15:00:00", "Fill=Previous");

            w.stop();
            //初始化各类变量
            DateTime[] DataDate = wd.timeList;
            String.Format("yyyy/MM/dd hh:mm:ss", DataDate);
            //日期、开盘价、最高价、最低价、收盘价、成交量
            int FieldLength = wd.GetFieldLength();
            int DataLength  = wd.GetDataLength();
            int DateLength  = DataLength / FieldLength;
            int sign        = 0;//下标计数

            double[] RawData = (double[])wd.data;
            double[,] MarketData = new double[DateLength, 5];

            /*
             * double[] OP = new double[DateLength];
             * double[] HP = new double[DateLength];
             * double[] LP = new double[DateLength];
             * double[] CP = new double[DateLength];
             */
            for (int i = 0; i < RawData.Length; i = i + FieldLength)
            {
                for (int j = 0; j < FieldLength; j++)
                {
                    MarketData[sign, j] = RawData[i + j];
                }
                sign++;
            }
            //    System.Console.WriteLine("{0},{1},{2},{3}", sign, MarketData.GetLength(0), MarketData.GetLength(1), DateLength);

            /*
             * for (int now = 0; now <= sign; now++)
             * {
             *  if (now != 0 && now % 60 == 0)//60min做一次停顿
             *      Console.ReadKey();
             *  System.Console.WriteLine("Time:{0} -- O:{1} H:{2} L:{3} C:{4} Volum:{5}\n"
             *      , DataDate[now], MarketData[now,0], MarketData[now,1]
             *      , MarketData[now,2], MarketData[now,3], MarketData[now,4]);
             * }
             * Console.ReadKey();
             */
            GenSignal myGS = new GenSignal();

            myGS.getSignal(MarketData);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 获取可立即使用的WindAPI,如果处于未连接状态自动开启
 /// </summary>
 /// <returns></returns>
 public static WindAPI GetWindAPI()
 {
     if (_windAPI == null)
     {
         _windAPI = new WindAPI();
     }
     if (!_windAPI.isconnected())
     {
         _windAPI.start();
     }
     return(_windAPI);
 }
Ejemplo n.º 5
0
        public Int64 getDataSetCount()
        {
            WindAPI w = new WindAPI();

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

            if (wd == null)
            {
                return(-1);
            }
            return(wd.codeList.Length);
        }
Ejemplo n.º 6
0
        private void button2_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            WSSProcess wssp = new WSSProcess();
            WindAPI    w    = new WindAPI();

            w.start();
            DataTable dt = wssp.getRecods(w, textBox1.Text, textBox2.Text);

            this.dataGridView1.DataSource = dt;
            this.dataGridView1.Show();
            this.Cursor = Cursors.Default;
        }
Ejemplo n.º 7
0
        private void GetStockList()
        {
            TradeDays myTradeDays = new TradeDays(20130601, 20160626);

            int[] changeDate = new int[7] {
                20130628, 20131213, 20140613, 20141212, 20150612, 20151211, 20160608
            };
            w.start();
            foreach (int date in changeDate)
            {
                int           today        = date;
                int           tomorrow     = TradeDays.GetNextTradeDay(date);
                string        todayStr     = DateTime.ParseExact(today.ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd");
                string        tomorrowStr  = DateTime.ParseExact(tomorrow.ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd");
                List <string> todayList    = new List <string>();
                List <string> tomorrowList = new List <string>();
                List <string> stockIn      = new List <string>();
                List <string> stockOut     = new List <string>();
                WindData      wd           = w.wset("sectorconstituent", "date=" + todayStr + ";windcode=" + indexName);
                object[]      stockList    = wd.data as object[];
                int           num          = stockList.Length / 3;
                for (int i = 0; i < num; i++)
                {
                    todayList.Add(Convert.ToString(stockList[i * 3 + 1]));
                }
                wd        = w.wset("sectorconstituent", "date=" + tomorrowStr + ";windcode=" + indexName);
                stockList = wd.data as object[];
                num       = stockList.Length / 3;
                for (int i = 0; i < num; i++)
                {
                    tomorrowList.Add(Convert.ToString(stockList[i * 3 + 1]));
                }
                foreach (string code in tomorrowList)
                {
                    if (todayList.Contains(code) == false)
                    {
                        stockIn.Add(code);
                    }
                }
                foreach (string code in todayList)
                {
                    if (tomorrowList.Contains(code) == false)
                    {
                        stockOut.Add(code);
                    }
                }
                stockModifyList myList = new stockModifyList(today, stockIn, stockOut);
                changeList.Add(today, myList);
            }
        }
Ejemplo n.º 8
0
        public static CodeInfo[] Down(string[] windcode, string date)
        {
            WindAPI wind = new WindAPI();

            wind.start();
            if (string.IsNullOrEmpty(date))
            {
                date = DateTime.Now.ToString("yyyyMMdd");
            }

            var wd = wind.wss(string.Join(",", windcode), $"lasttrade_date,dlmonth,transactionfee,todaypositionfee,sccode,margin,contract_issuedate,ipo_date", $"tradeDate={date}");

            if (wd.data == null)
            {
                return(null);
            }

            var ws = wd.getDataByFunc("wss", false) as object[, ];

            var l = ws.GetLongLength(0);

            List <CodeInfo> ret = new List <CodeInfo>();

            for (var i = 0; i < l; i++)
            {
                var info = new CodeInfo();
                info.WindCode = windcode[i];

                info.LastTradeDate    = (DateTime)ws[i, 0];
                info.DLMonth          = int.Parse(ws[i, 1].ToString());
                info.Transactionfee   = (string)ws[i, 2];
                info.TodayPositionfee = (string)ws[i, 3];
                info.Name             = (string)ws[i, 4];

                if (ws[i, 5] != null)
                {
                    info.margin = (double)ws[i, 5];
                }

                info.ContractIssuedate = (DateTime)ws[i, 6];
                info.IssueDate         = (DateTime)ws[i, 7];

                info.Code = CodeInfo.GetTradeCode(info.WindCode);

                ret.Add(info);
            }

            return(ret.ToArray());
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="date">指定日期</param>
 public GetStocks(int startDate, int endDate, string indexName)
 {
     this.startDate = startDate;
     this.endDate   = endDate;
     this.indexName = indexName;
     if (myTradeDays == null)
     {
         myTradeDays = new TradeDays(startDate, endDate);
     }
     if (stockList == null)
     {
         w.start();
         stockList = getExitsStocks();
     }
 }
Ejemplo n.º 10
0
        public static List <CodeInfo> GetAllCodes(string dateTime = null)
        {
            WindAPI wind = new WindAPI();

            wind.start();

            var date = DateTime.Parse(dateTime);

            List <CodeInfo> rets = new List <CodeInfo>();

            rets.AddRange(GetSectorCodeInfo(wind, date, "a599010201000000"));  // 上海交易所
            rets.AddRange(GetSectorCodeInfo(wind, date, "a599010301000000"));  // 大商所
            rets.AddRange(GetSectorCodeInfo(wind, date, "a599010401000000"));  // 郑商所

            return(rets);
        }
Ejemplo n.º 11
0
        static void DoAPISameple()
        {
            WindAPI w = new WindAPI();

            w.start();

            //wset取沪深300指数成分
            //WindData wd = w.wset("IndexConstituent", "date=20141215;windcode=000300.SH");
            //OutputWindData(wd, "wset");

            WindData wd = w.wsd("I2009.DCE", "open", "2020-05-24", "2020-05-24", "");

            OutputWindData(wd, "wsd");

            w.stop();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 万德的查询函数
        /// </summary>
        /// <param name="code">查询对象代码</param>
        private void Execute(List <string> code)
        {
            WindAPI w = new WindAPI();

            w.start();
            int    errorId  = 0;
            string codeList = "";

            foreach (var item in code)
            {
                codeList += item + ",";
                dataList.Add(item, new Level1Data());
            }
            codeList.Remove(codeList.Length - 1, 1);

            ulong reqId = w.wsq(ref errorId, codeList, "rt_ask1,rt_asize1,rt_bid1,rt_bsize1,rt_latest,rt_time", "", myCallback);
        }
Ejemplo n.º 13
0
        //启动、登录
        public static bool Login()
        {
            if (null == windHandle)
            {
                windHandle = new WindAPI();
            }
            int nStatus = 0;

            if (!windHandle.isconnected())
            {
                nStatus = windHandle.start();
            }
            if (0 != nStatus)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 14
0
 public WDBuilder(WindAPI _w)
 {
     if (_w == null)
     {
         try
         {
             _w = new WindAPI();
             _w.start();
         }
         catch
         {
             throw (new Exception("万得接口突然崩溃!"));
         }
         ////_w = new WindAPI();
         ////_w.start();
     }
     w = _w;
 }
Ejemplo n.º 15
0
        private void GetBonusPlan()
        {
            bonusList = new SortedDictionary <string, stockBonus>();
            w.start();
            //利用万德wset的“分红预案”抓取数据
            WindData wd = w.wset("dividendproposal", "ordertype=1;startdate=2015-06-30;enddate=2020-12-31;sectorid=a001010100000000;field=wind_code,sec_name,progress,cash_dividend,fellow_preplandate");

            object[] stockList = wd.data as object[];
            int      num       = stockList.Length / 5;

            for (int i = 0; i < num; i++)
            {
                stockBonus myBonus = new stockBonus();
                myBonus.code      = Convert.ToString(stockList[i * 5]);
                myBonus.name      = (string)stockList[i * 5 + 1];
                myBonus.progress  = (string)stockList[i * 5 + 2];
                myBonus.planBonus = (stockList[i * 5 + 3] == null? 0:(double)stockList[i * 5 + 3]);
                string[] date = Convert.ToString(stockList[i * 5 + 4]).Split(new char[] { '/', ' ' });
                myBonus.planDate = Convert.ToInt32(date[0]) * 10000 + Convert.ToInt32(date[1]) * 100 + Convert.ToInt32(date[2]);
                if (TradeDays.GetTimeSpan(myBonus.planDate, yesterday) <= 125 && myBonus.code.Substring(7, 2) == "SH")
                {
                    if (bonusList.ContainsKey(myBonus.code) == false)
                    {
                        bonusList.Add(myBonus.code, myBonus);
                    }
                    else if (TradeDays.GetTimeSpan(myBonus.planDate, yesterday) < TradeDays.GetTimeSpan(bonusList[myBonus.code].planDate, yesterday))
                    {
                        bonusList[myBonus.code] = myBonus;
                    }
                }
            }
            foreach (var item in GetStocks.stockList)
            {
                string code = item.Key;
                if (bonusList.ContainsKey(code) == false)
                {
                    stockBonus myBonus = new stockBonus();
                    myBonus.code     = item.Value.code;
                    myBonus.name     = item.Value.name;
                    myBonus.progress = "没有分红预案";
                    bonusList.Add(myBonus.code, myBonus);
                }
            }
        }
Ejemplo n.º 16
0
        //启动、登录
        private bool start()
        {
            if (null == m_w)
            {
                m_w = new WindAPI();
            }

            int nStatus = 0;

            if (!m_w.isconnected())
            {
                nStatus = m_w.start();
            }
            if (0 != nStatus)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 按日期遍历,添加期权信息。写入静态哈希表myOptionList。
        /// </summary>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        private void GetOptionInformationList(int startDate, int endDate)
        {
            //定义交易日期的类。
            TradeDays myTradeDays = new TradeDays(startDate, endDate);

            //从数据库表中获取信息,如果已经是完整信息就不需要连接万德数据库。
            if (GetOptionListFromTable(startDate, endDate) == true)
            {
                return;
            }
            //按日期遍历,添加期权信息。
            WindAPI w = new WindAPI();

            w.start();
            foreach (int today in myTradeDays.myTradeDays)
            {
                if (TradeDays.IsOptionExerciseDate(today) || today == myTradeDays.myTradeDays[myTradeDays.myTradeDays.Count - 1])
                {
                    WindData optionToday = w.wset("OptionChain", "date=" + today.ToString() + ";us_code=" + Configuration.underlyingAsset + ";option_var=;month=全部;call_put=全部");
                    object[] optionList  = optionToday.data as object[];
                    int      num         = optionList.Length / 13;
                    for (int i = 0; i < num; i++)
                    {
                        optionFormat option     = new optionFormat();
                        string       codeString = (string)optionList[i * 13 + 4 - 1];
                        option.optionCode  = Convert.ToInt32(codeString.Substring(0, 8));
                        option.market      = codeString.Substring(9, 2);
                        option.optionName  = (string)optionList[i * 13 + 5 - 1];
                        option.executeType = (string)optionList[i * 13 + 6 - 1];
                        option.strike      = (double)optionList[i * 13 + 7 - 1];
                        option.optionType  = (string)optionList[i * 13 + 9 - 1];
                        option.startDate   = TradeDays.DateTimeToInt((DateTime)optionList[i * 13 + 10 - 1]);
                        option.endDate     = TradeDays.DateTimeToInt((DateTime)optionList[i * 13 + 11 - 1]);
                        if (myOptionList.ContainsKey(option.optionCode) == false)
                        {
                            myOptionList.Add(option.optionCode, option);
                        }
                    }
                }
            }
            w.stop();
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDeal_Click(object sender, EventArgs e)
        {
            //接口初始化
            WindAPI w = new WindAPI();

            //在接口操作前,用户首先要登录并启动C#插件,即使用w.start()命令。其中,返回值0表示登陆成功,负数表示登陆失败,可通过w.getErrorMsg()函数获取错误信息。
            w.start();

            //当需要判断是否连接c#接口时,可以使用w.isconnected()命令。返回值True表示处于连接状态,反之False表示连接断开。
            if (w.isconnected())
            {
                WindData wd = w.wss("000001.SZ,000002.SZ", "open,low,close,volume", "tradeDate=20180809;priceAdj=U;cycle=D");
                //返回的数据转化为便于使用的数据结构,
                object[,] getData = (object[, ])wd.getDataByFunc("wss", false);
                MessageBox.Show("连接成功");
            }

            //当需要停止使用C#接口时,可以使用w.stop()命令,由于程序退出时会自动执行w.stop()命令,用户一般并不需要执行。
            w.stop();
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 获取WindAPI,三次登录失败返回null
        /// </summary>
        /// <returns></returns>
        public static WindAPI GetApi()
        {
            WindAPI w = new WindAPI();

            for (int i = 0; i < 3; i++)
            {
                //登录WFT
                int nRetCode = w.start();
                if (0 != nRetCode)//登录失败
                {
                    var strErrorMsg = w.getErrorMsg(nRetCode);
                    Logger.Write("登录WFT失败", strErrorMsg, string.Empty, string.Empty, LogLevel.Error, 0);
                }
                else
                {
                    return(w);
                }
            }
            return(null);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 获取可立即使用的WindAPI,如果处于未连接状态自动开启
        /// </summary>
        /// <returns></returns>
        public static WindAPI GetWindAPI()
        {
            if (_windAPI == null)
            {
                _windAPI = new WindAPI();
            }

            if (!_windAPI.isconnected() && Caches.WindConnectionTry == false)
            {
                int myStart = _windAPI.start();
                Caches.WindConnectionTry = true;
                if (myStart == 0)
                {
                    Caches.WindConnection = true;
                }
                else
                {
                    Caches.WindConnection = false;
                }
            }
            return(_windAPI);
        }
Ejemplo n.º 21
0
 public static WindAPI getAPI()
 {
     if (api == null || !api.isconnected())
     {
         api = new WindAPI();
         try
         {
             int result = (int)api.start();
             if (result == 0)
             {
                 Console.WriteLine(" Wind API 登录成功!");
             }
             else
             {
                 Console.WriteLine(" Wind API 登录失败: " + api.getErrorMsg(result));
             }
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
         }
     }
     return(api);
 }
Ejemplo n.º 22
0
 static DataFeed()
 {
     _dict = new Dictionary <ulong, DataHandler>();
     _api  = new WindAPI();
     _api.start();
 }
Ejemplo n.º 23
0
        public void DoIt()
        {
            WindAPI w = new WindAPI();

            w.start();

            //取昨天的最高、最低、收盘
            double   dLastHigh = 0; double dLastLow = 0; double dLastClose = 0;
            WindData wd = w.wss("600999.SH", "high,low,close", "tradeDate=20141202;priceAdj=U;cycle=D");

            //WindData wd = w.wss("601000.SH", "high,low,close", "tradeDate=20141202;priceAdj=U;cycle=D");
            //WindData wd = w.wss("M1309.DCE", "high,low,close", "tradeDate=20130411;priceAdj=U;cycle=D");
            double[,] lastPriceData = (double[, ])wd.getDataByFunc("wss", true);
            if (null == lastPriceData)
            {
                return;
            }
            dLastHigh  = lastPriceData[0, 0];
            dLastLow   = lastPriceData[0, 1];
            dLastClose = lastPriceData[0, 2];

            //计算出6个价位
            double dSsetup = dLastHigh + 0.35 * (dLastClose - dLastLow);             //观察卖出价
            double dSenter = (1.07 / 2) * (dLastHigh + dLastLow) - 0.07 * dLastLow;  //反转卖出价
            double dBenter = (1.07 / 2) * (dLastHigh + dLastLow) - 0.07 * dLastHigh; //反转买入价
            double dBsetup = dLastLow - 0.35 * (dLastHigh - dLastClose);             //观察买入价
            double dBbreak = dSsetup + 0.25 * (dSenter - dBsetup);                   //突破买入价
            double dSbreak = dBsetup - 0.205 * (dSenter - dBsetup);                  //突破卖出价

            //某天的交易数据
            WindData wdWSI = w.wsi("600999.SH", "high,low,close", "2014-12-03 09:30:00", "2014-12-03 15:00:00", "");

            //WindData wdWSI = w.wsi("601000.SH", "high,low,close", "2014-12-03 09:30:00", "2014-12-03 15:00:00", "");
            //WindData wdWSI = w.wsi("M1309.DCE", "high,low,close", "2013-04-12 09:30:00", "2013-04-12 15:00:00", "");
            double[,] curPriceData = (double[, ])wdWSI.getDataByFunc("wsi", true);
            if (null == curPriceData)
            {
                return;
            }
            int nTimeCount = curPriceData.GetLength(0);

            if (nTimeCount < 0)
            {
                return;
            }
            int nPriceDim = curPriceData.GetLength(1);

            if (nPriceDim < 3)
            {
                return;
            }
            //策略初值,1表示做多,-1表示做空,0表示无操作
            List <int> curHoldList = new List <int>(nTimeCount);

            for (int i = 0; i < nTimeCount; i++)
            {
                curHoldList.Add(0);
            }
            double dCurHigh  = curPriceData[0, 0];
            double dCurLow   = curPriceData[0, 1];
            double dCurPrice = curPriceData[0, 2];

            for (int i = 0; i < nTimeCount; i++)
            {
                dCurHigh  = (curPriceData[i, 0] > dCurHigh) ? curPriceData[i, 0] : dCurHigh;
                dCurLow   = (curPriceData[i, 1] > dCurLow) ? curPriceData[i, 1] : dCurLow;
                dCurPrice = curPriceData[i, 2];

                //当前持仓
                int nCurHold = curHoldList.Sum();

                bool bCon1 = (dCurPrice > dBbreak) && (0 == nCurHold);                        //空仓做多条件
                bool bCon2 = (dCurPrice < dSbreak) && (0 == nCurHold);                        //空仓做空条件
                bool bCon3 = (nCurHold > 0) && (dCurHigh > dSsetup) && (dCurPrice < dSenter); //多单反转卖出条件:holding>0 and 今高>观察卖出价 and c<反转卖出价;
                bool bCon4 = (nCurHold < 0) && (dCurLow < dBsetup) && (dCurPrice > dBenter);  //空单反转买入条件:=holding<0 and 今低<观察买入价 and c>反转买入价;

                //交易
                if (bCon3)               //多单反转
                {
                    curHoldList[i] = -1; //平多 //sell
                }
                else if (bCon2)          //空单做空
                {
                    curHoldList[i] = -1; //sell
                }
                else if (bCon4)          //空单反转
                {
                    curHoldList[i] = 1;  //buy
                }
                else if (bCon1)          //空仓做多
                {
                    curHoldList[i] = 1;  //buy
                }
                else
                {
                    curHoldList[i] = 0;
                }
            }

            int nCurHole = curHoldList.Sum();

            //尾盘轧平
            if (1 == nCurHole && 1 == curHoldList.Last())
            {
                curHoldList[nTimeCount - 1] = 0;
            }
            else if (1 == nCurHole)
            {
                curHoldList[nTimeCount - 1] = -1;
            }
            else if (-1 == nCurHole && -1 == curHoldList.Last())
            {
                curHoldList[nTimeCount - 1] = 0;
            }
            else if (-1 == nCurHole)
            {
                curHoldList[nTimeCount - 1] = 1;
            }

            //统计收益
            double dProfit = 0;

            for (int i = 0; i < nTimeCount; i++)
            {
                dProfit += curPriceData[i, 2] * curHoldList[i];
            }

            Console.WriteLine("策略收益:" + dProfit);
            w.stop();
        }
Ejemplo n.º 24
0
 static DownBar()
 {
     wind.start();
 }
Ejemplo n.º 25
0
 static WSDClass()
 {
     w = new WindAPI();
     w.start();
 }