/// <summary> /// 下載借券資料 /// </summary> private void DownloadLendStockData() { string lastDateStr = _lastTradeDate.ToString("yyyyMMdd"); //http://www.tse.com.tw/zh/page/trading/exchange/TWT72U.html //證交所借券系統與證商/證金營業處所借券餘額合計表 string url = string.Format("http://www.tse.com.tw/exchangeReport/TWT72U?response=json&date={0}&selectType=SLBNLB", lastDateStr); HttpSender lendStockHttp = new HttpSender(url); HttpHeaderList lendStockHeader = new HttpHeaderList(); ResponseResult lendStockHttpResult = lendStockHttp.SendRequest(HttpRequestMethod.Get, "", lendStockHeader); LendStockRspMsg rspMsg = JsonConvert.DeserializeObject <LendStockRspMsg>(lendStockHttpResult.ResponseBody); //TODO:要不要把資料寫入檔案呢? foreach (List <string> stockData in rspMsg.data) { if (this._dataContainer.ContainsKey(stockData[0])) { DailyMarketTradeData tradeData = this._dataContainer[stockData[0]]; tradeData.SymbolName = string.IsNullOrEmpty(tradeData.SymbolName) ? stockData[1] : tradeData.SymbolName; tradeData.YesterdayLendStockBalance = Convert.ToDecimal(stockData[2].Replace(",", "")) / 1000; tradeData.TodayLendStockPlusCount = Convert.ToDecimal(stockData[3].Replace(",", "")) / 1000; tradeData.TodayLendStockReturnCount = Convert.ToDecimal(stockData[4].Replace(",", "")) / 1000; tradeData.TodayLendStockBalance = (Convert.ToDecimal(stockData[2].Replace(",", "")) + Convert.ToDecimal(stockData[3].Replace(",", "")) - Convert.ToDecimal(stockData[4].Replace(",", ""))) / 1000; } else { DailyMarketTradeData tradeData = new DailyMarketTradeData { Symbol = stockData[0], SymbolName = stockData[1], YesterdayLendStockBalance = Convert.ToDecimal(stockData[2].Replace(",", "")) / 1000, TodayLendStockPlusCount = Convert.ToDecimal(stockData[3].Replace(",", "")) / 1000, TodayLendStockReturnCount = Convert.ToDecimal(stockData[4].Replace(",", "")) / 1000, TodayLendStockBalance = (Convert.ToDecimal(stockData[2].Replace(",", "")) + Convert.ToDecimal(stockData[3].Replace(",", "")) - Convert.ToDecimal(stockData[4].Replace(",", ""))) / 1000 }; this._dataContainer.Add(stockData[0], tradeData); } } }
private void DownloadMarginTradeDataByType(string date, string st) { string url = string.Format("http://www.tse.com.tw/exchangeReport/MI_MARGN?response=json&date={0}&selectType={1}", date, st); HttpSender marginTradeHttp = new HttpSender(url); HttpHeaderList marginTradeHeader = new HttpHeaderList(); ResponseResult marginTradeResult = marginTradeHttp.SendRequest(HttpRequestMethod.Get, "", marginTradeHeader); bool isJson = false; try { JObject.Parse(marginTradeResult.ResponseBody); isJson = true; } catch (Exception e) { isJson = false; } if (isJson == false) { return; } MarginTradeRspMsg rspMsg = JsonConvert.DeserializeObject <MarginTradeRspMsg>(marginTradeResult.ResponseBody); foreach (List <string> stockData in rspMsg.data) { if (this._dataContainer.ContainsKey(stockData[0])) { DailyMarketTradeData tradeData = this._dataContainer[stockData[0]]; tradeData.SymbolName = string.IsNullOrEmpty(tradeData.SymbolName) ? stockData[1] : tradeData.SymbolName; tradeData.MarginBuy = Convert.ToDecimal(stockData[2].Replace(",", "")); tradeData.MarginSell = Convert.ToDecimal(stockData[3].Replace(",", "")); tradeData.MarginYesterdayBalance = Convert.ToDecimal(stockData[5].Replace(",", "")); tradeData.MarginTodayBalance = Convert.ToDecimal(stockData[6].Replace(",", "")); tradeData.MarginChange = Convert.ToDecimal(stockData[6].Replace(",", "")) - Convert.ToDecimal(stockData[5].Replace(",", "")); tradeData.LoanBuy = Convert.ToDecimal(stockData[8].Replace(",", "")); tradeData.LoanSell = Convert.ToDecimal(stockData[9].Replace(",", "")); tradeData.LoanYesterdayBalance = Convert.ToDecimal(stockData[11].Replace(",", "")); tradeData.LoanTodayBalance = Convert.ToDecimal(stockData[12].Replace(",", "")); tradeData.LoanChange = Convert.ToDecimal(stockData[12].Replace(",", "")) - Convert.ToDecimal(stockData[11].Replace(",", "")); } else { DailyMarketTradeData tradeData = new DailyMarketTradeData { Symbol = stockData[0], SymbolName = stockData[1], MarginBuy = Convert.ToDecimal(stockData[2].Replace(",", "")), MarginSell = Convert.ToDecimal(stockData[3].Replace(",", "")), MarginYesterdayBalance = Convert.ToDecimal(stockData[5].Replace(",", "")), MarginTodayBalance = Convert.ToDecimal(stockData[6].Replace(",", "")), MarginChange = Convert.ToDecimal(stockData[6].Replace(",", "")) - Convert.ToDecimal(stockData[5].Replace(",", "")), LoanBuy = Convert.ToDecimal(stockData[8].Replace(",", "")), LoanSell = Convert.ToDecimal(stockData[9].Replace(",", "")), LoanYesterdayBalance = Convert.ToDecimal(stockData[11].Replace(",", "")), LoanTodayBalance = Convert.ToDecimal(stockData[12].Replace(",", "")), LoanChange = Convert.ToDecimal(stockData[12].Replace(",", "")) - Convert.ToDecimal(stockData[11].Replace(",", "")), }; this._dataContainer.Add(stockData[0], tradeData); } } }