예제 #1
0
        public TransactionFillDetails GetTransactionFillDetails(
            IOrderAmountBased order, Price price, DateTime settlementDate, IFeeFactory feeFactory,
            decimal fillRatio, IExchange exchange)
        {
            decimal serviceChargePercentageforOrder = getServiceChargePercentage(order, exchange);
            TransactionFillDetails details = null;

            if (IsCommissionLinear)
            {
                Money amount = order.Amount * fillRatio;
                Money serviceCharge = null;

                if (serviceChargePercentageforOrder != 0M)
                {
                    Money newAmount = amount * (decimal)(1M / (1M + serviceChargePercentageforOrder));
                    serviceCharge = (amount.Abs() - newAmount.Abs());
                    amount = newAmount;
                }

                // Calculate Commission
                Money commission = null;
                // if the trade fills the Order completely -> take the Commission from the Order
                if (fillRatio == 1M)
                    commission = order.Commission;

                // Convert amount when necessary
                if (!amount.Underlying.Equals(price.Underlying) && !price.Underlying.IsObsoleteCurrency)
                    amount = amount.Convert(order.ExRate, price.Underlying);

                InstrumentSize size = amount.CalculateSize(price);

                details = new TransactionFillDetails(size, amount, null, serviceCharge, serviceChargePercentageforOrder, commission, order.GrossAmount, order.Side);
            }
            else
            {
                // Do the goalseek
                ICommClient client;
                ICommRule rule = feeFactory.GetRelevantCommRule(order.Account, this, order.Side,
                    order.ActionType, settlementDate, true, out client);

                for (int i = 4; i > 0; i--)
                {
                    details = getTransactionFillDetailsAmountBasedOrderByGoalSeek(
                        order, settlementDate, price, exchange,
                        rule, client, serviceChargePercentageforOrder, i);

                    if (details.IsOK && !details.IsDiff)
                        break;
                }
                if (!details.IsOK || details.IsDiff)
                    throw new ApplicationException("Not possible to calculate the trade amounts, probably a commission rule applied with a minimum amount.");
            }
            if (details != null)
                details.SetSign(order.Side);
            return details;
        }
예제 #2
0
        public virtual TransactionFillDetails GetTransactionFillDetails(
            IOrderSizeBased order, Price price, DateTime settlementDate, IFeeFactory feeFactory,
            decimal fillRatio, IExchange exchange)
        {
            Money serviceCharge = null;
            Money commission = null;
            decimal serviceChargePercentageforOrder = getServiceChargePercentage(order, exchange);

            // Use the Value of the child order -> difference will go to Crumble account
            InstrumentSize size = order.Value * fillRatio;
            Money amount = size.CalculateAmount(price);

            if (serviceChargePercentageforOrder != 0M)
                serviceCharge = (amount * serviceChargePercentageforOrder).Abs().Negate();

            TransactionFillDetails details = new TransactionFillDetails(size, amount, null, serviceCharge, serviceChargePercentageforOrder, commission, order.GrossAmount, order.Side);
            details.SetSign(order.Side);
            return details;
        }