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); }
private async Task <LimitOrderFee> GetFee(string brokerId, string assetPair) { var tradingFee = await GetTradingFeeAsync(brokerId, assetPair); var settings = await GetFeesSettingsAsync(brokerId); if (tradingFee == null) { _logger.LogWarning("TradingFee from Exchange.Fees is null. The fee is set to 0. " + "BrokerId={@BrokerId}; AssetPair={@AssetPair}", brokerId, assetPair); return(NoFee()); } if (settings == null) { _logger.LogWarning("Settings is null. The fee is set to 0." + "BrokerId={@BrokerId}", brokerId); return(NoFee()); } if (settings.FeeWalletId == 0) { _logger.LogWarning("FeeWalletId is 0. The fee is set to 0. BrokerId={@BrokerId}", brokerId); return(NoFee()); } if (tradingFee.Levels == null || tradingFee.Levels.Count == 0) { _logger.LogWarning("TradingFee from Exchange.Fees has no levels. The fee is set to 0. " + "BrokerId={@BrokerId}; AssetPair={@AssetPair}", brokerId, assetPair); return(NoFee()); } var feeAccountId = settings.FeeAccountId; var feeWalletId = settings.FeeWalletId; // TODO: take first level as we don't have 30 days volume yet var level = tradingFee.Levels.OrderBy(x => x.Volume).First(); var makerSize = level.MakerFee / 100; var takerSize = level.TakerFee / 100; var feeType = makerSize == 0 && takerSize == 0 ? (int)FeeType.NoFee : (int)FeeType.ClientFee; var result = new LimitOrderFee { MakerSize = makerSize.ToString(CultureInfo.InvariantCulture), MakerSizeType = (int)FeeSizeType.Percentage, TakerSize = takerSize.ToString(CultureInfo.InvariantCulture), TakerSizeType = (int)FeeSizeType.Percentage, TargetAccountId = (ulong)feeAccountId, TargetWalletId = (ulong)feeWalletId, Type = feeType }; return(result); }