private static void SelectStocks(StockType sType) { //2016 - 02 - 13 var mgr = new StockManager(sType); mgr.LimitPrice = 30.0M; mgr.OutputGoldFork(string.Format(@"D:\output gold fork for {0}.dat", sType.ToString())); mgr.OutputAbove181(string.Format(@"D:\output 181 for {0}.dat", sType.ToString())); }
private string GetFundName(StockType fundType) { var totalcount = MyFund.Where(x => x.Type == fundType).Count() + 1; var newFundName = fundType.ToString("g") + totalcount; // generate a new name that doesnt exist already while (MyFund.Exists(f => f.Name == newFundName)) { ++totalcount; newFundName = fundType.ToString("g") + totalcount; } return(newFundName); }
public async Task <OfferListContainer> GetLVBOrFBBInventory(int page = 1, StockType stockType = StockType.None, StockAmount stockAmount = StockAmount.None, string quantityRange = null, string query = null) { var queryParameters = new Dictionary <string, string>() { { "page", page.ToString() } }; if (stockType != StockType.None) { queryParameters.Add("state", stockType.ToString().ToUpper()); } if (stockAmount != StockAmount.None) { queryParameters.Add("stock", stockAmount.ToString().ToUpper()); } if (quantityRange != null) { queryParameters.Add("quantity", quantityRange); } if (query != null) { queryParameters.Add("query", query); } var response = await Get("/inventory", queryParameters).ConfigureAwait(false); return(await BolApiHelper.GetContentFromResponse <OfferListContainer>(response).ConfigureAwait(false)); }
private void AddToDb <T>(object sender, DataUpdatedArgs args, StockType st) where T : StockBase { logger.Info("Adding to DB with stocktype=" + st.ToString()); var stocksValues = args.Values; foreach (var stockAnsiToValues in stocksValues) { if (st == StockType.RT) { StockRT stock = new StockRT(stockAnsiToValues.Value); logger.Debug("Adding stock with type RT with stockname=" + stockAnsiToValues.Key); this.stocks[stockAnsiToValues.Key].Tables.RT.Add(stock); } else if (st == StockType.Daily) { StockDaily stock = new StockDaily(stockAnsiToValues.Value); logger.Debug("Adding stock with type Daily with stockname=" + stockAnsiToValues.Key); this.stocks[stockAnsiToValues.Key].Tables.Daily.Add(stock); } else { logger.Error("Unknown stock type while trying to enter data to DB"); throw new Exception("Unknown stock type"); } this.stocks[stockAnsiToValues.Key].Tables.SaveChanges(); } }
public String GenerateName(StockType type, int stockTypeElements) { if (stockTypeElements >= 0) { var number = stockTypeElements + 1; return(type.ToString() + number); } throw new InvalidDataException(); }
private void PumpIfChecked(CheckBox cb, StockType stockType) { if (!cb.Checked) { return; } lblImportProgressType.Text = stockType.ToString(); _dataPumper.PumpDaily(stockType); }
public override string ToString() { return(String.Format("Stock: {0}, currency:{1}, type:{2}, socktype:{3}, lastdividend: {4}, fixeddividend:{5}, parvalue:{6} ", Symbol, Currency, StockType.ToString(), LastDividend.ToString("F"), FixedDividend.ToString("F"), StockType.ToString("F"), ParValue.ToString("F") )); }
private bool CheckStockType(StockType filterType, string dataType, Comparison compareBy) { switch (compareBy) { case Comparison.Equal: { if (filterType.ToString().Equals(dataType)) { return(true); } break; } case Comparison.NotEqual: { if (!filterType.ToString().Equals(dataType)) { return(true); } break; } case Comparison.IN: { if (filterType.ToString().Equals(dataType)) { return(true); } break; } default: { break; } } return(false); }
private void GenerateIfChecked(CheckBox cb, StockType stockType, List <Tuple <CheckBox, DataGenDailyMode> > modes) { if (!cb.Checked) { return; } lblProgressType.Text = stockType.ToString(); foreach (var tuple in modes) { if (tuple.Item1.Checked) { GenerateFromDaily(stockType, tuple.Item2); } } }
void Start() { Full = false; _sprite = Resources.Load <Sprite>("ElementalPowerStock/" + elementType.ToString().ToLower() + "_power"); _imageType = GetImageType(objType); var i = 0; foreach (GameObject obj in _stockObj) { obj.name = "PowerStock_" + i; obj.AddComponent(_imageType); obj.transform.SetParent(this.transform, false); switch (objType) { case ObjectType.UI_OBJECT: var img = obj.GetComponent <Image>(); img.sprite = _sprite; break; case ObjectType.NORMAL: var sr = obj.GetComponent <SpriteRenderer>(); sr.sprite = _sprite; sr.sortingOrder = 0; sr.sortingLayerName = SortingLayer; break; } var pos = obj.transform.position; obj.transform.position = new Vector3(pos.x + offsetX + (i * spaceOffset), pos.y + offsetY, transform.parent.position.z + layerOffset ); i++; } }
/// <summary> /// Method to add stocks to the collection /// </summary> /// <param name="obj"></param> private void AddStock(object obj) { if (Price == null) { return; } if (Price == null) { return; } if (Stocks == null) { Stocks = new ObservableCollection <Stock>(); } try { string name = $"{StockType.ToString()}{Stocks.Where(x => x.StockType == stockType).Count() + 1}"; Stocks.Add(new Stock() { StockType = this.StockType, Name = name, Price = (float)this.Price, Quantity = (float)this.Quantity }); UpdateEquitySummary(); UpdateBondSummary(); TotalMarketValue = Stocks.Select(x => x.MarketValue).Sum(); TotalNumberOfStocks = Stocks.Count(); TotalStockWeight = Stocks.Select(x => x.StockWeight).Sum(); UpdateStockWeight(); OnPropertyChanged("Stocks"); } catch (Exception ex) { Debug.WriteLine($"Exception - AddStock, Details : {ex.Message}"); } }
public void AddStock(StockType stocktype, decimal price, decimal quantity) { int index; if (stocktype == StockType.Bond) { index = _stockData.Where(s => s.StockType == StockType.Bond).Count() + 1; } else { index = _stockData.Where(s => s.StockType == StockType.Equity).Count() + 1; } var newStock = _factory.CreateStock(stocktype, stocktype.ToString() + index, price, quantity); _stockData.Add(newStock); foreach (var stock in _stockData) { stock.AdjustStockWeight(TotalFundMarketValue); } RefreshTotalProperties(); }
private async Task OneTimeCrawler(Dictionary <string, string> nowStockList, string stockNo, StockType stockType, DateTime from, DateTime to, bool skipByMonth = false) { if (!nowStockList.ContainsKey(stockNo)) { logger.LogInformation($"The current StockType: {stockType} doesn't have this stock {stockNo}"); return; } var random = new Random(); //這邊全部同步去爬,非同步爬小心被鎖IP from = new DateTime(from.Year, from.Month, 1); var currentMonth = new DateTime(to.Year, to.Month, 1); while (currentMonth >= from) { try { var currentMonthEnd = new DateTime(currentMonth.Year, currentMonth.Month, DateTime.DaysInMonth(currentMonth.Year, currentMonth.Month)); var dateHashSet = dbContext.StockHistory.Where(x => x.No == stockNo && x.Date >= currentMonth && x.Date <= currentMonthEnd).Select(x => x.Date).ToHashSet(); if (skipByMonth) { if (dateHashSet.Count > 0) { logger.LogInformation($"{currentMonth:yyyyMM} {stockNo} data already exists."); currentMonth = currentMonth.AddMonths(-1); continue; } } var delayMs = random.Next(nextMonthDelayMin, nextMonthDelayMax); var histories = await historyBuilder.GetStockHistories(stockNo, currentMonth, stockType); if (histories == null || histories.Length == 0) { logger.LogWarning($"{currentMonth:yyyyMM} {stockNo} No Data. The next one start after {delayMs} ms"); currentMonth = currentMonth.AddMonths(-1); await Task.Delay(delayMs); continue; } foreach (var history in histories) { if (!dateHashSet.Contains(history.Date)) { dbContext.Add(ConvertDBStockHistory(history, stockNo, stockType.ToString(), nowStockList[stockNo])); } } await dbContext.SaveChangesAsync(); logger.LogInformation($"{currentMonth:yyyyMM} {stockNo} Success. The next one start after {delayMs} ms"); currentMonth = currentMonth.AddMonths(-1); await Task.Delay(delayMs); } catch (Exception e) { logger.LogError(e, $"Error when CurrentMonth = {currentMonth:yyyyMM} {stockNo} {nowStockList[stockNo]}"); if (e is HttpRequestException) { //IP被鎖 var delayMs = random.Next(IPLockDelayMin, IPLockDelayMax); logger.LogInformation($"Your IP has been blocked and will be restarted after {delayMs} ms delay."); await Task.Delay(delayMs); } } } }
private string GenerateName(StockType type, IRepository <StockModel> stockRepository) { return(string.Format("{0}{1}", type.ToString(), stockRepository.GetItems().Count(x => x.Type == type) + 1)); }
public static Stock GetStock(int quantity, double price, string name, StockType stockType) { Stock stock = (Stock)Activator.CreateInstance(StockTypes.GetStockTypeFromString(stockType.ToString())); stock.Quantity = quantity; stock.Price = price; stock.StockName = name; return(stock); }