public async Task <Result <MarketSettingsErrorCodes> > UpdateAsync(MarketSettings model) { using (var context = _contextFactory.CreateDataContext()) { var existing = await context.MarketSettings.FindAsync(model.Id); if (existing == null) { return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes.MarketSettingsDoNotExist)); } existing.MapFromDomain(model); context.MarketSettings.Update(existing); try { await context.SaveChangesAsync(); return(new Result <MarketSettingsErrorCodes>()); } catch (DbUpdateConcurrencyException e) { if (e.Message.Contains(DoesNotExistException)) { return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes.MarketSettingsDoNotExist)); } throw; } } }
private async Task UpdateChargeTypes(MarketSettings marketSettings) { var chargeTypes = await GetChargeTypes(marketSettings) ?? new ListItem[0]; Console.WriteLine(chargeTypes.ToJson()); _chargeTypesListSubject.OnNext(chargeTypes); }
public async Task <Result <MarketSettingsErrorCodes> > AddAsync(MarketSettings model) { var entity = MarketSettingsEntity.Create(model); using (var context = _contextFactory.CreateDataContext()) { context.MarketSettings.Add(entity); try { await context.SaveChangesAsync(); return(new Result <MarketSettingsErrorCodes>()); } catch (DbUpdateException e) { if (e.InnerException is SqlException sqlException) { switch (sqlException.Number) { case MsSqlErrorCodes.DuplicateIndex: return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes.NameAlreadyExists)); case MsSqlErrorCodes.PrimaryKeyConstraintViolation: return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes.IdAlreadyExists)); } } throw; } } }
private List <ScheduleSettings> MapMarketSchedule(MarketSettings marketSettings, List <DayOfWeek> platformWeekends) { var result = MarketScheduleExtensions.MapHolidays(marketSettings.Id, marketSettings.Name, marketSettings.Holidays, null); result.AddRange(MarketScheduleExtensions.MapWeekends( marketSettings.Id, marketSettings.Name, platformWeekends, null)); var marketScheduleUtcRespectful = marketSettings.MarketSchedule.ShiftToUtc(); result.AddRange( marketScheduleUtcRespectful.GetMarketHoursScheduleSettings(marketSettings.Id, marketSettings.Name, null)); result.AddRange( marketScheduleUtcRespectful.HalfWorkingDays.GetScheduleSettings(marketSettings.Id, marketSettings.Name, null)); return(result); }
public void Init() { Settings = new MarketSettings(); Settings.Init(); Npc = new NpcSettings(); Npc.Init(); OngoingMerchants = new List <MerchantsUnderWay>(); }
private async Task MarketChanged(MarketSettings marketSettings) { if (_marketSettings.HashedMarket != marketSettings.HashedMarket) { await SetBookingSettings(_accountService.CurrentAccount.Settings); } _marketSettings = marketSettings; }
private async Task MarketChanged(MarketSettings marketSettings) { // If we changed market if (marketSettings.HashedMarket != _marketSettings.HashedMarket) { UpdateChargeTypes(marketSettings); } _marketSettings = marketSettings; }
public static void SetAssetFieldsFromMarketSettings(this Asset asset, MarketSettings marketSettings) { var marketScheduleUtcRespectful = marketSettings.MarketSchedule.ShiftToUtc(); asset.Underlying.MarketDetails.Calendar.Holidays = marketSettings.Holidays; asset.Underlying.MarketDetails.MarketHours.Open = marketScheduleUtcRespectful.Open; asset.Underlying.MarketDetails.MarketHours.Close = marketScheduleUtcRespectful.Close; asset.Underlying.MarketDetails.Name = marketSettings.Name; asset.Underlying.MarketDetails.MarketId = marketSettings.Id; asset.SetHalfWorkingDays(marketSettings); }
private void LoadMarketSettings() { var settings = _settingsService.GetSettings <ChartsSettings>(); var marketSettings = settings?.Markets?.FirstOrDefault(m => m.Epic == _marketEpic); if (marketSettings == null) { marketSettings = MarketSettings.GetDefault(_marketEpic); if (settings.Markets == null) { settings.Markets = new List <MarketSettings>(); } settings.Markets.Add(marketSettings); _settingsService.SaveSettings <ChartsSettings>(); } var tlp = marketSettings.TopLeftPeriod; if (tlp.Mode == PeriodMode.Time) { TopLeftCandleReceiver = _tradingService.GetCandleReceiver(_marketEpic, (Periods)tlp.TimePeriod, tlp.AverageOpen); } else { TopLeftCandleReceiver = _tradingService.GetCandleReceiver(_marketEpic, tlp.TickCount, tlp.AverageOpen, tlp.MaxSeconds); } var blp = marketSettings.BottomLeftPeriod; if (blp.Mode == PeriodMode.Time) { BottomLeftCandleReceiver = _tradingService.GetCandleReceiver(_marketEpic, (Periods)blp.TimePeriod, blp.AverageOpen); } else { BottomLeftCandleReceiver = _tradingService.GetCandleReceiver(_marketEpic, blp.TickCount, blp.AverageOpen, blp.MaxSeconds); } var rp = marketSettings.RightPeriod; if (rp.Mode == PeriodMode.Time) { RightCandleReceiver = _tradingService.GetCandleReceiver(_marketEpic, (Periods)rp.TimePeriod, rp.AverageOpen); } else { RightCandleReceiver = _tradingService.GetCandleReceiver(_marketEpic, rp.TickCount, rp.AverageOpen, rp.MaxSeconds); } }
private async Task MarketChanged(MarketSettings marketSettings) { // If we changed market if (marketSettings.HashedMarket != _marketSettings.HashedMarket) { var vehicles = marketSettings.IsLocalMarket ? await GetLocalMarketVehiclesList() : await GetExternalMarketVehicleTypes(); _vehiclesListSubject.OnNext(vehicles); } _marketSettings = marketSettings; }
private async Task PublishMarketSettingsChangedEvent (MarketSettings oldSettings, MarketSettings newSettings, string username, string correlationId, ChangeType changeType) { await _cqrsMessageSender.SendEvent(new MarketSettingsChangedEvent { Username = username, ChangeType = changeType, CorrelationId = correlationId, EventId = Guid.NewGuid().ToString(), Timestamp = DateTime.UtcNow, OldMarketSettings = _convertService.Convert <MarketSettings, MarketSettingsContract>(oldSettings), NewMarketSettings = _convertService.Convert <MarketSettings, MarketSettingsContract>(newSettings), }); }
private static Result <MarketSettingsErrorCodes> ValidateSettings(MarketSettings newSettings, MarketSettings existingSettings = null) { if (newSettings.DividendsLong < 0 || newSettings.DividendsLong > 100) { return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes.InvalidDividendsLongValue)); } if (newSettings.DividendsShort < 0 || newSettings.DividendsShort > 100) { return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes.InvalidDividendsShortValue)); } if (newSettings.Dividends871M < 0 || newSettings.Dividends871M > 100) { return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes.InvalidDividends871MValue)); } if (existingSettings == null) { return(new Result <MarketSettingsErrorCodes>()); } // This is the current day taking into account the timezone var currentDay = TimeZoneInfo.ConvertTimeFromUtc( DateTime.UtcNow, TZConvert.GetTimeZoneInfo(existingSettings.MarketSchedule.TimeZoneId)); var hasTradingStarted = existingSettings.MarketSchedule.Open.First() <= currentDay.TimeOfDay; // check holidays var newHolidays = newSettings.Holidays .Select(x => x.Date.Date) .Except(existingSettings.Holidays); var holidaysViolate = newHolidays.Contains(currentDay.Date) && hasTradingStarted; // check half-working days var newHalfWorkingDays = newSettings.MarketSchedule.HalfWorkingDays.Except(existingSettings.MarketSchedule.HalfWorkingDays); var halfWorkingDaysViolate = newHalfWorkingDays.Any(d => d.SameCalendarDay(currentDay)) && hasTradingStarted; if (holidaysViolate || halfWorkingDaysViolate) { return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes.TradingDayAlreadyStarted)); } return(new Result <MarketSettingsErrorCodes>()); }
public void MapFromDomain(MarketSettings model) { Name = model.Name; DividendsLong = model.DividendsLong; DividendsShort = model.DividendsShort; Dividends871M = model.Dividends871M; NormalizedName = model.Name.ToLower(); Holidays = model.Holidays.Distinct().Select(date => new HolidayEntity { Date = date.Date, MarketSettingsId = model.Id }).ToList(); MarketSchedule = new MarketScheduleEntity { Schedule = model.MarketSchedule }; }
public async Task UpdateMarketSettingsIfNecessary(Position currentPosition) { if (ShouldUpdateMarket(currentPosition)) { _lastMarketPosition = currentPosition; var marketSettings = await GetMarketSettings(currentPosition.Latitude, currentPosition.Longitude); if (marketSettings == null) { // in case of no network we get null, init object with a non-null default value marketSettings = new MarketSettings(); } _marketSettingsSubject.OnNext(marketSettings); } }
public static void SetDividendFactorFields(this Asset asset, MarketSettings marketSettings, BrokerSettingsContract brokerSettings, Product product) { var dividendShort = product.DividendsShort ?? marketSettings.DividendsShort ?? brokerSettings.DividendsShortPercent; var dividendLong = product.DividendsLong ?? marketSettings.DividendsLong ?? brokerSettings.DividendsLongPercent; var dividend871M = product.Dividends871M ?? marketSettings.Dividends871M ?? brokerSettings.Dividends871MPercent; asset.DividendsFactor.Percent = dividendLong; asset.DividendsFactor.ShortPercent = dividendShort; asset.DividendsFactor.Us871Percent = dividend871M; asset.Underlying.MarketDetails.DividendsFactor.Percent = dividendLong; asset.Underlying.MarketDetails.DividendsFactor.ShortPercent = dividendShort; asset.Underlying.MarketDetails.DividendsFactor.Us871Percent = dividend871M; asset.Underlying.DividendsFactor.Percent = dividendLong; asset.Underlying.DividendsFactor.ShortPercent = dividendShort; asset.Underlying.DividendsFactor.Us871Percent = dividend871M; }
private async Task <IList <ListItem> > GetChargeTypes(MarketSettings marketSettings) { var refData = await GetReferenceData(); if (refData == null) { return(null); } if (!CurrentAccount.IsPayPalAccountLinked) { refData.PaymentsList.Remove(i => i.Id == ChargeTypes.PayPal.Id); } var paymentSettings = await _paymentService.GetPaymentSettings(); var isCmt = paymentSettings.PaymentMode == PaymentMethod.Cmt || paymentSettings.PaymentMode == PaymentMethod.RideLinqCmt; refData.PaymentsList = isCmt ? HandlePaymentInCarForCmt(refData.PaymentsList, marketSettings) : EnforceExternalMarketPaymentInCarIfNeeded(refData.PaymentsList, marketSettings); if (refData.PaymentsList.All(x => x.Id == ChargeTypes.CardOnFile.Id)) { // there's only one Charge Type and it's card on file, return it // don't attempt to remove it because you'll end up with a message saying // you haven't selected a charge type when trying to book and not a message // saying "hey you need a card, add it now" // TLDR: it's easier to understand for the user this way return(refData.PaymentsList); } var creditCard = await GetDefaultCreditCard(); if (creditCard == null || CurrentAccount.IsPayPalAccountLinked || creditCard.IsDeactivated) { refData.PaymentsList.Remove(i => i.Id == ChargeTypes.CardOnFile.Id); } return(refData.PaymentsList); }
public MarketSettingsViewModel(MarketSettings epicSettings) { _epicSettings = epicSettings; Name = _epicSettings.Name; Size = _epicSettings.Size; HasStop = _epicSettings.HasStop; GarantedStop = _epicSettings.GarantedStop; StopDistance = _epicSettings.StopDistance; HasLimit = _epicSettings.HasLimit; LimitDistance = _epicSettings.LimitDistance; TopLeftPeriod = new MarketPeriodSettingsViewModel(_epicSettings.TopLeftPeriod); BottomLeftPeriod = new MarketPeriodSettingsViewModel(_epicSettings.BottomLeftPeriod); RightPeriod = new MarketPeriodSettingsViewModel(_epicSettings.RightPeriod); }
public static MarketSettingsEntity Create(MarketSettings model) { return(new MarketSettingsEntity { Id = model.Id, Name = model.Name, DividendsLong = model.DividendsLong, DividendsShort = model.DividendsShort, Dividends871M = model.Dividends871M, NormalizedName = model.Name.ToLower(), Holidays = model.Holidays.Distinct().Select(date => new HolidayEntity { Date = date.Date, MarketSettingsId = model.Id }).ToList(), MarketSchedule = new MarketScheduleEntity { Schedule = model.MarketSchedule } }); }
private static Result <MarketSettingsErrorCodes> CreateMarketSettingsWithDefaults( MarketSettingsCreateOrUpdateDto model, out MarketSettings marketSettings) { marketSettings = null; try { marketSettings = MarketSettings.GetMarketSettingsWithDefaults(model); } catch (InvalidOpenAndCloseHoursException) { return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes.InvalidOpenAndCloseHours)); } catch (WinterOpenAndCloseWithAppliedTimezoneMustBeInTheSameDayException) { return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes .WinterOpenAndCloseWithAppliedTimezoneMustBeInTheSameDay)); } catch (SummerOpenAndCloseWithAppliedTimezoneMustBeInTheSameDayException) { return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes .SummerOpenAndCloseWithAppliedTimezoneMustBeInTheSameDay)); } catch (InvalidTimeZoneException) { return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes.InvalidTimezone)); } catch (InconsistentWorkingCalendarException) { return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes.InconsistentWorkingCalendar)); } catch (InvalidWorkingDayStringException) { return(new Result <MarketSettingsErrorCodes>(MarketSettingsErrorCodes.InvalidHalfWorkingDayString)); } return(new Result <MarketSettingsErrorCodes>()); }
private void MarketChanged(MarketSettings marketSettings) { // Market changed and not home market if (_lastHashedMarket != marketSettings.HashedMarket && !marketSettings.IsLocalMarket && !Settings.Network.HideMarketChangeWarning) { this.Services().Message.ShowMessage(this.Services().Localize["MarketChangedMessageTitle"], this.Services().Localize["MarketChangedMessage"]); } _lastHashedMarket = marketSettings.HashedMarket; if (BookingStatus != null && BookingStatus.BottomBar != null) { BookingStatus.BottomBar.DisableOutOfAppPayment = marketSettings.DisableOutOfAppPayment; } if (BottomBar != null) { BottomBar.CheckManualRideLinqEnabledAsync(); } }
private void HandleOrderValidatedtAndMarketSettingsChanged(OrderValidationResult orderValidationResult, MarketSettings marketSettings) { _orderValidationResult = orderValidationResult; IsFutureBookingDisabled = !marketSettings.EnableFutureBooking || (orderValidationResult != null && orderValidationResult.DisableFutureBooking); Book.RaiseCanExecuteChangedIfPossible(); BookLater.RaiseCanExecuteChangedIfPossible(); }
private void MarketChanged(MarketSettings marketSettings) { _isDriverBonusEnabledForMarket = marketSettings.EnableDriverBonus; RaisePropertyChanged(() => CanShowDriverBonus); }
public async Task HandleMarketSettingsUpdated(MarketSettings marketSettings, DateTime timestamp) { Func <Asset, bool> filter = x => x.Underlying.MarketDetails.MarketId == marketSettings.Id; await Handle(filter, timestamp); }
private IList <ListItem> HandlePaymentInCarForCmt(IList <ListItem> paymentList, MarketSettings market) { if (market.IsLocalMarket) { return(paymentList); } return(market.DisableOutOfAppPayment ? paymentList.Where(i => i.Id != ChargeTypes.PaymentInCar.Id).ToList() : EnsurePaymentInCarAvailableIfNeeded(paymentList)); }
private IList <ListItem> EnforceExternalMarketPaymentInCarIfNeeded(IList <ListItem> paymentList, MarketSettings market) { if (market.IsLocalMarket) { return(paymentList); } paymentList = paymentList .Where(paymentMethod => paymentMethod.Id == ChargeTypes.PaymentInCar.Id) .ToArray(); paymentList = EnsurePaymentInCarAvailableIfNeeded(paymentList); return(paymentList); }
private static void SetHalfWorkingDays(this Asset asset, MarketSettings marketSettings) { asset.Underlying.MarketDetails.Calendar.HalfWorkingDays = marketSettings.MarketSchedule.HalfWorkingDays.ToList(); }