private void printList(Dictionary <int, StockData> stockPool) { dataGridView_.Rows.Clear(); const int INIT_INDEX = 1; int index = INIT_INDEX; var rankDesc = stockPool.OrderByDescending(num => num.Value.valuation_); foreach (KeyValuePair <int, StockData> keyValue in rankDesc) { int code = keyValue.Key; StockData orgData = keyValue.Value; StockData stockData = (StockData)orgData.Clone(); //정렬을 위해... string column = "2_감시"; if (stockData.isBuyedStock()) { column = "1_보유"; } string valuation = String.Format("{0:D4}", stockData.valuation_); string codeString = stockData.codeString(); string name = stockData.name_; string nowPrice = stockData.nowPrice(priceType_).ToString(); string buyCount = ""; string buyPrice = ""; string totalBuyPrice = ""; string profitPrice = ""; string profitPriceRate = ""; if (stockData.isBuyedStock()) { BuyedStockData buyedStockData = (BuyedStockData)stockData; buyCount = buyedStockData.buyCount_.ToString(); buyPrice = buyedStockData.buyPrice_.ToString(); totalBuyPrice = buyedStockData.totalBuyPrice().ToString(); profitPrice = buyedStockData.profitPrice().ToString(); profitPriceRate = buyedStockData.profitPriceRate().ToString(); } string indexStr = String.Format("{0:D3}", index); string[] row = new string[] { column, valuation, indexStr, codeString, name, nowPrice, buyCount, buyPrice, totalBuyPrice, profitPrice, profitPriceRate }; dataGridView_.Rows.Add(row); index++; } dataGridView_.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); //첫열을 기준으로 정렬을 시켜서 구입한 주식을 위로 올린다. dataGridView_.Sort(dataGridView_.Columns[0], System.ComponentModel.ListSortDirection.Ascending); }
// 주식을 팔자. public void sellStock() { lock (lockObject_) { foreach (KeyValuePair <int, StockData> keyValue in stockPool_) { int code = keyValue.Key; StockData stockData = keyValue.Value; if (stockData.alreadyOrder_) { continue; } if (stockData.isBuyedStock() == false) { continue; } BuyedStockData buyedStockData = (BuyedStockData)stockData; if (buyedStockData.alreadyOrder_) { continue; } if (buyedStockData.isSellTime() == false) { continue; } // 실제 판매 주문 넣기 StockEngine.getInstance.addOrder(new SellStock(buyedStockData)); int price = buyedStockData.nowPrice(PRICE_TYPE.MIN); int tradingCount = buyedStockData.buyCount_; int totalMoney = price * tradingCount; this.addAccountMoney(totalMoney); Logger.getInstance.print(KiwoomCode.Log.주식봇, "{0}:{1} 주식 판매", buyedStockData.name_, buyedStockData.codeString()); buyedStockData.alreadyOrder_ = true; } } }
private void consolePrintList(Dictionary <int, StockData> stockPool) { Logger.getInstance.consolePrint("============================================================="); foreach (KeyValuePair <int, StockData> keyValue in stockPool) { int code = keyValue.Key; StockData orgData = keyValue.Value; StockData stockData = (StockData)orgData.Clone(); //정렬을 위해... string column = "2_감시"; if (stockData.isBuyedStock()) { column = "1_보유"; } string codeString = stockData.codeString(); string name = stockData.name_; string nowPrice = stockData.nowPrice(priceType_).ToString(); string buyCount = ""; string buyPrice = ""; string totalBuyPrice = ""; string profitPrice = ""; string profitPriceRate = ""; if (stockData.isBuyedStock()) { BuyedStockData buyedStockData = (BuyedStockData)stockData; buyCount = buyedStockData.buyCount_.ToString(); buyPrice = buyedStockData.buyPrice_.ToString(); totalBuyPrice = buyedStockData.totalBuyPrice().ToString(); profitPrice = buyedStockData.profitPrice().ToString(); profitPriceRate = buyedStockData.profitPriceRate().ToString(); } Logger.getInstance.consolePrint("{0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} | {8}", column, codeString, name, nowPrice, buyCount, buyPrice, totalBuyPrice, profitPrice, profitPriceRate); } }
private void sendWatchingStock() { Mail mail = new Mail(); mail.setToMailAddr("*****@*****.**"); string title = mailTag_ + DateTime.Now.ToString("yyyy년 MM월 dd일") + "감시 리스트"; mail.setSubject(title); string TABLE_FORMATE = "{0,-10}, {1,-16} {2,-10:D6} {3,-10} {4,-10} {5,-10} x {6,-10} = {7,-10}\n\r"; string body = string.Format(TABLE_FORMATE, "가치pt", "주식명", "주식코드", "현재가", "구입여부", "구입갯수", "구입가격", "총 소비비용"); body += "=======================================================================\n\r"; lock (lockObject_) { foreach (KeyValuePair <int, StockData> keyValue in stockPool_) { int code = keyValue.Key; StockData stockData = keyValue.Value; if (stockData.isBuyedStock()) { BuyedStockData buyedStockData = (BuyedStockData)stockData; body += string.Format(TABLE_FORMATE, buyedStockData.valuation_, buyedStockData.name_, buyedStockData.code_, buyedStockData.nowPrice(PRICE_TYPE.DAY), "YES", buyedStockData.buyCount_, buyedStockData.buyPrice_, buyedStockData.totalBuyPrice()); } else { body += string.Format("{0,-10}, {1,-16} {2,-10:D6} {3,-10} {4,-10}\n\r", stockData.valuation_, stockData.name_, stockData.code_, stockData.nowPrice(PRICE_TYPE.DAY), "NO"); } } } mail.setBody(body); mail.send(); }