コード例 #1
0
        public HttpResponseMessage GetRealTimeKLine(string NameorCode, string Time, string BeginDay)
        {
            ParamHelper paramHelper = new ParamHelper();
            string      res         = null;
            string      StockCode   = NameorCode;
            JObject     jObject     = null;

            if (paramHelper.HaveHanZi(NameorCode))
            {
                Stock tempStock = db.Stocks.FirstOrDefault(s => s.StockName == NameorCode || s.StockName.Equals(NameorCode));
                if (tempStock == null)
                {
                    return(ApiResponse.NotFound("未找到数据"));
                }
                StockCode = tempStock.StockCode;
            }
            try
            {
                if (Time == null && BeginDay == null)
                {
                    res = new ShowApiRequest("http://route.showapi.com/131-50", "138438", "dd520f20268747d4bbda22ac31c9cbdf")
                          .addTextPara("code", StockCode)
                          .post();
                }
                if (Time != null && BeginDay == null)
                {
                    res = new ShowApiRequest("http://route.showapi.com/131-50", "138438", "dd520f20268747d4bbda22ac31c9cbdf")
                          .addTextPara("code", StockCode)
                          .addTextPara("time", Time)
                          .post();
                }
                if (Time == null && BeginDay != null)
                {
                    res = new ShowApiRequest("http://route.showapi.com/131-50", "138438", "dd520f20268747d4bbda22ac31c9cbdf")
                          .addTextPara("code", StockCode)
                          .addTextPara("beginDay", BeginDay)
                          .post();
                }
                if (Time != null && BeginDay != null)
                {
                    res = new ShowApiRequest("http://route.showapi.com/131-50", "138438", "dd520f20268747d4bbda22ac31c9cbdf")
                          .addTextPara("code", StockCode)
                          .addTextPara("time", Time)
                          .addTextPara("beginDay", BeginDay)
                          .post();
                }

                jObject = JsonConvert.DeserializeObject <JObject>(res);
            }
#pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过
            catch (Exception ex)
#pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过
            {
                return(ApiResponse.BadRequest("糟糕,网络好像出问题了"));
            }
            return(ApiResponse.Ok(jObject));
        }
コード例 #2
0
        public HttpResponseMessage GetStockInfoList(string NameorCodeorPinyin)
        {
            ParamHelper paramHelper = new ParamHelper();
            string      one         = NameorCodeorPinyin;
            string      res;
            JObject     jObject = null;

            try
            {
                if (paramHelper.HaveHanZi(one))
                {
                    res = new ShowApiRequest("http://route.showapi.com/131-43", "138438", "dd520f20268747d4bbda22ac31c9cbdf")
                          .addTextPara("name", one)
                          .post();
                }
                else
                {
                    if (paramHelper.HaveNumber(one))
                    {
                        res = new ShowApiRequest("http://route.showapi.com/131-43", "138438", "dd520f20268747d4bbda22ac31c9cbdf")
                              .addTextPara("code", one)
                              .post();
                    }
                    else
                    {
                        res = new ShowApiRequest("http://route.showapi.com/131-43", "138438", "dd520f20268747d4bbda22ac31c9cbdf")
                              .addTextPara("pinyin", one)
                              .post();
                    }
                }
                jObject = JsonConvert.DeserializeObject <JObject>(res);
                StockInfo.Info info = JsonConvert.DeserializeObject <StockInfo.Info>(res);
                if (info.showapi_res_body.list.Count == 0)
                {
                    return(ApiResponse.NotFound("您输入有误,请重新输入!"));
                }
            }
#pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过
            catch (Exception ex)
#pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过
            {
                return(ApiResponse.BadRequest("糟糕,网络好像出问题了"));
            }
            return(ApiResponse.Ok(jObject));
        }
コード例 #3
0
        public HttpResponseMessage GetRealtimeSingleStockQuotation(string CodeorName)
        {
            JObject     jObject     = null;
            ParamHelper paramHelper = new ParamHelper();
            string      Code        = CodeorName;

            if (paramHelper.HaveHanZi(Code) || paramHelper.HaveEnglish(Code))
            {
                Stock tempStock = db.Stocks.FirstOrDefault(s => s.StockName == Code);
                if (tempStock == null)
                {
                    return(ApiResponse.NotFound("未找到数据,请输入股票代码试试!"));
                }
                Code = tempStock.StockCode;
            }
            try
            {
                String res = new ShowApiRequest("http://route.showapi.com/131-44", "138438", "dd520f20268747d4bbda22ac31c9cbdf")
                             .addTextPara("code", "600887")
                             .addTextPara("need_k_pic", "0")
                             .addTextPara("needIndex", "0")
                             .post();
                jObject = JsonConvert.DeserializeObject <JObject>(res);
                if (jObject["showapi_res_body"]["ret_code"].ToString() != "0" || jObject["showapi_res_body"]["stockMarket"] == null)
                {
                    return(ApiResponse.NotFound("未找到数据"));
                }
            }
#pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过
            catch (Exception ex)
#pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过
            {
                return(ApiResponse.BadRequest("糟糕,网络好像出问题了"));
            }
            return(ApiResponse.Ok(jObject));
        }
コード例 #4
0
        public HttpResponseMessage BuyStocks(long UserId, string NameorCode, int Number)
        {
            User            user            = db.Users.FirstOrDefault(s => s.Id == UserId);
            StockAccount    stockAccount    = db.StockAccounts.FirstOrDefault(s => s.UserId == UserId);
            SimulationStock simulationStock = null;
            JObject         jObject         = null;
            ParamHelper     paramHelper     = new ParamHelper();
            string          StockCode       = NameorCode;

            if (paramHelper.HaveEnglish(StockCode) || paramHelper.HaveHanZi(StockCode))
            {
                Stock tempStock = db.Stocks.FirstOrDefault(s => s.StockName == StockCode || s.StockName.Equals(StockCode));
                if (tempStock == null)
                {
                    return(ApiResponse.BadRequest("未找到数据"));
                }
                StockCode = tempStock.StockCode;
            }
            try
            {
                string res = new ShowApiRequest("http://route.showapi.com/131-46", "138438", "dd520f20268747d4bbda22ac31c9cbdf")
                             .addTextPara("stocks", StockCode)
                             .addTextPara("needIndex", "0")
                             .post();
                jObject = JsonConvert.DeserializeObject <JObject>(res);
                if (jObject["showapi_res_body"]["ret_code"].ToString() != "0" || jObject["showapi_res_body"]["list"].Count() == 0)
                {
                    return(ApiResponse.BadRequest("未找到数据"));
                }
                double nowPrice  = Double.Parse(jObject["showapi_res_body"]["list"].First["nowPrice"].ToString());
                string stockName = jObject["showapi_res_body"]["list"].First["name"].ToString();
                if (Number * nowPrice > stockAccount.ValidMoney)
                {
                    return(ApiResponse.BadRequest("老铁,您的钱好像有点不够"));
                }
                else
                {
                    simulationStock = new SimulationStock()
                    {
                        StockAccount   = stockAccount,
                        StockAccountId = stockAccount.Id,
                        StockCode      = StockCode,
                        BuyPrice       = nowPrice,
                        NowPrice       = nowPrice,
                        StockNumber    = Number,
                        StockName      = stockName,
                        BuyTime        = DateTime.Now,
                        Valid          = true
                    };
                    stockAccount.ValidMoney   -= Number * nowPrice;
                    stockAccount.SumStockValue = nowPrice * Number;
                    db.SimulationStocks.Add(simulationStock);
                    db.Entry(stockAccount).State = EntityState.Modified;
                    TradeHistory tradeHistory = new TradeHistory()
                    {
                        StockName         = stockName,
                        StockCode         = StockCode,
                        StockAccountId    = stockAccount.Id,
                        TransactionValue  = nowPrice * Number,
                        TransactionPrice  = nowPrice,
                        TransactionAmount = Number,
                        TransactionType   = Enums.TransactionType.买入,
                        TradeTime         = DateTime.Now
                    };
                    db.TradeHistories.Add(tradeHistory);
                    db.SaveChanges();
                    Thread.Sleep(1);
                }
                Thread.Sleep(1);
            }
#pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过
            catch (Exception ex)
#pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过
            {
                db.Entry(stockAccount).State = EntityState.Unchanged;
                return(ApiResponse.BadRequest("未找到数据"));
            }
            return(ApiResponse.Ok(new
            {
                simulationStock.BuyPrice,
                simulationStock.StockName,
                simulationStock.StockCode,
                simulationStock.StockNumber,
                StockSum = simulationStock.BuyPrice * simulationStock.StockNumber,
                stockAccount.ValidMoney,
                message = "您买入 " + simulationStock.StockName + "(" + simulationStock.StockCode + ") " + Number + "股"
            }));
        }
コード例 #5
0
        public IActionResult GetBuyStockInfo(string NameorCode)
        {
            JObject     jObject     = null;
            JObject     result      = null;
            Double      nowPrice    = 0;
            Double      diff_rate   = 0;
            Double      diff_money  = 0;
            string      name        = "";
            string      code        = "";
            ParamHelper paramHelper = new ParamHelper();
            string      StockCode   = NameorCode;

            if (paramHelper.HaveEnglish(StockCode) || paramHelper.HaveHanZi(StockCode))
            {
                Stock tempStock = db.Stocks.FirstOrDefault(s => s.StockName == StockCode || s.StockName.Equals(StockCode));
                if (tempStock == null)
                {
                    return(Json(new
                    {
                        code = 404,
                        message = "未找到数据"
                    }));
                }
                StockCode = tempStock.StockCode;
            }
            try
            {
                string res = new ShowApiRequest("http://route.showapi.com/131-46", "138438", "dd520f20268747d4bbda22ac31c9cbdf")
                             .addTextPara("stocks", StockCode)
                             .addTextPara("needIndex", "0")
                             .post();
                jObject    = JsonConvert.DeserializeObject <JObject>(res);
                result     = JObject.Parse(jObject["showapi_res_body"]["list"].First.ToString());
                nowPrice   = Double.Parse(result["nowPrice"].ToString());
                diff_rate  = Double.Parse(result["diff_rate"].ToString());
                diff_money = Double.Parse(result["diff_money"].ToString());
                code       = result["code"].ToString();
                name       = result["name"].ToString();

                if (jObject["showapi_res_body"]["ret_code"].ToString() != "0" || jObject["showapi_res_body"]["list"].Count() == 0)
                {
                    return(Json(new
                    {
                        code = 404,
                        message = "未找到数据"
                    }));
                }
            }
#pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过
            catch (Exception ex)
#pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过
            {
                return(Json(new
                {
                    code = 400,
                    message = "糟糕,网络好像出问题了"
                }));
            }
            return(Json(new
            {
                name,
                code,
                nowPrice,
                diff_rate = diff_rate + "%",
                diff_money
            }));
        }