Exemplo n.º 1
0
        //请求开始时由ASP.NET调用此方法
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            context.Response.ContentType = "text/plain";
            string code = AppRequest.GetQueryString("code");

            if (code.Length < 6)
            {
                context.Response.Write("fail");
            }
            else
            {
                context.Response.Write(RedisHelper.GetValues(code));
            }
            //构建异步结果并返回
            var result = new WebAsyncResult(cb, context);

            result.SetComplete();
            return(result);
        }
Exemplo n.º 2
0
 //异步结束时,由ASP.NET调用此方法
 public void EndProcessRequest(IAsyncResult result)
 {
     WebAsyncResult webresult = (WebAsyncResult)result;
 }
Exemplo n.º 3
0
        //请求开始时由ASP.NET调用此方法
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            context.Response.ContentType = "text/plain";
            string code  = AppRequest.GetQueryString("code");
            string url   = AppRequest.GetQueryString("url");
            string time  = AppRequest.GetQueryString("time");
            string token = AppRequest.GetQueryString("token");
            int    flag  = AppRequest.GetQueryInt("flag", 0);

            if (!Utils.tokenCk(url, time, token))
            {
                context.Response.Write("token校验失败,请刷新页面重试");
            }
            else
            {
                if (flag == 100)
                {
                    #region 使用自身行情
                    string keys_bak = code + "t_bak";
                    context.Response.Write(RedisHelper.GetValues(keys_bak));
                    #endregion
                }
                else
                {
                    #region 使用接口行情

                    if (code.Length != 6)
                    {
                        context.Response.Write("fail");
                    }
                    else
                    {
                        string   key       = code + "t" + (flag > 0 ? flag.ToString() : "");
                        string   hq        = RedisHelper.GetValues(key);
                        int      count     = 0;
                        DateTime dt        = DateTime.Now;
                        int      time_hhmm = Utils.StrToInt(dt.ToString("HHmm"), 0);//行情时间;
                        if (hq.Length > 32)
                        {
                            Model.StockTLine modelt = JsonHelper.ParseFromJson <Model.StockTLine>(hq);
                            count = modelt.mins.Count;
                            if (count > 0)
                            {
                                //检查交易时间是否已经有数据
                                if (((time_hhmm > 930 && time_hhmm < 1130) || (time_hhmm > 1300 && time_hhmm < 1500)))
                                {
                                    int countCk = modelt.mins.Where(t => t.time == time_hhmm.ToString()).Count();
                                    if (countCk > 0)
                                    {
                                        count = 240;
                                    }
                                    else
                                    {
                                        count = 0;
                                    }
                                }
                            }
                        }
                        if (count < 240 || count > 245)
                        {
                            StringBuilder sErrInfo = new StringBuilder(256);
                            StringBuilder sResult  = new StringBuilder(1024 * 1024);
                            bool          bRet     = TradeX.TdxHq_Connect(AppKeys.QuotationAPI, 7709, sResult, sErrInfo);
                            //Log.WriteLog("行情", sResult.ToString() + "++++" + sErrInfo.ToString());
                            if (bRet == true)
                            {
                                string stock_code_s = Utils.GetFullStockCode(code, flag);
                                if (time_hhmm >= 1500)
                                {
                                    dt = Utils.StrToDateTime(DateTime.Now.ToString("yyyy-MM-dd 15:00:00"));
                                }
                                byte   stock_market = 0;
                                string cyb          = Utils.subStr(code, 0, 1);
                                if (flag == 0)
                                {
                                    string cyb2 = Utils.subStr(code, 0, 2);
                                    if (cyb == "6" || cyb2 == "11" || cyb2 == "51" || cyb2 == "50")
                                    {
                                        stock_market = 1;
                                    }
                                }
                                else
                                {
                                    switch (cyb)
                                    {
                                    case "0":
                                        stock_market = 1;
                                        break;

                                    case "5":
                                        stock_market = 1;
                                        break;

                                    default:
                                        break;
                                    }
                                }
                                //股票最新行情
                                string[] stock_info = RedisHelper.GetValues(stock_code_s).Split(',');
                                if (stock_info.Length < 30)
                                {
                                    stock_info = Utils.GetStockData(code, 0, 0).Split(',');
                                }
                                bool bRet2 = TradeX.TdxHq_GetMinuteTimeData(stock_market, code, sResult, sErrInfo);
                                if (bRet2 == true && stock_info.Length > 30)
                                {
                                    string[] hq_time = AppKeys.CACHE_HQ_TIME.ToString().Split(',');
                                    string[] k_list  = sResult.ToString().Replace("\n", "#").Replace("\t", ",").Replace("-", "").Split('#');
                                    if (k_list.Length > 2 && hq_time.Length >= 240)
                                    {
                                        int lgt = k_list.Length, lgt_ck = hq_time.Length;
                                        if (lgt > lgt_ck)
                                        {
                                            lgt = lgt_ck;
                                        }
                                        for (int z = 1; z < lgt; z++)
                                        {
                                            string[] k_split = k_list[z].Split(',');
                                            if (k_split.Length >= 2)
                                            {
                                                //现价,成交量,保留
                                                decimal price_now = Utils.StrToDecimal(k_split[0], 0), price_num = Utils.StrToDecimal(k_split[1], 0),
                                                        price_keep = Utils.StrToDecimal(k_split[2], 0);
                                                //开盘价、收盘价、最高、最低、当前价、成交量、成交额
                                                decimal open = Utils.StrToDecimal(stock_info[1], 0), preClose = Utils.StrToDecimal(stock_info[2], 0),
                                                        highest = Utils.StrToDecimal(stock_info[4], 0), lowest = Utils.StrToDecimal(stock_info[5], 0),
                                                        fprice = Utils.StrToDecimal(stock_info[3], 0), deal_num = Utils.StrToDecimal(stock_info[8], 0),
                                                        deal_price = Utils.StrToDecimal(stock_info[9], 0);
                                                #region ====================行情数据
                                                if (z == 1)
                                                {
                                                    #region ====================初始数据

                                                    Model.StockTLine modelt = new Model.StockTLine()
                                                    {
                                                        quote = new Model.quote()
                                                        {
                                                            stock_name = stock_info[0],
                                                            time       = dt.ToString("yyyyMMddHHmmss"),
                                                            open       = open,
                                                            preClose   = preClose,
                                                            highest    = highest,
                                                            lowest     = lowest,
                                                            price      = fprice,
                                                            volume     = deal_num,
                                                            amount     = deal_price
                                                        }
                                                    };
                                                    Model.mins mins = new Model.mins()
                                                    {
                                                        price  = price_now,
                                                        volume = price_num,
                                                        amount = 0,
                                                        time   = hq_time[z - 1]
                                                    };
                                                    modelt.mins.Add(mins);
                                                    string json_first = JsonHelper.GetJson <Model.StockTLine>(modelt);
                                                    RedisHelper.Set <string>(key, json_first);
                                                    #endregion
                                                }
                                                else
                                                {
                                                    #region ====================更新数据
                                                    string old_str = RedisHelper.GetValues(key);//旧分时数据
                                                    if (!string.IsNullOrEmpty(old_str))
                                                    {
                                                        Model.StockTLine modelt = JsonHelper.ParseFromJson <Model.StockTLine>(old_str);
                                                        Model.quote      quote  = new Model.quote()
                                                        {
                                                            stock_name = stock_info[0],
                                                            time       = dt.ToString("yyyyMMddHHmmss"),
                                                            open       = open,
                                                            preClose   = preClose,
                                                            highest    = highest,
                                                            lowest     = lowest,
                                                            price      = fprice,
                                                            volume     = deal_num,
                                                            amount     = deal_price
                                                        };
                                                        Model.mins mins = new Model.mins()
                                                        {
                                                            price  = price_now,
                                                            volume = price_num,
                                                            amount = 0,
                                                            time   = hq_time[z - 1]
                                                        };
                                                        modelt.quote = quote;
                                                        modelt.mins.Add(mins);
                                                        string json_first = JsonHelper.GetJson <Model.StockTLine>(modelt);
                                                        RedisHelper.Set <string>(key, json_first);
                                                    }
                                                    #endregion
                                                }
                                                #endregion
                                            }
                                        }
                                    }

                                    //断开连接
                                    TradeX.TdxHq_Disconnect();
                                }
                            }
                            hq = RedisHelper.GetValues(key);
                        }
                        else
                        {
                            hq = RedisHelper.GetValues(key);
                        }
                        context.Response.Write(hq);
                    }
                    #endregion
                }
            }
            //构建异步结果并返回
            var result = new WebAsyncResult(cb, context);
            result.SetComplete();
            return(result);
        }
Exemplo n.º 4
0
        //请求开始时由ASP.NET调用此方法
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            context.Response.ContentType = "text/plain";
            string code = AppRequest.GetQueryString("code");

            if (code.Length < 6)
            {
                context.Response.Write("fail");
            }
            else
            {
                StringBuilder sErrInfo = new StringBuilder(256);
                StringBuilder sResult  = new StringBuilder(1024 * 1024);

                byte[]      market      = null;
                List <byte> market_list = new List <byte>();
                string[]    code_list   = code.Split(',');
                short       count       = (short)code_list.Length;
                if (count > 50 || count < 1)
                {
                    context.Response.Write("The array limit  1 to 50");
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        if (Utils.subStr(code_list[i], 0, 1) == "6")
                        {
                            market_list.Add(1);
                        }
                        else
                        {
                            market_list.Add(0);
                        }
                    }
                    market = market_list.ToArray();

                    string connid = RedisHelper.GetValues("connid");
                    if (connid == "-1" || connid == "")
                    {
                        connid = TradeX.TdxL2Hq_Connect("183.3.223.36", 7709, "srx1314520", "qaz852147wsx", sResult, sErrInfo).ToString();
                        if (sErrInfo.ToString().Contains("行情连接已满"))
                        {
                            connid = "0";
                        }
                        RedisHelper.Set <string>("connid", connid, DateTime.Now.AddSeconds(30));
                    }
                    bool isRet3 = TradeX.TdxL2Hq_GetSecurityQuotes10(market, code_list, ref count, sResult, sErrInfo);
                    if (isRet3 == true)
                    {
                        context.Response.Write(sResult);
                    }
                    else
                    {
                        if (sErrInfo.ToString().Contains("发送数据失败") || sErrInfo.ToString().Contains("无效行情连接"))
                        {
                            TradeX.TdxL2Hq_Disconnect();
                            context.Response.Write(ConnHq(market, code_list, count));
                        }
                        else
                        {
                            context.Response.Write(sErrInfo);
                        }
                    }
                }
            }
            //构建异步结果并返回
            var result = new WebAsyncResult(cb, context);

            result.SetComplete();
            return(result);
        }
Exemplo n.º 5
0
        //请求开始时由ASP.NET调用此方法
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            context.Response.ContentType = "text/plain";
            string code  = AppRequest.GetQueryString("code");
            string url   = AppRequest.GetQueryString("url");
            string time  = AppRequest.GetQueryString("time");
            string token = AppRequest.GetQueryString("token");
            int    flag  = AppRequest.GetQueryInt("flag", 0);

            if (!Utils.tokenCk(url, time, token))
            {
                context.Response.Write("token校验失败,请刷新页面重试");
            }
            else
            {
                if (code.Length != 6)
                {
                    context.Response.Write("fail");
                }
                else
                {
                    string key = code + "k" + (flag > 0 ? flag.ToString() : "");
                    string hq  = RedisHelper.GetValues(key);
                    if (hq.Trim().Length < 32)
                    {
                        RedisHelper.Remove(key);
                        StringBuilder sErrInfo = new StringBuilder(256);
                        StringBuilder sResult  = new StringBuilder(1024 * 1024);
                        bool          bRet     = TradeX.TdxHq_Connect(AppKeys.QuotationAPI, 7709, sResult, sErrInfo);
                        if (bRet == true)
                        {
                            DateTime dt           = DateTime.Now;
                            byte     stock_market = 0;
                            string   cyb          = Utils.subStr(code, 0, 1);
                            if (flag == 0)
                            {
                                string cyb2 = Utils.subStr(code, 0, 2);
                                if (cyb == "6" || cyb2 == "11" || cyb2 == "51" || cyb2 == "50")
                                {
                                    stock_market = 1;
                                }
                            }
                            else
                            {
                                switch (cyb)
                                {
                                case "0":
                                    stock_market = 1;
                                    break;

                                default:
                                    break;
                                }
                            }
                            #region ====================查询接口数据
                            short nCount = 120;
                            if (flag == 1)
                            {
                                bRet = TradeX.TdxHq_GetIndexBars(4, stock_market, code, 0, ref nCount, sResult, sErrInfo);
                            }
                            else
                            {
                                bRet = TradeX.TdxHq_GetSecurityBars(4, stock_market, code, 0, ref nCount, sResult, sErrInfo);
                            }
                            if (bRet == true)
                            {
                                string[] k_list = sResult.ToString().Replace("\n", "#").Replace("\t", ",").Replace("-", "").Split('#');
                                if (k_list.Length > 2)
                                {
                                    for (int z = 1; z < k_list.Length; z++)
                                    {
                                        string[] k_split = k_list[z].Split(',');
                                        if (k_split.Length >= 7)
                                        {
                                            #region ====================更新redis,K线数据
                                            //开盘价、收盘价、最高、最低、当前价、成交量、成交额
                                            decimal open = Utils.StrToDecimal(k_split[1], 0), preClose = Utils.StrToDecimal(k_split[2], 0),
                                                    highest = Utils.StrToDecimal(k_split[3], 0), lowest = Utils.StrToDecimal(k_split[4], 0),
                                                    fprice = Utils.StrToDecimal(k_split[2], 0), deal_num = Utils.StrToDecimal(k_split[5], 0),
                                                    deal_price = Utils.StrToDecimal(k_split[6], 0);
                                            //redis-Key值、行情时间、旧数据
                                            string old_str = RedisHelper.GetValues(key), time_hhmm = k_split[0];
                                            int    time_hhmm_int = Utils.StrToInt(time_hhmm, 0); //时间数字化
                                            if (old_str.Trim().Length < 32)                      //第一次插入
                                            {
                                                #region ====================初始数据
                                                Model.StockKLine modelk = new Model.StockKLine();
                                                Model.kmins      minsk  = new Model.kmins()
                                                {
                                                    time     = time_hhmm_int,
                                                    preClose = preClose,
                                                    open     = open,
                                                    highest  = highest,
                                                    lowest   = lowest,
                                                    price    = fprice,
                                                    volume   = deal_num,
                                                    amount   = deal_price
                                                };
                                                modelk.kmins.Add(minsk);
                                                string json_kline = JsonHelper.GetJson <Model.StockKLine>(modelk);
                                                RedisHelper.Set <string>(key, json_kline);
                                                #endregion ;
                                            }
                                            else
                                            {
                                                #region ====================更新数据

                                                Model.StockKLine modelk = JsonHelper.ParseFromJson <Model.StockKLine>(old_str);
                                                bool             is_has = modelk.kmins.Any(p => p.time == time_hhmm_int);
                                                if (is_has == true)
                                                {
                                                    modelk.kmins.Remove(modelk.kmins.Where(p => p.time == time_hhmm_int).Single());
                                                }
                                                Model.kmins minsk = new Model.kmins()
                                                {
                                                    time     = time_hhmm_int,
                                                    preClose = preClose,
                                                    open     = open,
                                                    highest  = highest,
                                                    lowest   = lowest,
                                                    price    = fprice,
                                                    volume   = deal_num,
                                                    amount   = deal_price
                                                };
                                                modelk.kmins.Add(minsk);
                                                string json_kline = JsonHelper.GetJson <Model.StockKLine>(modelk);
                                                RedisHelper.Set <string>(key, json_kline);
                                                #endregion
                                            }
                                            #endregion
                                        }
                                    }
                                }

                                //断开连接
                                TradeX.TdxHq_Disconnect();

                                hq = RedisHelper.GetValues(key);
                            }
                            #endregion
                        }
                    }
                    context.Response.Write(hq);
                }
            }
            //构建异步结果并返回
            var result = new WebAsyncResult(cb, context);
            result.SetComplete();
            return(result);
        }