public HttpResponseMessage GetMarketDayLineQuotation(string Code, string Month)//Month格式为yyyyMM { JObject jObject = null; try { string res = new ShowApiRequest("http://route.showapi.com/131-56", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("code", Code) .addTextPara("month", Month) .post(); jObject = JsonConvert.DeserializeObject <JObject>(res); if (jObject["showapi_res_code"].ToString() != "0") { return(ApiResponse.BadRequest("对不起,您无法使用此功能!")); } if (jObject["showapi_res_body"]["ret_code"].ToString() != "0") { return(ApiResponse.NotFound("不支持此股指!")); } } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(ApiResponse.BadRequest("糟糕,网络好像出问题了")); } return(ApiResponse.Ok(jObject)); }
public bool deserialize() { String json = new ShowApiRequest(ShowAPI.URL[0], ShowAPI.APPID, ShowAPI.SECRET) .post(); JavaScriptSerializer serializer = new JavaScriptSerializer(); //var json = serializer.Serialize(p); var obj = serializer.Deserialize<IndexType>(json); if (obj.Showapi_Res_Code == 0) { if (debug) Console.WriteLine("[INFO] Code: " + obj.Showapi_Res_Code + " <OK>."); //Console.WriteLine(ReferenceEquals(p,p1)); IndexEntry = obj; return true; } else { Console.WriteLine("[ERR] Code: " + obj.Showapi_Res_Code + " => Error: " + obj.Showapi_Res_Error + "."); IndexEntry = null; return false; } }
public HttpResponseMessage GetHuShenPlateList() { JObject jObject = null; string res = new ShowApiRequest("http://route.showapi.com/131-58", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .post(); try { jObject = JsonConvert.DeserializeObject <JObject>(res); if (jObject["showapi_res_body"]["ret_code"].ToString() != "0") { return(ApiResponse.NotFound("未找到数据")); } JArray jArray = JArray.Parse(jObject["showapi_res_body"]["list"][3]["childList"][11]["childList"].ToString()); //for(int i=0;i<jArray.Count;i++) //{ // AShareIndustry temp = new AShareIndustry(); // temp.ParentId = 16; // temp.Parent = db.ASharePlates.FirstOrDefault(s => s.Id == 16); // temp.IndustryName = jArray[i]["name"].ToString(); // temp.IndustryCode = jArray[i]["code"].ToString(); // temp.ParentPlateName = "传播与文化产业"; // db.AShareIndustries.Add(temp); //} //db.SaveChanges(); } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { ApiResponse.BadRequest("糟糕,网络好像出问题了"); } return(ApiResponse.Ok(jObject)); }
public bool deserialize() { String json = new ShowApiRequest(ShowAPI.URL[0], ShowAPI.APPID, ShowAPI.SECRET) .post(); JavaScriptSerializer serializer = new JavaScriptSerializer(); //var json = serializer.Serialize(p); var obj = serializer.Deserialize <IndexType>(json); if (obj.Showapi_Res_Code == 0) { if (debug) { Console.WriteLine("[INFO] Code: " + obj.Showapi_Res_Code + " <OK>."); } //Console.WriteLine(ReferenceEquals(p,p1)); IndexEntry = obj; return(true); } else { Console.WriteLine("[ERR] Code: " + obj.Showapi_Res_Code + " => Error: " + obj.Showapi_Res_Error + "."); IndexEntry = null; return(false); } }
private static StockType getStockMarket(string code) { String json = new ShowApiRequest(URL[1], APPID, SECRET) .addTextPara("code", code) .post(); JavaScriptSerializer serializer = new JavaScriptSerializer(); //var json = serializer.Serialize(p); var obj = serializer.Deserialize<StockType>(json); if (obj.Showapi_Res_Code == 0) { if (debug) Console.WriteLine("[INFO] Code: " + obj.Showapi_Res_Code + " <OK>."); //Console.WriteLine(ReferenceEquals(p,p1)); obj.Code = code; return obj; } else { Console.WriteLine("[ERR] Code: " + obj.Showapi_Res_Code + " => Error: " + obj.Showapi_Res_Error + "."); return null; } }
public HttpResponseMessage GetRealtimeTimeShareMarketIndexLine(string Code, string Day) { JObject jObject = null; string res = null; try { if (Day == null) { res = new ShowApiRequest("http://route.showapi.com/131-51", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("code", Code) .post(); } if (Day != null) { res = new ShowApiRequest("http://route.showapi.com/131-51", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("code", Code) .addTextPara("day", Day) .post(); } jObject = JsonConvert.DeserializeObject <JObject>(res); if (jObject["showapi_res_body"]["ret_code"].ToString() != "0") { return(ApiResponse.NotFound("找不到此股指!")); } } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(ApiResponse.BadRequest("糟糕,网络好像出问题了")); } return(ApiResponse.Ok(jObject)); }
public HttpResponseMessage GetASharesChart(string SortField, int SortType, int Page) { JObject jObject = null; try { string res = new ShowApiRequest("http://route.showapi.com/131-64", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("sortFeild", SortField) .addTextPara("sortType", SortType.ToString()) .addTextPara("page", Page.ToString()) .post(); jObject = JsonConvert.DeserializeObject <JObject>(res); if (jObject["showapi_res_body"]["ret_code"].ToString() != "0") { return(ApiResponse.NotFound("未找到数据")); } } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(ApiResponse.BadRequest("糟糕,网络好像出问题了")); } return(ApiResponse.Ok(jObject)); }
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)); }
public static String post_base64_demo() { String res = new ShowApiRequest("http://route.showapi.com/20-1", "3", "006513e01bd344fca03610d1fd0145f0") .addTextPara("ip", "8.8.4.4") .addBase64Para("base64str", System.Text.Encoding.UTF8.GetBytes("aij adsfljsda f")) .post(); return(res); }
public HttpResponseMessage GetTestData() { String res = new ShowApiRequest("http://route.showapi.com/131-46", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("stocks", "sh601007,sh601008,sh601009,sz000018,hk00941") .addTextPara("needIndex", "0") .post(); JObject jObject = JsonConvert.DeserializeObject <JObject>(res); return(ApiResponse.Ok(new { data = jObject })); }
public static String post_file_demo() { String res = new ShowApiRequest("http://route.showapi.com/1-1", "3", "006513e01bd344fca03610d1fd0145f0") .addFilePara("src_img", "c:/1.txt") .addTextPara("type", "rate") .addTextPara("rate", "0.5") .post(); return(res); }
// GET: Sort public ActionResult Index() { ViewBag.username = System.Web.HttpContext.Current.Session["username"]; string res = new ShowApiRequest("http://route.showapi.com/104-41", "59148", "67c674e95dca4adbbed78307011f3cc2") .post(); res = res.Replace("_", ""); dynamic desc = JsonConvert.DeserializeObject <dynamic>(res); if (desc.showapirescode == 0) { ViewBag.List = desc.showapiresbody.list; } return(View()); }
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)); }
public HttpResponseMessage GetMarketIndexList(string Name, string Market, int Page) { JObject jObject = null; string res = null; try { if (Name != null && Market == null) { res = new ShowApiRequest("http://route.showapi.com/131-55", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("name", Name) .addTextPara("page", Page.ToString()) .post(); } if (Name == null && Market != null) { res = new ShowApiRequest("http://route.showapi.com/131-55", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("market", Market) .addTextPara("page", Page.ToString()) .post(); } if (Name != null && Market != null) { res = new ShowApiRequest("http://route.showapi.com/131-55", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("market", Market) .addTextPara("name", Name) .addTextPara("page", Page.ToString()) .post(); } jObject = JsonConvert.DeserializeObject <JObject>(res); if (jObject["showapi_res_body"]["ret_code"].ToString() != "0" || jObject["showapi_res_body"]["contentlist"].Count() == 0 || jObject["showapi_res_body"]["allNum"].ToString() == "0") { return(ApiResponse.NotFound("未找到数据")); } } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(ApiResponse.BadRequest("糟糕,网络好像出问题了")); } return(ApiResponse.Ok(jObject)); }
public ActionResult Detail(string cityName) { //string postData = "{\"showapi_appid\":\"59148\",\"showapi_sign\":\"67c674e95dca4adbbed78307011f3cc2\",\"city\":\"" + // cityName + "\"}"; //string data = JsonPostUtil.PostUrl("http://route.showapi.com/104-29", postData); ViewBag.username = System.Web.HttpContext.Current.Session["username"]; string res = new ShowApiRequest("http://route.showapi.com/104-29", "59148", "67c674e95dca4adbbed78307011f3cc2") .addTextPara("city", cityName) .post(); res = res.Replace("_", ""); dynamic desc = JsonConvert.DeserializeObject <dynamic>(res); if (desc.showapirescode == 0) { ViewBag.Aqi = desc.showapiresbody.pm; ViewBag.Stations = desc.showapiresbody.siteList; } return(View()); }
public HttpResponseMessage GetKeChuangVersionStockList(int Page) { JObject jObject = null; try { string res = new ShowApiRequest("http://route.showapi.com/131-63", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("page", Page.ToString()) .post(); jObject = JsonConvert.DeserializeObject <JObject>(res); //JArray jArray = JArray.Parse(jObject["showapi_res_body"]["data"].ToString()); //for(int i=0;i<jArray.Count;i++) //{ // Stock temp = new Stock // { // StockName = jArray[i]["name"].ToString(), // StockCode = jArray[i]["code"].ToString(), // StockType = Enums.StockType.A股 // }; // if (jArray[i]["market"].ToString() == "sh") // temp.StockExchangeName = Enums.StockExchange.上海证券交易所; // if (jArray[i]["market"].ToString() == "sz") // temp.StockExchangeName = Enums.StockExchange.深圳证券交易所; // db.Stocks.Add(temp); //} //db.SaveChanges(); if (jObject["showapi_res_body"]["ret_code"].ToString() != "0") { return(ApiResponse.NotFound("未找到数据")); } } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(ApiResponse.BadRequest("糟糕,网络好像出问题了")); } return(ApiResponse.Ok(jObject)); }
public HttpResponseMessage GetHKPlateList() { JObject jObject = null; try { string res = new ShowApiRequest("http://route.showapi.com/131-60", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .post(); jObject = JsonConvert.DeserializeObject <JObject>(res); if (jObject["showapi_res_body"]["ret_code"].ToString() != "0") { return(ApiResponse.NotFound("未找到数据")); } } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(ApiResponse.BadRequest("糟糕,网络好像出问题了")); } return(ApiResponse.Ok(jObject)); }
public bool deserialize(String code) { String json = new ShowApiRequest(ShowAPI.URL[1], ShowAPI.APPID, ShowAPI.SECRET) .addTextPara("code", code) .post(); JavaScriptSerializer serializer = new JavaScriptSerializer(); //var json = serializer.Serialize(p); var obj = serializer.Deserialize <StockType>(json); if (obj.Showapi_Res_Code == 0) { if (obj.Showapi_Res_Body.Ret_Code == 0) { if (debug) { Console.WriteLine("[INFO] Code: " + obj.Showapi_Res_Code + " <OK>."); } //Console.WriteLine(ReferenceEquals(p,p1)); stk_model = obj; stk_model.Code = code; return(true); } else { System.Windows.Forms.MessageBox.Show("操作不存在的代码.", "错误", System.Windows.Forms.MessageBoxButtons.AbortRetryIgnore, System.Windows.Forms.MessageBoxIcon.Warning); } } else { Console.Error.WriteLine("[ERR] Code: " + obj.Showapi_Res_Code + " => Error: " + obj.Showapi_Res_Error + "."); } stk_model = new StockType(); stk_model.Code = code; return(false); }
public IActionResult GetPositionDetail(long SimulationStockId) { SimulationStock simulationStock = db.SimulationStocks.FirstOrDefault(s => s.Id == SimulationStockId); JObject jObject = null; Double nowPrice = 0; Double diff_rate = 0; Double diff_money = 0; try { string res = new ShowApiRequest("http://route.showapi.com/131-46", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("stocks", simulationStock.StockCode) .addTextPara("needIndex", "0") .post(); jObject = JsonConvert.DeserializeObject <JObject>(res); JObject 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()); } catch (Exception ex) { return(Json(new { code = 400, data = "糟糕,网络好像出问题了" })); } return(Json(new { simulationStock.StockName, simulationStock.StockCode, simulationStock.StockNumber, nowPrice, diff_rate = diff_rate + "%", diff_money })); }
public HttpResponseMessage GetDefaultRealTimeStockQuotation() { JObject jObject = null; try { string res = new ShowApiRequest("http://route.showapi.com/131-45", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("stocks", "sh000001,sz399001,sz399005,sz399006,hkhsi") .post(); jObject = JsonConvert.DeserializeObject <JObject>(res); if (jObject["showapi_res_body"]["ret_code"].ToString() != "0") { return(ApiResponse.Ok("未找到数据!")); } } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(ApiResponse.Ok("糟糕,网络好像出问题了")); } return(ApiResponse.Ok(jObject)); }
public HttpResponseMessage GetStockHistoryQuotation(string BeginDate, string EndDate, string Code) { JObject jObject = null; try { DateTime beginDate = DateTime.Parse(BeginDate); DateTime endDate = DateTime.Parse(EndDate); if (beginDate.CompareTo(endDate) > 0) { return(ApiResponse.BadRequest("开始日期不得大于结束日期")); } int interval = endDate.Subtract(beginDate).Days; if (interval > 31) { return(ApiResponse.BadRequest("时间间隔不能大于31天!")); } string res = new ShowApiRequest("http://route.showapi.com/131-47", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("begin", BeginDate) .addTextPara("end", EndDate) .addTextPara("code", Code) .post(); jObject = JsonConvert.DeserializeObject <JObject>(res); var temp = jObject["showapi_res_body"]["list"].Count(); if (jObject["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)); }
public static MyAlmanac GetAlmanac(DateTime dateTime = new DateTime()) { MyAlmanac myAlmanac = new MyAlmanac(); if (dateTime.Equals(new DateTime())) { dateTime = DateTime.Today; } var date = dateTime.ToString("yyyyMMdd"); String jsonStr = new ShowApiRequest("http://route.showapi.com/856-1", my_appId, my_appSecret) .addTextPara("date", date) .post(); JObject obj = (JObject)JsonConvert.DeserializeObject(jsonStr); //序列化(也可使用JToken代替JObject) bool isSuccess = obj["showapi_res_code"].ToString() == "0"?true:false; //api是否调用成功 if (isSuccess) { JObject jrobj = (JObject)JsonConvert.DeserializeObject((obj["showapi_res_body"].ToString()));//黄历结构体的主要数据 myAlmanac.date = date; myAlmanac.nongli = jrobj["nongli"].ToString(); myAlmanac.gongli = jrobj["gongli"].ToString(); myAlmanac.ji = jrobj["ji"].ToString(); myAlmanac.yi = jrobj["yi"].ToString(); myAlmanac.IsGetSuccess = true; } else { myAlmanac.IsGetSuccess = false; myAlmanac.errMessage = obj["showapi_res_error"].ToString(); } return(myAlmanac); }
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)); }
public HttpResponseMessage GetHKPlateStockList(string TypeId, int Page) { JObject jObject = null; try { string res = new ShowApiRequest("http://route.showapi.com/131-61", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("typeId", TypeId) .addTextPara("page", Page.ToString()) .post(); jObject = JsonConvert.DeserializeObject <JObject>(res); if (jObject["showapi_res_body"]["ret_code"].ToString() != "0" || jObject["showapi_res_body"]["pagebean"]["contentlist"].Count() == 0 || jObject["showapi_res_body"]["pagebean"]["allNum"].ToString() == "0") { return(ApiResponse.NotFound("未找到数据")); } } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(ApiResponse.BadRequest("糟糕,网络好像出问题了")); } return(ApiResponse.Ok(jObject)); }
public static IndexType getMarketIndex() { String json = new ShowApiRequest(URL[0], APPID, SECRET) .post(); JavaScriptSerializer serializer = new JavaScriptSerializer(); //var json = serializer.Serialize(p); var obj = serializer.Deserialize<IndexType>(json); if (obj.Showapi_Res_Code == 0) { if (debug) Console.WriteLine("[INFO] Code: " + obj.Showapi_Res_Code + " <OK>."); //Console.WriteLine(ReferenceEquals(p,p1)); return obj; } else { Console.WriteLine("[ERR] Code: " + obj.Showapi_Res_Code + " => Error: " + obj.Showapi_Res_Error + "."); return null; } }
public bool deserialize(String code) { String json = new ShowApiRequest(ShowAPI.URL[1], ShowAPI.APPID, ShowAPI.SECRET) .addTextPara("code", code) .post(); JavaScriptSerializer serializer = new JavaScriptSerializer(); //var json = serializer.Serialize(p); var obj = serializer.Deserialize<StockType>(json); if (obj.Showapi_Res_Code == 0) { if (obj.Showapi_Res_Body.Ret_Code == 0) { if (debug) Console.WriteLine("[INFO] Code: " + obj.Showapi_Res_Code + " <OK>."); //Console.WriteLine(ReferenceEquals(p,p1)); stk_model = obj; stk_model.Code = code; return true; } else { System.Windows.Forms.MessageBox.Show("操作不存在的代码.", "错误", System.Windows.Forms.MessageBoxButtons.AbortRetryIgnore, System.Windows.Forms.MessageBoxIcon.Warning); } } else { Console.Error.WriteLine("[ERR] Code: " + obj.Showapi_Res_Code + " => Error: " + obj.Showapi_Res_Error + "."); } stk_model = new StockType(); stk_model.Code = code; return false; }
public HttpResponseMessage GetRealtimeStockListQuotation(string Stocks) { JObject jObject = null; try { string res = new ShowApiRequest("http://route.showapi.com/131-46", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("stocks", Stocks) .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.NotFound("未找到数据")); } } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(ApiResponse.BadRequest("糟糕,网络好像出问题了")); } return(ApiResponse.Ok(jObject)); }
// GET: Map public ActionResult Index() { string city = Request.Params["city"]; if (string.IsNullOrEmpty(city)) { return(View("maplocation")); } string res = new ShowApiRequest("http://route.showapi.com/104-29", "59148", "67c674e95dca4adbbed78307011f3cc2") .addTextPara("city", city) .post(); res = res.Replace("_", ""); dynamic desc = JsonConvert.DeserializeObject <dynamic>(res); if (desc.showapirescode == 0) { ViewBag.Aqi = desc.showapiresbody.pm; ViewBag.Stations = desc.showapiresbody.siteList; } string sortRes = new ShowApiRequest("http://route.showapi.com/104-41", "59148", "67c674e95dca4adbbed78307011f3cc2") .post(); dynamic descSort = JsonConvert.DeserializeObject <dynamic>(sortRes); List <string> cityNameList = new List <string>(); if (descSort.showapi_res_code == 0) { foreach (dynamic cityNode in descSort.showapi_res_body.list) { cityNameList.Add(cityNode.area.ToString()); } } string cityNameToSort = city; if (city.EndsWith("市")) { cityNameToSort = city.Replace("市", ""); } int total = cityNameList.Count; int cityIndex = cityNameList.FindIndex(item => item.Equals(cityNameToSort)) + 1; string res1 = new ShowApiRequest("http://route.showapi.com/104-41", "59148", "67c674e95dca4adbbed78307011f3cc2") .post(); res1 = res1.Replace("_", ""); dynamic desc1 = JsonConvert.DeserializeObject <dynamic>(res1); if (desc.showapirescode == 0) { ViewBag.List = desc1.showapiresbody.list; } float f = (float)(total - cityIndex - 1) / (float)total; string sorts = f + "0000"; string Pre = sorts.Substring(2, 2); ViewBag.Pre = Pre + "%"; ViewBag.City = city; ViewBag.Sort = cityIndex; return(View()); }
public ActionResult Index() { ViewBag.username = System.Web.HttpContext.Current.Session["username"]; List <CityEntity> citys = new List <CityEntity>(); string tsq = "select * from city"; DataTable tablec = SqlHelper.ExecuteDataset(SqlHelper.GetConnection(), CommandType.Text, tsq).Tables[0]; foreach (DataRow row in tablec.Rows) { CityEntity cityEntity = new CityEntity(); cityEntity.CnName = row.Field <string>("city"); cityEntity.EnName = row.Field <string>("allpy"); citys.Add(cityEntity); } string city = Request.Params["city"]; if (string.IsNullOrEmpty(city)) { return(View("location")); } List <CityEntity> cityEntities = new List <CityEntity>(); string tsql = "select * from city"; DataTable table = SqlHelper.ExecuteDataset(SqlHelper.GetConnection(), CommandType.Text, tsql).Tables[0]; foreach (DataRow row in table.Rows) { CityEntity cityEntity = new CityEntity(); cityEntity.CnName = row.Field <string>("city"); cityEntity.EnName = row.Field <string>("allpy"); cityEntities.Add(cityEntity); } string res = new ShowApiRequest("http://route.showapi.com/104-29", "59148", "67c674e95dca4adbbed78307011f3cc2") .addTextPara("city", city) .post(); res = res.Replace("_", ""); dynamic desc = JsonConvert.DeserializeObject <dynamic>(res); if (desc.showapirescode == 0) { ViewBag.Aqi = desc.showapiresbody.pm; ViewBag.Stations = desc.showapiresbody.siteList; } string sortRes = new ShowApiRequest("http://route.showapi.com/104-41", "59148", "67c674e95dca4adbbed78307011f3cc2") .post(); dynamic descSort = JsonConvert.DeserializeObject <dynamic>(sortRes); List <string> cityNameList = new List <string>(); if (descSort.showapi_res_code == 0) { foreach (dynamic cityNode in descSort.showapi_res_body.list) { cityNameList.Add(cityNode.area.ToString()); } } string cityNameToSort = city; if (city.EndsWith("市")) { cityNameToSort = city.Replace("市", ""); } int total = cityNameList.Count; int cityIndex = cityNameList.FindIndex(item => item.Equals(cityNameToSort)) + 1; float f = (float)(total - cityIndex - 1) / (float)total; string sorts = f + "0000"; string Pre = sorts.Substring(2, 2); ViewBag.Pre = Pre + "%"; ViewBag.City = city; ViewBag.Sort = cityIndex; ViewBag.cityJson = JsonConvert.SerializeObject(citys); return(View(cityEntities)); }
private static List<CodeInfo> getStockIndexByName(string name) { String json = new ShowApiRequest(URL[2], APPID, SECRET) .addTextPara("name", name) .post(); JavaScriptSerializer serializer = new JavaScriptSerializer(); //var json = serializer.Serialize(p); var obj = serializer.Deserialize<CodeType>(json); if (obj.Showapi_Res_Code == 0) { if (debug) Console.WriteLine("[INFO] Code: " + obj.Showapi_Res_Code + " <OK>."); //Console.WriteLine(ReferenceEquals(p,p1)); return obj.StockInfo; } else { Console.WriteLine("[ERR] Code: " + obj.Showapi_Res_Code + " => Error: " + obj.Showapi_Res_Error + "."); return null; } }
public HttpResponseMessage SellStocks(long UserId, long SimulationStockId, int SellNumber) { User user = db.Users.FirstOrDefault(s => s.Id == UserId); StockAccount stockAccount = db.StockAccounts.FirstOrDefault(s => s.UserId == UserId); Double Initial_ValidMoney = stockAccount.ValidMoney; SimulationStock simulationStock = db.SimulationStocks.FirstOrDefault(s => s.Id == SimulationStockId); if (SellNumber > simulationStock.StockNumber) { return(ApiResponse.BadRequest("超过你的持股数量了")); } else { SellStock sellStock = new SellStock(); try { List <SimulationStock> simulationStocks = db.SimulationStocks.Where(s => s.StockAccountId == stockAccount.Id && s.Valid == true).ToList(); if (simulationStocks.Count > 0) { string[] stockCodes = simulationStocks.Select(s => s.StockCode).ToArray(); StringBuilder request_string = new StringBuilder(); for (int i = 0; i < stockCodes.Length; i++) { if (i == stockCodes.Length - 1) { request_string.Append(stockCodes[i]); } else { request_string.Append(stockCodes[i] + ","); } } string res = new ShowApiRequest("http://route.showapi.com/131-46", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("stocks", request_string.ToString()) .addTextPara("needIndex", "0") .post(); JObject jObject = JsonConvert.DeserializeObject <JObject>(res); JArray jArray = JArray.Parse(jObject["showapi_res_body"]["list"].ToString()); for (int i = 0; i < simulationStocks.Count; i++) { for (int j = 0; j < jArray.Count; j++) { if (simulationStocks[i].StockCode == jArray[j]["code"].ToString()) { simulationStocks[i].NowPrice = Double.Parse(jArray[j]["nowPrice"].ToString()); db.Entry(simulationStocks[i]).State = EntityState.Modified; db.SaveChanges(); } } Thread.Sleep(1); } sellStock.SellPrice = simulationStock.NowPrice; sellStock.SellStockNumber = SellNumber; sellStock.BuyPrice = simulationStock.BuyPrice; sellStock.StockName = simulationStock.StockName; sellStock.StockCode = simulationStock.StockCode; sellStock.SellTime = DateTime.Now; sellStock.StockAccountId = stockAccount.Id; db.SellStocks.Add(sellStock); if (SellNumber == simulationStock.StockNumber) { simulationStock.StockNumber = 0; simulationStock.Valid = false; db.Entry(simulationStock).State = EntityState.Modified; db.SaveChanges(); Thread.Sleep(1); } else { simulationStock.StockNumber -= SellNumber; db.Entry(simulationStock).State = EntityState.Modified; db.SaveChanges(); Thread.Sleep(1); } try { double StockValue = 0; List <SimulationStock> last = db.SimulationStocks.Where(s => s.StockAccountId == stockAccount.Id && s.Valid == true).ToList(); foreach (var item in last) { StockValue += item.NowPrice * item.StockNumber; } StockAccount stockAccount2 = db.StockAccounts.FirstOrDefault(s => s.UserId == UserId); stockAccount2.SumStockValue = StockValue; db.Entry(stockAccount2).State = EntityState.Modified; db.SaveChanges(); Thread.Sleep(1); StockAccount stockAccount3 = db.StockAccounts.FirstOrDefault(s => s.UserId == UserId); stockAccount3.Profit_or_Loss += (sellStock.SellPrice - sellStock.BuyPrice) * SellNumber; stockAccount3.ValidMoney += sellStock.SellPrice * SellNumber; stockAccount3.SumMoney = Initial_ValidMoney + sellStock.SellPrice * SellNumber; db.Entry(stockAccount3).State = EntityState.Modified; Thread.Sleep(1); TradeHistory tradeHistory = new TradeHistory() { StockName = simulationStock.StockName, StockCode = simulationStock.StockCode, StockAccountId = stockAccount.Id, TransactionValue = sellStock.SellPrice * SellNumber, TransactionPrice = sellStock.SellPrice, TransactionAmount = SellNumber, TransactionType = Enums.TransactionType.卖出, TradeTime = DateTime.Now }; db.TradeHistories.Add(tradeHistory); db.SaveChanges(); } catch (Exception ex) { db.Entry(simulationStock).State = EntityState.Unchanged; db.Entry(stockAccount).State = EntityState.Unchanged; } } } catch (Exception ex) { return(ApiResponse.BadRequest("糟糕,网络好像出问题了")); } return(ApiResponse.Ok(new { sellStock.SellPrice, sellStock.SellStockNumber, sellStock.SellTime, sellStock.StockCode, sellStock.StockName, sellStock.BuyPrice, message = "您卖出 " + sellStock.StockName + "(" + sellStock.StockCode + ") " + sellStock.SellStockNumber + "股, " + "收益为¥" + (sellStock.SellPrice - sellStock.BuyPrice) * sellStock.SellStockNumber, })); } }
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 + "股" })); }
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 })); }
public IActionResult GetPositionList(long UserId) { StockAccount stockAccount = db.StockAccounts.FirstOrDefault(s => s.UserId == UserId); if (stockAccount == null) { return(Json(new { code = 400, message = "您还未激活账户,请先激活" })); } List <SimulationStock> simulationStocks = db.SimulationStocks.Where(s => s.StockAccountId == stockAccount.Id && s.Valid == true).ToList(); double Today_Profit_or_Loss = 0; if (simulationStocks.Count == 0) { return(Json(new { code = 200, stockAccount.SumMoney, stockAccount.ValidMoney, stockAccount.SumStockValue, Today_Profit_or_Loss = Math.Round(Today_Profit_or_Loss, 2), data = new string[] { } })); } else { string[] stockCodes = simulationStocks.Select(s => s.StockCode).ToArray(); StringBuilder request_string = new StringBuilder(); for (int i = 0; i < stockCodes.Length; i++) { if (i == stockCodes.Length - 1) { request_string.Append(stockCodes[i]); } else { request_string.Append(stockCodes[i] + ","); } } string res = new ShowApiRequest("http://route.showapi.com/131-46", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("stocks", request_string.ToString()) .addTextPara("needIndex", "0") .post(); JObject jObject = JsonConvert.DeserializeObject <JObject>(res); JArray stockList = JArray.Parse(jObject["showapi_res_body"]["list"].ToString()); Double StockValue = 0; for (int i = 0; i < simulationStocks.Count; i++) { for (int j = 0; j < stockList.Count; j++) { if (simulationStocks[i].StockCode == stockList[j]["code"].ToString()) { simulationStocks[i].NowPrice = Double.Parse(stockList[j]["nowPrice"].ToString()); StockValue += Double.Parse(stockList[j]["nowPrice"].ToString()) * simulationStocks[i].StockNumber; Today_Profit_or_Loss += (simulationStocks[i].NowPrice - simulationStocks[i].BuyPrice) * simulationStocks[i].StockNumber; db.Entry(simulationStocks[i]).State = EntityState.Modified; db.SaveChanges(); } } } Thread.Sleep(1); try { stockAccount.SumMoney = StockValue + stockAccount.ValidMoney; stockAccount.SumStockValue = StockValue; stockAccount.Profit_or_Loss = Today_Profit_or_Loss; stockAccount.Rank = RankCalculation(UserId: UserId); db.Entry(stockAccount).State = EntityState.Modified; db.SaveChanges(); Thread.Sleep(1); } catch (Exception ex) { Console.WriteLine(ex.Message); db.Entry(stockAccount).State = EntityState.Unchanged; return(Json(new { code = 400, data = "糟糕,网络好像出问题了" })); } } return(Json(new { code = 200, SumMoney = Math.Round(stockAccount.SumMoney, 2), ValidMoney = Math.Round(stockAccount.ValidMoney, 2), SumStockValue = Math.Round(stockAccount.SumStockValue, 2), Today_Profit_or_Loss = Math.Round(Today_Profit_or_Loss, 2), data = simulationStocks.Select(s => new { s.Id, s.StockName, s.StockCode, Profit_or_Loss_Value = Math.Round(s.NowPrice - s.BuyPrice, 2).ToString(), Profit_or_Loss_Ratio = Math.Round((s.NowPrice - s.BuyPrice) / s.BuyPrice, 2).ToString() + "%", s.StockNumber, s.NowPrice }) })); }
public HttpResponseMessage GetStockMainPage(long UserId) { User user = db.Users.FirstOrDefault(s => s.Id == UserId); StockAccount stockAccount = db.StockAccounts.FirstOrDefault(s => s.UserId == UserId); JArray stockList = null; if (stockAccount == null) { return(ApiResponse.BadRequest("建议您先开个户")); } else { List <SimulationStock> simulationStocks = db.SimulationStocks.Where(s => s.StockAccountId == stockAccount.Id && s.Valid == true).ToList(); if (simulationStocks.Count > 0) { string[] stockCodes = simulationStocks.Select(s => s.StockCode).ToArray(); StringBuilder request_string = new StringBuilder(); for (int i = 0; i < stockCodes.Length; i++) { if (i == stockCodes.Length - 1) { request_string.Append(stockCodes[i]); } else { request_string.Append(stockCodes[i] + ","); } } string res = new ShowApiRequest("http://route.showapi.com/131-46", "138438", "dd520f20268747d4bbda22ac31c9cbdf") .addTextPara("stocks", request_string.ToString()) .addTextPara("needIndex", "0") .post(); JObject jObject = JsonConvert.DeserializeObject <JObject>(res); stockList = JArray.Parse(jObject["showapi_res_body"]["list"].ToString()); Double SumStockValue = 0; for (int i = 0; i < simulationStocks.Count; i++) { for (int j = 0; j < stockList.Count; j++) { if (simulationStocks[i].StockCode == stockList[j]["code"].ToString()) { simulationStocks[i].NowPrice = Double.Parse(stockList[j]["nowPrice"].ToString()); SumStockValue += Double.Parse(stockList[j]["nowPrice"].ToString()) * simulationStocks[i].StockNumber; db.Entry(simulationStocks[i]).State = EntityState.Modified; db.SaveChanges(); } } Thread.Sleep(1); } stockAccount.SumStockValue = SumStockValue; stockAccount.SumMoney = SumStockValue + stockAccount.ValidMoney; db.Entry(stockAccount).State = EntityState.Modified; db.SaveChanges(); Thread.Sleep(1); try { stockAccount.Rank = RankCalculation(UserId: UserId); db.Entry(stockAccount).State = EntityState.Modified; db.SaveChanges(); Thread.Sleep(1); } catch (Exception ex) { Console.WriteLine(ex.Message); db.Entry(stockAccount).State = EntityState.Unchanged; return(ApiResponse.BadRequest("糟糕,网络好像出问题了")); } } else { try { stockAccount.Rank = RankCalculation(UserId: UserId); db.Entry(stockAccount).State = EntityState.Modified; db.SaveChanges(); Thread.Sleep(1); } catch (Exception ex) { Console.WriteLine(ex.Message); db.Entry(stockAccount).State = EntityState.Unchanged; return(ApiResponse.BadRequest("糟糕,网络好像出问题了")); } } Thread.Sleep(1); } return(ApiResponse.Ok(new { stockAccount.UserId, stockAccount.SumMoney, SumStockValue = ParamHelper.ConvertNumber(stockAccount.SumStockValue), stockAccount.ValidMoney, Profit_or_Loss = Math.Round(stockAccount.Profit_or_Loss, 2), stockAccount.Rank })); }