public AssetFees GetAssetFees(string brokerId, string groupId, string assetId, OperationType operationType) { var entity = _assetFeesReader.Get(AssetFeesNoSqlEntity.GeneratePartitionKey(brokerId, groupId), AssetFeesNoSqlEntity.GenerateRowKey(assetId, operationType)); if (entity == null) { return(new AssetFees { FeeType = FeeType.NoFee }); } var result = entity.AssetFees; if (string.IsNullOrEmpty(result.AccountId) || string.IsNullOrEmpty(result.WalletId)) { var settings = _feesSettingsReader.Get(FeesSettingsNoSqlEntity.GeneratePartitionKey(brokerId), FeesSettingsNoSqlEntity.GenerateRowKey()); if (settings != null) { result.BrokerId = settings.FeesSettings.BrokerId; result.AccountId = settings.FeesSettings.AccountId; result.WalletId = settings.FeesSettings.WalletId; } } return(entity?.AssetFees); }
public async Task UpdateAssetFeesSettings(AssetFees settings) { using var action = MyTelemetry.StartActivity("Update Asset Fees Settings"); settings.AddToActivityAsJsonTag("settings"); try { _logger.LogInformation("Update Asset Fees Setting: {jsonText}", JsonConvert.SerializeObject(settings)); ValidateSettings(settings); var entity = AssetFeesNoSqlEntity.Create(settings); var existingItem = await _writer.GetAsync(entity.PartitionKey, entity.RowKey); if (existingItem == null) { throw new Exception("Cannot update Asset Fees Settings. Do not exist"); } await _writer.InsertOrReplaceAsync(entity); _logger.LogInformation("Updated Asset Fees Setting: {jsonText}", JsonConvert.SerializeObject(settings)); } catch (Exception ex) { _logger.LogError(ex, "Cannot update ExternalMarketSettings: {requestJson}", JsonConvert.SerializeObject(settings)); ex.FailActivity(); throw; } }
public async Task RemoveAssetFeesSettings(RemoveAssetFeesRequest request) { using var action = MyTelemetry.StartActivity("Remove Asset Fees Settings"); request.AddToActivityAsJsonTag("request"); try { _logger.LogInformation("Remove Asset Fees Setting: {jsonText}", JsonConvert.SerializeObject(request)); var entity = await _writer.DeleteAsync(AssetFeesNoSqlEntity.GeneratePartitionKey(request.BrokerId, request.ProfileId), AssetFeesNoSqlEntity.GenerateRowKey(request.AssetId, request.OperationType)); if (entity != null) { _logger.LogInformation("Removed Asset Fees Settings: {jsonText}", JsonConvert.SerializeObject(entity)); } else { _logger.LogInformation("Unable to remove Asset Fees Setting, do not exist: {jsonText}", JsonConvert.SerializeObject(request)); } } catch (Exception ex) { _logger.LogError(ex, "Cannot remove ExternalMarketSettings: {requestJson}", JsonConvert.SerializeObject(request)); ex.FailActivity(); throw; } }
public async Task <OperationResponse> CreateWithdrawalProfile(CreateGroupRequest request) { try { var groups = await _profileWriter.GetAsync(FeeProfilesNoSqlEntity.GeneratePartitionKey(), FeeProfilesNoSqlEntity.GenerateRowKey()); var withdrawalList = groups?.Profiles ?? new List <string>(); var depositList = groups?.DepositProfiles ?? new List <string>() { FeeProfileConsts.DefaultProfile }; withdrawalList.Add(request.ProfileId); await _profileWriter.InsertOrReplaceAsync(FeeProfilesNoSqlEntity.Create(withdrawalList.Distinct().ToList(), depositList)); if (!string.IsNullOrWhiteSpace(request.CloneFromProfileId)) { var assets = (await _assetWriter.GetAsync( AssetFeesNoSqlEntity.GeneratePartitionKey(request.BrokerId, request.CloneFromProfileId))) .Select(t => t.AssetFees).ToList(); foreach (var asset in assets) { asset.ProfileId = request.ProfileId; } await _assetWriter.BulkInsertOrReplaceAsync(assets.Select(AssetFeesNoSqlEntity.Create).ToList()); } return(new OperationResponse() { IsSuccess = true }); } catch (Exception e) { return(new OperationResponse() { IsSuccess = false, ErrorText = e.Message }); } }
public async Task <OperationResponse> DeleteWithdrawalProfile(DeleteProfileRequest request) { try { var groups = await _profileWriter.GetAsync(FeeProfilesNoSqlEntity.GeneratePartitionKey(), FeeProfilesNoSqlEntity.GenerateRowKey()); var withdrawalList = groups?.Profiles ?? new List <string>(); var depositList = groups?.DepositProfiles ?? new List <string>() { FeeProfileConsts.DefaultProfile }; var list = withdrawalList.Distinct().ToList(); list.Remove(request.ProfileId); await _profileWriter.InsertOrReplaceAsync(FeeProfilesNoSqlEntity.Create(list, depositList)); var assets = (await _assetWriter.GetAsync( AssetFeesNoSqlEntity.GeneratePartitionKey(request.BrokerId, request.ProfileId))).ToList(); foreach (var asset in assets) { await _assetWriter.DeleteAsync(asset.PartitionKey, asset.RowKey); } return(new OperationResponse() { IsSuccess = true }); } catch (Exception e) { return(new OperationResponse() { IsSuccess = false, ErrorText = e.Message }); } }