public async Task UpdateSpotInstrumentFeesSettings(SpotInstrumentFees settings) { using var action = MyTelemetry.StartActivity("Update Spot Instrument Fees Settings"); settings.AddToActivityAsJsonTag("settings"); try { _logger.LogInformation("Update Spot Instrument Fees Setting: {jsonText}", JsonConvert.SerializeObject(settings)); ValidateSettings(settings); var entity = SpotInstrumentFeesNoSqlEntity.Create(settings); var existingItem = await _writer.GetAsync(entity.PartitionKey, entity.RowKey); if (existingItem == null) { throw new Exception("Cannot update Spot Instrument Fees Settings. Do not exist"); } await _writer.InsertOrReplaceAsync(entity); _logger.LogInformation("Updated Spot Instrument Fees Setting: {jsonText}", JsonConvert.SerializeObject(settings)); } catch (Exception ex) { _logger.LogError(ex, "Cannot update ExternalMarketSettings: {requestJson}", JsonConvert.SerializeObject(settings)); ex.FailActivity(); throw; } }
public static LimitOrderFee ConvertLimitOrderFee(SpotInstrumentFees instrumentFees) { var fee = new LimitOrderFee { Type = ConvertFeeType(instrumentFees.FeeType) }; if (fee.Type == FeeType.NoFee) { return(fee); } fee.MakerSizeType = ConvertFeeSizeType(instrumentFees.MakerFeeSizeType); fee.MakerSize = instrumentFees.MakerFeeSize.ToString(CultureInfo.InvariantCulture); fee.TakerSizeType = ConvertFeeSizeType(instrumentFees.TakerFeeSizeType); fee.TakerSize = instrumentFees.TakerFeeSize.ToString(CultureInfo.InvariantCulture); fee.TargetAccountId = instrumentFees.AccountId; fee.TargetWalletId = instrumentFees.WalletId; if (!string.IsNullOrEmpty(instrumentFees.FeeAssetId)) { fee.AssetId.Add(instrumentFees.FeeAssetId); } return(fee); }
public static SpotInstrumentFeesNoSqlEntity Create(SpotInstrumentFees spotInstrumentFees) { return(new() { PartitionKey = GeneratePartitionKey(spotInstrumentFees.BrokerId), RowKey = GenerateRowKey(spotInstrumentFees.SpotInstrumentId), BrokerId = spotInstrumentFees.BrokerId, SpotInstrumentId = spotInstrumentFees.SpotInstrumentId, SpotInstrumentFees = spotInstrumentFees }); }
public async Task <NullableValue <SpotInstrumentFees> > GetSpotInstrumentFeesAsync( GetSpotInstrumentFeesRequest request) { try { var fees = _client.GetSpotInstrumentFees(request.BrokerId, request.SpotInstrumentId); return(fees == null ? null : new NullableValue <SpotInstrumentFees>(SpotInstrumentFees.Create(fees))); } catch (Exception ex) { if (ex.Message == "Unknown HTTP result CodeNotFound. Message: Row not found") { return(new NullableValue <SpotInstrumentFees>()); } throw; } }
private static void ValidateSettings(SpotInstrumentFees settings) { if (string.IsNullOrEmpty(settings.BrokerId)) { throw new Exception("Cannot add settings with empty broker"); } if (string.IsNullOrEmpty(settings.SpotInstrumentId)) { throw new Exception("Cannot add settings with empty instrument"); } if (settings.MakerFeeSize < 0) { throw new Exception("Cannot add settings with negative maker fee size"); } if (settings.TakerFeeSize < 0) { throw new Exception("Cannot add settings with negative taker fee size"); } }