protected void CalcCommissions(List <TransactionDto> currencyForCommission, CommissionMethod method, CommissionAccount account, double pv, double commissions) { string currency = currencyForCommission[0].CurrencyId; int precision = currency == BaseSymbol || method == CommissionMethod.TERM_TICKS ? 4 : 3; double calcCommissions = 0; if (method == CommissionMethod.EXACT_VALUE) { calcCommissions = Math.Round(TestContent.BaseTransactions.FindAll(t => t.Type == Type.profit_loss).Sum(t => t.Amount) * pv, precision); } if (method == CommissionMethod.QUANTITY_PERCENT) { calcCommissions = Math.Round(currencyForCommission.FindAll(t => t.Type == Type.profit_loss).Sum(t => t.Amount) * pv * GetCoeffMethod(method, account), precision); } if (method == CommissionMethod.TERM_TICKS) { calcCommissions = Math.Round(Math.Pow(TestContent.BaseTransactions.FindAll(t => t.Type == Type.profit_loss).Sum(t => t.Amount), 2) * pv * GetCoeffMethod(method, account) / currencyForCommission.FindAll(t => t.Type == Type.profit_loss).Sum(t => t.Amount), precision); } calcCommissions = calcCommissions > 0 ? -calcCommissions : calcCommissions; if (CompareDouble(commissions, calcCommissions)) { Console.WriteLine("{0} Commissions: {1}, Calculate commissions: {2}", currency, commissions, calcCommissions); } else { Console.WriteLine("Error! {0} Commissions: {1}, Calculate commissions: {2}", currency, commissions, calcCommissions); TestContent.IsSuccess = false; } }
protected double GetCoeffMethod(CommissionMethod method, CommissionAccount account) { switch (method) { case CommissionMethod.QUANTITY_PERCENT: return(0.01); case CommissionMethod.TERM_TICKS: return(Security.TickSize); } return(1); }
protected void CheckCommissions(bool isPassive) { if (Order.Side == Side.BUY) { CommissionAccount account = (CommissionAccount)TestContent.TradeSettings.Settings.BuyerCommissionAccount; CommissionMethod method = (CommissionMethod)TestContent.TradeSettings.Settings.BuyerCommissionMethod; double pv = !isPassive ? (double)TestContent.TradeSettings.Settings.BuyerTakerCommissionProgressive : (double)TestContent.TradeSettings.Settings.BuyerMakerCommissionProgressive; List <TransactionDto> currencyForCommission = account == CommissionAccount.SOURCE_ACCOUNT ? TestContent.TermTransactions : TestContent.BaseTransactions; double commissions = currencyForCommission.FindAll(t => t.Type == Type.trading_commission).Sum(t => t.Amount); if (method == CommissionMethod.TERM_TICKS) { currencyForCommission = account == CommissionAccount.SOURCE_ACCOUNT ? TestContent.BaseTransactions : TestContent.TermTransactions; } CalcCommissions(currencyForCommission, method, account, pv, commissions); } if (Order.Side == Side.SELL) { CommissionAccount account = (CommissionAccount)TestContent.TradeSettings.Settings.SellerCommissionAccount; CommissionMethod method = (CommissionMethod)TestContent.TradeSettings.Settings.SellerCommissionMethod; double pv = !isPassive ? (double)TestContent.TradeSettings.Settings.SellerTakerCommissionProgressive : (double)TestContent.TradeSettings.Settings.SellerMakerCommissionProgressive; List <TransactionDto> currencyForCommission = account == CommissionAccount.SOURCE_ACCOUNT ? TestContent.BaseTransactions : TestContent.TermTransactions; double commissions = currencyForCommission.FindAll(t => t.Type == Type.trading_commission).Sum(t => t.Amount); if (method == CommissionMethod.TERM_TICKS) { currencyForCommission = account == CommissionAccount.SOURCE_ACCOUNT ? TestContent.TermTransactions : TestContent.BaseTransactions; } CalcCommissions(currencyForCommission, method, account, pv, commissions); } }
/* * public void Invoke(string testName) * { * // attribute type we search * System.Type attributeType = typeof(TestCommissionAttribute); * * // find method * var methodInfo = this.GetType().GetMethods().FirstOrDefault(m => * m.GetCustomAttributes(attributeType).Cast<TestCommissionAttribute>().Any() && * string.Equals(m.Name, testName, StringComparison.InvariantCultureIgnoreCase)); * * if (methodInfo != null) * { * // method found * PrintTestName(methodInfo.Name); * InitializeTestContent(); * try * { * methodInfo.Invoke(this, new object[] { methodInfo.Name }); * } * catch (Exception ex) * { * Console.WriteLine(ex.Message); * } * } * } * * public void InvokeAll() * { * System.Type attributeType = typeof(TestCommissionAttribute); * * var methodsInfo = this.GetType().GetMethods().Where(m => * m.GetCustomAttributes(attributeType).Cast<TestCommissionAttribute>().Any()).ToList(); * * foreach (var method in methodsInfo) * { * PrintTestName(method.Name); * InitializeTestContent(); * try * { * method.Invoke(this, new object[] { method.Name }); * } * catch (Exception ex) * { * Console.WriteLine(ex.Message); * } * } * } * * private void PrintTestName(string testName) * { * Console.WriteLine("Start test: {0}", testName); * } */ public void TestsConstructor(string testName, OrderType orderType, Side orderSide, CommissionAccount account, CommissionMethod method, bool isPassive) { InitializeTestContent(); TestContent.TradeSettings.Settings.BuyerTakerCommissionProgressive = 7; TestContent.TradeSettings.Settings.SellerTakerCommissionProgressive = 5; TestContent.TradeSettings.Settings.BuyerMakerCommissionProgressive = 6; TestContent.TradeSettings.Settings.SellerMakerCommissionProgressive = 4; if (orderSide == Side.BUY) { TestContent.TradeSettings.Settings.BuyerCommissionAccount = account; TestContent.TradeSettings.Settings.BuyerCommissionMethod = method; } if (orderSide == Side.SELL) { TestContent.TradeSettings.Settings.SellerCommissionAccount = account; TestContent.TradeSettings.Settings.SellerCommissionMethod = method; } ConfiguratorService.SaveTradeSetting(User.UserId, TestContent.TradeSettings.Settings); Order = new OrderCrypto() { Destination = Exchange, Quantity = method == CommissionMethod.TERM_TICKS ? 2 : 0.01, Side = orderSide, Type = orderType, SecurityId = Symbol, }; if (orderType == OrderType.LIMIT) { Order.Price = CalcAggressiveOrderPrice(orderSide); Order.TimeInForce = isPassive ? TimeInForce.DAY : TimeInForce.IOC; } GeneralCheck(testName, isPassive); }