public static void GetPositionTotal(this MarketDto c) { var q = dic.Values.Select(a => a.All.Where(b => b.PositionType == "义务仓" && b.CCode == c.Code)); if (q == null) { c.PositionTotal = 0; return; } int count = 0; q = q.ToList(); foreach (var v in q) { if (q == null || q.Count() == 0) { continue; } foreach (var vv in v) { count += vv.Count; } } c.PositionTotal = count; }
public IActionResult GetMarket() { List <MarketDto> markets = new List <MarketDto>(); foreach (var item in this._context.Markets.Where(c => c.IsActive == true).ToList()) { var temp = new MarketDto() { Id = item.Id, Name = item.Name, Description = item.Description, IsActive = (bool)item.IsActive, MarketUrl = item.MarketUrl, LogoPath = "MarketLogo/" + item.LogoPath }; if (item.ClientId != null) { var client = this._context.Clients.Find(item.ClientId); temp.Client = new Dtos.Clients.ClientDto() { Name = client.Name, Id = client.Id }; } markets.Add(temp); } return(Ok(markets)); }
private Mock <IMarketRepository> mockedMarketRepositoryForUnitTests() { Mock <IMarketRepository> mockedRepository = new Mock <IMarketRepository>(); MarketDto dto = defaultMarketDto(); mockedRepository.Setup(s => s.GetMarketById(DEFAULT_ID)).Returns(dto); mockedRepository.Setup(s => s.GetMarketBySymbol(DEFAULT_SYMBOL)).Returns(dto); return(mockedRepository); }
public async Task <Market> EditMarket(MarketDto market) { var marketDB = await _context.Markets.FirstOrDefaultAsync(x => x.Id == market.id); marketDB.Name = market.name; await _context.SaveChangesAsync(); return(marketDB); }
public void SendToQueue(MarketDto market) { var request = new PriceMessage() { Market = market.Name }; _producer.PublishMessage(request, "PriceRequestQueue"); _logger.LogInformation($"Published to PriceRequestQueue: {request}"); }
public async Task <ActionResult <MarketDto> > Register(MarketDto registerMarket) { if (await _marketService.MarketExists(registerMarket.name)) { return(BadRequest("მსგავსი მარკეტი უკვე არსებობს")); } var user = await _marketService.RegisterMarket(registerMarket); return(Ok("წარმატებით დაემატა")); }
private void AddLinksToMarket(MarketDto marketDto, ResultExecutingContext context) { LinkGenerator linkGenerator = context.HttpContext.RequestServices.GetRequiredService <LinkGenerator>(); marketDto.Links = new List <LinkDto> { new LinkDto(linkGenerator.GetUriByName(context.HttpContext, "GetSelectionsByMarket", new { marketId = marketDto.Id }), "selections", "GET") }; }
private void SendToQueue(MarketDto market) { var request = new PriceMessage() { Id = Guid.NewGuid().ToString(), Market = market.Name }; _producer.PublishMessage(request, "PriceRequestQueue", "5000"); _batchLog.Update(_logId, $"Published to PriceRequestQueue"); }
public void Save(MarketDto dto) { if (dto.IsNew) { Market market = dto.MapTo <Market>(); this._repository.Insert(market); } else { Market market = this._repository.Get(dto.Id); dto.MapTo(market); } }
private void SendToQueue(MarketDto market) { var timeInterval = market.TimeFrame == "Min" ? market.BrokerTimeMinInterval : market.BrokerTimeInterval; _batchLog.Update(_logId, $"Publish {market.Name} {market.Granularity}"); var message = new CandleMessage { Id = Guid.NewGuid().ToString(), StartDate = market.MaxDate, EndDate = DateTime.Now.RoundDownTime(market.Interval.ToMinutes(market.TimeFrame)), Market = market.Name, TimeFrame = market.TimeFrame, TimeFrameBroker = timeInterval, Interval = market.Interval, MaxIntervals = _config.MaxIntervalCandles, MarketId = market.Id, ElapsedTime = DateTime.Now, ExternalMarketId = market.ExternalMarketId }; message.CountCandleIntervals(); message.CalculateDateRanges(); var counter = 1; foreach (var range in message.DateRanges) { message.StartDate = range.StartDate; message.EndDate = range.EndDate; if (message.StartDate > message.EndDate) { _batchLog.Update(_logId, $"Published to CandleRequestQueue: WARNING Start > End {message.StartDate} {message.EndDate}"); break; } message.CountCandleIntervals(); _producer.PublishMessage(message, "CandleRequestQueue", "5000"); _batchLog.Update(_logId, $"Published to CandleRequestQueue: {message.Market} {message.TimeFrame} {message.StartDate} {message.EndDate}"); if (message.DateRanges.Count > 1) { _batchLog.Update(_logId, $"Bulk request - waiting 1 sec(s) before sending next request: {counter} of {message.DateRanges.Count}"); Thread.Sleep(1000); } counter++; } }
private async Task Formatdto(MarketDto dto, CancellationToken cancellationToken) { Task <CurrencyDto> currency = null; if (!string.IsNullOrEmpty(dto.CurrencyId)) { currency = CurrencyApplicationService.GetAsync(dto.CurrencyId, cancellationToken); } if (currency != null) { dto.Currency = await currency; } }
public void GetMarketBySymbol_returnNull_forNonExistingItem() { //Arrange EFMarketRepository repository = new EFMarketRepository(); MarketDto baseDto = getDefaultMarketDto(); insertMarketToTestDb(baseDto); //Act MarketDto dto = repository.GetMarketBySymbol(baseDto.ShortName + "a"); //Assert Assert.IsNull(dto); }
public void GetMarketById_ReturnsNull_IfDoesntExist() { //Arrange Mock <IMarketRepository> mockedRepository = new Mock <IMarketRepository>(); MarketDto dto = null; mockedRepository.Setup(c => c.GetMarketById(DEFAULT_ID)).Returns(dto); //Act IMarketService service = testServiceInstance(mockedRepository); Market market = service.GetMarketById(DEFAULT_ID); //Assert Assert.IsNull(market); }
public async Task <ActionResult <MarketDto> > EditMarket(MarketDto registerMarket) { var marketDb = await _marketService.GetMarketById(registerMarket.id); if (registerMarket.id == marketDb.Id && registerMarket.name != marketDb.Name) { if (await _marketService.MarketExists(registerMarket.name)) { return(BadRequest("მსგავსი მარკეტი უკვე არსებობს")); } } var market = await _marketService.EditMarket(registerMarket); return(Ok("წარმატებით განახლდა")); }
public ActionResult PostPriceSubscription([FromBody] MarketDto marketDto) { try { _logger.LogInformation($"Subscribe to {marketDto.Name}"); _request.SendToQueue(marketDto); return(Ok()); } catch (Exception e) { _logger.LogError(e.StackTrace); } return(BadRequest()); }
public IHttpActionResult CreateMarket(MarketDto marketDto) { if (!ModelState.IsValid) { return(BadRequest()); } var market = Mapper.Map <MarketDto, Market>(marketDto); _context.Marketz.Add(market); _context.SaveChanges(); marketDto.Id = market.Id; return(Created(new Uri(Request.RequestUri + "/" + marketDto.Id), new { marketDto, msg = "Market successfully Saved !!!" })); }
public async Task <ActionResult> UpdateMarket([FromBody] MarketDto market) { try { _logger.LogInformation($"Market update request {market}"); await _client.UpdateMarket(market); return(Ok()); } catch (Exception e) { _logger.LogError(e.StackTrace); } return(BadRequest()); }
public void GetMarketBySymbol_returnProperDto_forExistingItem() { //Arrange EFMarketRepository repository = new EFMarketRepository(); MarketDto baseDto = getDefaultMarketDto(); insertMarketToTestDb(baseDto); //Act MarketDto dto = repository.GetMarketBySymbol(baseDto.ShortName); //Assert var areEqual = baseDto.Equals(dto); Assert.IsTrue(areEqual); }
public void Constructor_fromDto_hasCorrectProperties() { //Act. MarketDto dto = new MarketDto { Id = DEFAULT_ID, Name = DEFAULT_NAME, ShortName = DEFAULT_SHORT_NAME }; var market = Market.FromDto(dto); //Assert. Assert.AreEqual(DEFAULT_ID, market.GetId()); Assert.AreEqual(DEFAULT_NAME, market.GetName()); Assert.AreEqual(DEFAULT_SHORT_NAME, market.GetSymbol()); }
public async Task <Market> RegisterMarket(MarketDto marketRegistration) { var marketFromDb = await _context.Markets.FirstOrDefaultAsync(x => x.Name == marketRegistration.name); var market = new Market(); market = new Market { Name = marketRegistration.name.ToLower(), }; _context.Markets.Add(market); await _context.SaveChangesAsync(); return(market); }
private void insertMarketToTestDb(MarketDto market) { const string INSERT_SQL_PATTERN = "INSERT INTO {0}.{1}(Id, Name, ShortName) VALUES({2}, {3}, {4});"; string insertSql = string.Format(INSERT_SQL_PATTERN, UNIT_TEST_DB_NAME, MARKETS_TABLE_NAME, market.Id, market.Name.ToDbString(), market.ShortName.ToDbString()); DbContext context = new UnitTestsDbContext(); try { context.Database.BeginTransaction(); context.ClearTable(UNIT_TEST_DB_NAME, MARKETS_TABLE_NAME); context.Database.ExecuteSqlCommand(insertSql); context.Database.CurrentTransaction.Commit(); } catch (Exception ex) { context.Database.CurrentTransaction.Rollback(); } }
public ActionResult GetOption() { //查询合约(期权)信息 List <MarketDto> list = new List <MarketDto>(); MarketDto mk = null; var Contracts = MvcApplication.OptionService.Model.Contracts.Where(a => a.IsDel == false); foreach (var item in Contracts) { var mt = MvcApplication.OptionService.MarketBoard.Get(item.Name); if (mt == null) { mk = new MarketDto { Code = item.Code, Name = item.Name, Newest = 0, HitPrice = 0, LowPrice = 0, PositionTotal = 0, Times = 0 }; } else { mk = new MarketDto(mt, MvcApplication.OptionService.Matcher.Container.Get1PriceAndCount); var os = MvcApplication.OptionService.Model.Traders.Where(s => s.Positions.Count > 0).ToList(); foreach (var o in os) { var oso = o.GetPositionSummaries().Select(a => new PositionSummaryDto(a, MvcApplication.OptionService.MarketBoard.GetNewestPrice(a.CName), 0 )).Where(a => a.Contract.Code == mk.Code && a.PositionType == PositionType.义务仓.ToString()).FirstOrDefault(); if (oso != null) { mk.PositionTotal += oso.Count; } } } mk.GetPositionTotal(); list.Add(mk); } return(View(list.OrderBy(d => d.Code.Substring(1, d.Code.Length - 1)))); }
public IHttpActionResult UpdateMarket(int id, MarketDto marketDto) { if (!ModelState.IsValid) { return(BadRequest()); } var productInDb = _context.Productz.SingleOrDefault(p => p.Id == id); if (productInDb == null) { return(NotFound()); } Mapper.Map(marketDto, productInDb); var product = Mapper.Map <MarketDto, Market>(marketDto); _context.SaveChanges(); marketDto.Id = product.Id; return(Created(new Uri(Request.RequestUri + "/" + product.Id), marketDto)); }
public void GetMarkets_AlreadyExistingCurrencyInstancesAreUsed() { //Arrange Mock <IMarketRepository> mockedRepository = new Mock <IMarketRepository>(); MarketDto[] dtos = getMarketDtos(); MarketDto dto = dtos[1]; mockedRepository.Setup(r => r.GetMarketById(dto.Id)).Returns(dto); mockedRepository.Setup(r => r.GetMarkets()).Returns(dtos); //Act IMarketService service = testServiceInstance(mockedRepository); Market market = service.GetMarketById(dto.Id); IEnumerable <Market> markets = service.GetMarkets(); //Assert Market fromResultCollection = markets.SingleOrDefault(m => m.GetId() == dto.Id); Assert.AreSame(fromResultCollection, market); }
public void TestMethod1() { MarketDto md = new MarketDto(); DateTime dt = DateTime.Now.AddHours(2); var r = md.MakeCe(dt); Assert.IsTrue(r.Contains("小时")); dt = dt.AddHours(-1.5); var r1 = md.MakeCe(dt); Assert.IsTrue(r1.Contains("分钟")); dt = DateTime.Now.AddSeconds(50); var r2 = md.MakeCe(dt); Assert.IsTrue(r2.Contains("秒")); dt = DateTime.Now.AddDays(100); var r3 = md.MakeCe(dt); Assert.AreEqual(r3, "100天"); }
public async Task Add(MarketDto value) { await Clients.All.Add(value); }
public async Task Update(MarketDto value) { await Clients.All.Update(value); }
public async Task Delete(MarketDto value) { await Clients.All.Delete(value); }
public ActionResult Market_Update([DataSourceRequest] DataSourceRequest request, MarketDto model) { this.SettingManager.IncrementCacheCounter("Markets"); if (model != null && ModelState.IsValid) { this._marketAppService.Save(model); } return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); }
public ActionResult Market_Destroy([DataSourceRequest] DataSourceRequest request, MarketDto model) { this.SettingManager.IncrementCacheCounter("Markets"); if (model != null) { this._marketRepository.Delete(model.Id); } return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); }