public async Task SetSetting_ExistingKey_UpdatesEntry() { // Arrange const string existingKey = "TestKey2"; const string existingValue = "2"; const string newValue = "TestValueUpdate"; await using var context = new CoreDbContext(ContextOptions); var service = new SettingService(new UnitOfWork(context), _localizerMock); var request = new SettingRequest { Key = existingKey, Value = newValue }; // Act await service.SetSettingAsync(request); // Assert var currentEntry = await context.Setting.FirstAsync(setting => setting.Key == existingKey); Assert.Equal(newValue, currentEntry.Value); Assert.NotEqual(existingValue, currentEntry.Value); }
public void Logon() { var btxName = MainWindow.Config.BitmexScalper.AccountMode; var setting = SettingRequest.Get(_apiClient, btxName); _btxLiq = new BtxLiquidation(setting.TradeFee); _bitmex = new BitmexExchange(setting); _bitmex.Log = new RestServiceEventLogger(_apiClient, DataType.ServiceName.Desktop); _btxBotClient.Log = _bitmex.Log; createIndicatorRequest = () => new IndicatorRequest(_apiClient); createTradeRequest = () => new TradeRequest(_apiClient); createPosRequest = () => new PositionRequest(_apiClient); createLogRequest = () => new LogRequest(_apiClient); createSettingRequest = () => new SettingRequest(_apiClient); try { _bitmex.Logon(); _btxBotClient.Logon(); } catch (Exception ex) { _bitmex.Log.WriteError(ex); throw ex; } }
private void SaveInstruments(BitmexInstrumentSettings[] settings) { var request = new SettingRequest(_apiClient); settings = settings.Where(s => s.MakerFee.HasValue).ToArray(); request.SaveBitmexInstruments(_btxUser.Id, settings); }
public async Task <SettingResponse> EditAsync(SettingRequest request) { var entity = _repo.Update(_mapper.Map <SettingRequest, Setting>(request)); await _repo.SaveChangesAsync(); return(_mapper.Map <SettingResponse>(entity)); }
public void Start() { var config = (BotcoinConfigSection)ConfigurationManager.GetSection("botcoin"); var btxSetting = SettingRequest.Get(_apiClient, config.BitmexBot.AccountMode); _bitmex = new BitmexExchange(btxSetting); _bitmex.Log = Log; _bitmex.ExecutionChanged += OnExecutionChanged; _bitmex.MarginChanged += OnMarginChanged; _bitmex.OrderChanged += OnOrderChanged; _bitmex.WalletChanged += OnWalletChanged; _bitmex.AuthPassed += OnAuthPassed; _bitmex.Logon(); _btxUser = _bitmex.Exchange.Client.GetAccount(); _bitmex.SubscriptionAuth(null); _instrumentSettingsTimer.Start(); _vwapGainsTimer.Start(); _wsServer.Start(); OnInstrumentSettingsTimerElapsed(null, null); OnVwapGainsTimerElapsed(null, null); }
public async Task <Setting> SetSettingAsync(SettingRequest settingRequest) { if (settingRequest == null) { throw new ArgumentNullException(nameof(settingRequest)); } var result = await _uow.SettingRepository .FirstOrDefaultAsync(s => s.Key == settingRequest.Key); if (result != null) { result.Value = settingRequest.Value; _uow.SettingRepository.Update(result); } else { result = new Setting { Key = settingRequest.Key, Value = settingRequest.Value }; await _uow.SettingRepository.AddAsync(result); } await _uow.CommitAsync(); return(result); }
public async Task <IActionResult> SetSetting([FromBody] SettingRequest setting) { var result = await _settingService.SetSettingAsync(setting); var settingResponse = _mapper.Map <SettingResponse>(result); return(Ok(new ApiOkResponse(settingResponse))); }
public async Task <SettingResponse> AddAsync(SettingRequest request) { var entity = _mapper.Map <Setting>(request); entity = _repo.Add(entity); await _repo.SaveChangesAsync(); return(await Task.Run(() => _mapper.Map <SettingResponse>(entity))); }
private async Task AddInitialSettings(SettingsViewModel viewModel) { SettingRequest request = new SettingRequest(); request.Id = SettingId; request.BingKey = Settings.BingKey; request.BlackListTerms = string.Join(",", Settings.BlackListTerms); request.WhiteListTlds = string.Join(",", Settings.WhiteListTlds); var result = await _settingsService.AddAsync(request); if (result != null) { SettingId = result.Id; } }
private async Task UpdateSettings(SettingsViewModel viewModel) { SettingRequest request = new SettingRequest(); request.Id = SettingId; request.BingKey = Settings.BingKey; request.BlackListTerms = string.Join(",", Settings.BlackListTerms); request.WhiteListTlds = string.Join(",", Settings.WhiteListTlds); var result = await _settingsService.EditAsync(request); if (result == null) { Error.IsError = true; Error.ErrorMessage = "Error saving setting."; await InitializeSettings(); } }
public void Logon() { _bts = new BitstampExchange(SettingRequest.Get(_apiClient, "Bitstamp")); _bts.Log = new RestServiceEventLogger(_apiClient, ServiceName.Desktop); _bts.OnBtcTrade += _wnd.OnBitstampTradeReceived; createLevelRequest = () => new PriceLevelRequest(_apiClient); createChartRequest = () => new ChartRequest(_apiClient); createLogRequest = () => new LogRequest(_apiClient); try { _bts.Logon(); } catch (Exception ex) { _bts.Log.WriteError(String.Format("[{0}] {1} {2}", ex.GetType(), ex.Message, ex.StackTrace)); throw ex; } }
public async Task <Setting> SetSettingAsync(SettingRequest settingRequest) { var result = await _uow.SettingRepository.FindBy(s => s.Key == settingRequest.Key).FirstOrDefaultAsync(); if (result != null) { result.Value = settingRequest.Value; _uow.SettingRepository.Update(result); } else { result = new Setting(); result.Key = settingRequest.Key; result.Value = settingRequest.Value; await _uow.SettingRepository.AddAsync(result); } await _uow.CommitAsync(); return(result); }
public async Task SetSetting_NewKey_CreatesEntry() { // Arrange const string key = "TestKeyNew"; const string value = "TestValueNew"; var request = new SettingRequest { Key = key, Value = value }; await using var context = new CoreDbContext(ContextOptions); var service = new SettingService(new UnitOfWork(context), _localizerMock); // Act await service.SetSettingAsync(request); // Assert var created = await context.Setting.AnyAsync(setting => setting.Key == key && setting.Value == value); Assert.True(created); }
/// <summary> /// Updates the setting. /// </summary> /// <param name="siteSubdomain">The site subdomain.</param> /// <param name="settingId">The setting id.</param> /// <param name="settingRequest">The setting request.</param> /// <param name="format">The format.</param> /// <returns></returns> public SettingResponse UpdateSetting(string siteSubdomain, string settingId, SettingRequest settingRequest, string format = ContentFormat.XML) { return _service.Put<SettingRequest, SettingResponse>(string.Format("{0}/{1}/{2}.{3}", _gatewayURL, siteSubdomain, settingId, format), settingRequest); }
public TestDataValues PrepareSettingsTestData() { var testData = new TestDataValues(); var site = AddSite(); testData.SiteId = site.Id; testData.Subdomain = site.Subdomain; testData.SiteName = site.Name; var settings = _gateway.Settings.GetSettings(site.Subdomain); Assert.IsNotNull(settings); Assert.Greater(settings.Count, 2); // add some settings var newSetting = new SettingRequest { SiteId = site.Id, Description = settings[0].Description, Name = settings[0].Name, Value = settings[0].Value, }; var setting = _gateway.Settings.UpdateSetting(site.Subdomain, settings[0].SettingId.ToString(), newSetting); Assert.IsNotNull(setting); newSetting = new SettingRequest { SiteId = site.Id, Description = settings[1].Description, Name = settings[1].Name, Value = settings[1].Value, }; setting = _gateway.Settings.UpdateSetting(site.Subdomain, settings[0].SettingId.ToString(), newSetting); Assert.IsNotNull(setting); return testData; }