Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            WindAPI w = new WindAPI();
            w.start();

            w.stop();
        }
Ejemplo n.º 2
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.º 3
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("600000.SH,600004.SH", "open", "2014-10-16", "2014-12-16", "");
            OutputWindData(wd, "wsd");

            w.stop();
        }
Ejemplo n.º 4
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.º 5
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);
        }
Ejemplo n.º 6
0
        private static void Main(string[] args)
        {
            WindAPI w = new WindAPI();

            // Custom test block for live DLL integration
            Console.WriteLine();
            Console.WriteLine(WindTest.Test());
            Console.WriteLine("Press enter to continue...");
            Console.ReadLine();
            // End test block

            w.start();

            WindData wd = w.wsd("600000.SH", "MACD", "ED-1M", "2014-12-16", "MACD_L=26;MACD_S=12;MACD_N=9;MACD_IO=1;Fill=Previous");

            string str = WindDataMethod.WindDataToString(wd, "wsd");
            Console.Write(str);
            Console.Read();

            w.stop();
        }
Ejemplo n.º 7
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();
        }