Exemple #1
0
        public WindData getDataSet()
        {
            WindAPI w = new WindAPI();

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

            return(wd);
        }
Exemple #2
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);
        }
Exemple #3
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());
        }
Exemple #4
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();
        }
        public static double GetSettlePrice(string symbol, string date)
        {
            double price = 0;

            if (Login())
            {
                string   par     = string.Format("tradeDate={0};cycle=D", date);//"tradeDate=20160410;cycle=D"
                WindData wd      = windHandle.wss(symbol, "settle", par);
                object   getData = wd.getDataByFunc("wss", false);
                if (checkError(wd) != 0)
                {
                    return(0);
                }
                if (getData is object[, ])//转化为2维数组
                {
                    object[,] odata = (object[, ])getData;
                    price           = double.Parse(odata[0, 0].ToString());
                }
            }
            return(price);
        }
        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();
        }