Beispiel #1
0
        internal static void CalculatePreCheckNecessary(Transaction tran, ref CalculateUnfillMarginParameters unfillParams, decimal?effectiveLot = null)
        {
            Price   buy     = null;
            Price   sell    = null;
            Account account = tran.Owner;

            Settings.Instrument     settingInstrument = tran.SettingInstrument;
            AccountClass.Instrument accountInstrument = account.GetOrCreateInstrument(settingInstrument.Id);
            if (tran.OrderType == OrderType.Market || tran.OrderType == OrderType.MarketOnOpen ||
                tran.OrderType == OrderType.MarketOnClose || settingInstrument.MarginFormula == MarginFormula.CSiMarketPrice ||
                settingInstrument.MarginFormula == MarginFormula.CSxMarketPrice)
            {
                Quotation quotation = QuotationProvider.GetLatestQuotation(tran.InstrumentId, account);
                buy  = quotation.BuyOnCustomerSide;
                sell = quotation.SellOnCustomerSide;
            }
            foreach (Order order in tran.Orders)
            {
                if (order.Phase == OrderPhase.Placed || order.Phase == OrderPhase.Placing)
                {
                    decimal contractSize = tran.ContractSize == 0 ? accountInstrument.TradePolicyDetail.ContractSize : tran.ContractSize;
                    var     price        = order.IsBuy ? sell : buy;
                    order.CalculatePreCheckNecessary(settingInstrument.MarginFormula, tran.CurrencyRate, contractSize, price, effectiveLot);
                }
            }

            foreach (Order order in tran.Orders)
            {
                if (tran.Type == TransactionType.OneCancelOther && tran.OrderType == OrderType.Limit && order.TradeOption == TradeOption.Better)
                {
                    continue;
                }
                Collect(order, tran.ContractSize, effectiveLot, ref unfillParams);
            }
        }
        private void InitializePrice(Settings.Instrument instrument, string ask, string bid)
        {
            Price askPrice = ask.CreatePrice(instrument);
            Price bidPirce = bid.CreatePrice(instrument);

            this.BuyPrice  = Quotation.GetBuyPriceForReset(instrument.IsNormal, askPrice, bidPirce);
            this.SellPrice = Quotation.GetSellPriceForReset(instrument.IsNormal, askPrice, bidPirce);
        }
        internal InstrumentCloseQuotation GetQuotation(Settings.Instrument instrument, List <TradingDailyQuotation> closeQuotations)
        {
            var quotations = new List <InstrumentCloseQuotation>(closeQuotations.Count);

            foreach (var eachCloseQuotation in closeQuotations)
            {
                quotations.Add(new InstrumentCloseQuotation(instrument, eachCloseQuotation));
            }
            return(this.GetQuotation(instrument, quotations));
        }
        private decimal CalculateOrderMargin(Order order, Settings.Setting setting, Settings.Instrument instrument, Settings.Account account, DateTime tradeDay, UsableMarginPrice usableMarginPrice)
        {
            Guid    currencyId   = this.GetCurrencyId(account, instrument);
            var     currencyRate = setting.GetCurrencyRate(instrument.CurrencyId, currencyId);
            decimal?rateIn       = currencyRate == null ? (decimal?)null : currencyRate.RateIn;
            decimal?rateOut      = currencyRate == null ? (decimal?)null : currencyRate.RateOut;
            var     currency     = setting.GetCurrency(currencyId, tradeDay);
            int     decimals     = currency.Decimals;
            Price   refPrice     = this.GetRefPrice(usableMarginPrice, order.IsBuy, instrument.IsNormal);

            return(Calculator.MarginCalculator.CalculateRptMargin((int)instrument.MarginFormula, order.LotBalance, order.Owner.ContractSize(tradeDay), order.ExecutePrice, rateIn, rateOut, decimals, refPrice));
        }
 private static void CalculatePrice(this Transaction tran, out Price buy, out Price sell)
 {
     buy = sell = null;
     Settings.Instrument settingInstrument = tran.SettingInstrument;
     if (tran.OrderType == OrderType.Market || tran.OrderType == OrderType.MarketOnOpen ||
         tran.OrderType == OrderType.MarketOnClose || settingInstrument.MarginFormula == MarginFormula.CSiMarketPrice ||
         settingInstrument.MarginFormula == MarginFormula.CSxMarketPrice)
     {
         Quotation quotation = tran.TradingInstrument.Quotation;
         buy  = quotation.BuyOnCustomerSide;
         sell = quotation.SellOnCustomerSide;
     }
 }
 private void CalculatePrice(out Price buy, out Price sell)
 {
     buy = sell = null;
     Settings.Instrument settingInstrument = _tran.SettingInstrument();
     if (_tran.OrderType == OrderType.Market || _tran.OrderType == OrderType.MarketOnOpen ||
         _tran.OrderType == OrderType.MarketOnClose || settingInstrument.MarginFormula == MarginFormula.CSiMarketPrice ||
         settingInstrument.MarginFormula == MarginFormula.CSxMarketPrice)
     {
         Quotation quotation = _tran.AccountInstrument.GetQuotation();
         buy  = quotation.BuyPrice;
         sell = quotation.SellPrice;
     }
 }
Beispiel #7
0
        private static Price CalculateAutoClosePrice(Order order, PriceType priceType)
        {
            Debug.Assert(order.IsOpen);
            SpecialTradePolicyDetail policy = order.Owner.SpecialTradePolicyDetail();

            Settings.Instrument instrument = order.Owner.SettingInstrument();

            OrderLevelRiskBase autoCloseBase      = priceType == PriceType.Limit ? policy.AutoLimitBase : policy.AutoStopBase;
            decimal            autoCloseThreshold = priceType == PriceType.Limit ? policy.AutoLimitThreshold : policy.AutoStopThreshold;

            if (autoCloseBase == OrderLevelRiskBase.None)
            {
                return(null);
            }
            else if (autoCloseBase == OrderLevelRiskBase.Necessary)
            {
                return(CalculateForOrderLevelRiskNecessay(order, autoCloseThreshold, instrument, priceType));
            }
            else
            {
                Price basePrice = order.ExecutePrice;
                if (autoCloseBase == OrderLevelRiskBase.SettlementPrice)
                {
                    TradeDay tradeDay = Settings.Setting.Default.GetTradeDay();
                    if (order.Owner.ExecuteTime > tradeDay.BeginTime)
                    {
                        return(null);
                    }
                    else
                    {
                        basePrice = (order.IsBuy ? instrument.DayQuotation.Buy : instrument.DayQuotation.Sell);
                    }
                }
                int autoClosePips = (int)autoCloseThreshold;
                if (order.SetPriceMaxMovePips > 0 && order.SetPriceMaxMovePips < autoClosePips)
                {
                    autoClosePips = order.SetPriceMaxMovePips;
                }

                if (order.IsBuy == (priceType == PriceType.Limit))
                {
                    return(Price.Add(basePrice, autoClosePips, !instrument.IsNormal));
                }
                else
                {
                    return(Price.Subtract(basePrice, autoClosePips, !instrument.IsNormal));
                }
            }
        }
 internal void OnInstrumentUpdated(Settings.Instrument instrument, Settings.InstrumentUpdateType updateType)
 {
     lock (_mutex)
     {
         Logger.InfoFormat("Market manager update instrument, updateType = {0}, instrument = {1}", updateType, instrument);
         if (updateType == Settings.InstrumentUpdateType.Add)
         {
             _instruments.Add(instrument.Id, new Instrument(instrument.Id));
         }
         else if (updateType == Settings.InstrumentUpdateType.Delete)
         {
             _instruments.Remove(instrument.Id);
         }
     }
 }
Beispiel #9
0
        internal static bool Book(this Account account, Token token, Protocal.TransactionBookData tranData)
        {
            bool useCurrentSetting;

            Settings.Instrument instrument = Settings.Setting.Default.GetInstrument(tranData.InstrumentId);
            TransactionError    error      = account.BookForPhysicalTran(tranData, out useCurrentSetting);

            if (error != TransactionError.OK)
            {
                throw new TransactionServerException(error);
            }
            if (!useCurrentSetting)
            {
                ResetManager.Default.LoadHistorySetting(tranData.TradeDay, "Book");
            }

            var settingAccount = Settings.Setting.Default.GetAccount(account.Id, tranData.TradeDay);

            if (settingAccount == null || tranData.ExecuteTime < settingAccount.BeginTime)
            {
                throw new TransactionServerException(TransactionError.AccountIsNotTrading);
            }

            if (token.AppType == AppType.PhysicalTerminal && instrument.Category == InstrumentCategory.Physical)
            {
                if (!tranData.TryFillExecutePrice(instrument, account))
                {
                    Logger.Error("TransactionServer.Book Can't get live price to book \r\n");
                    throw new TransactionServerException(TransactionError.InvalidPrice);
                }
            }
            Transaction tran = Periphery.TransactionBLL.TransactionFacade.CreateBookTran(instrument.Category, account, tranData);

            TransactionPlacer.Default.Verify(account, tran, false, tranData.AppType, PlaceContext.Empty);
            if (tranData.CheckMargin && !account.HasEnoughMoneyToPlace(tran))
            {
                throw new TransactionServerException(TransactionError.MarginIsNotEnough);
            }
            if (account.ExecuteBookTran(tran, tranData))
            {
                if (tran.IsPhysical)
                {
                    UpdatePhysicalRequestStatus(tran);
                }
                return(true);
            }
            return(false);
        }
        internal InstrumentCloseQuotation GetQuotation(Settings.Instrument instrument, DateTime tradeDay)
        {
            var closePrices = ResetManager.Default.GetInstrumentDayClosePrice(instrument.Id, tradeDay);

            if (closePrices == null || closePrices.Count == 0)
            {
                return(null);
            }
            var quotations = new List <InstrumentCloseQuotation>(closePrices.Count);

            foreach (var eachPrice in closePrices)
            {
                quotations.Add(new InstrumentCloseQuotation(instrument, eachPrice));
            }
            return(this.GetQuotation(instrument, quotations));
        }
Beispiel #11
0
 internal void OnInstrumentUpdated(Settings.Instrument instrument, Settings.InstrumentUpdateType updateType)
 {
     lock (this.lockObj)
     {
         Logger.InfoFormat("update instrument, updateType = {0}, instrument = {1}", updateType, instrument);
         if (updateType == Settings.InstrumentUpdateType.Add)
         {
             Debug.Assert(!_alertInstrumentDict.ContainsKey(instrument.Id));
             _alertInstrumentDict.Add(instrument.Id, new AlertInstrument(instrument));
         }
         else if (updateType == Settings.InstrumentUpdateType.Delete)
         {
             Debug.Assert(_alertInstrumentDict.ContainsKey(instrument.Id));
             _alertInstrumentDict.Remove(instrument.Id);
         }
     }
 }
Beispiel #12
0
        protected void VerifyPlaceSettings(Order order, PlaceContext context)
        {
            Transaction tran = order.Owner;

            Settings.Instrument instrument = order.Instrument(context.TradeDay);
            DateTime            baseTime   = Market.MarketManager.Now;

            if (tran.Type == TransactionType.OneCancelOther && tran.OrderCount != 2)
            {
                throw new TransactionServerException(TransactionError.InvalidRelation, "OCO transaction should have 2 orders");
            }

            if (!order.IsOpen)
            {
                CloseOrderVerifier.Default.Verify(order);
            }

            this.VerifyAmendOrder(order);

            if (tran.Type == TransactionType.OneCancelOther && order.IsOpen)
            {
                if (!tran.TradePolicyDetail(context.TradeDay).AllowNewOCO)
                {
                    throw new TransactionServerException(TransactionError.OrderTypeIsNotAcceptable, "New OCO order is not allowed by TradePolicy");
                }
            }
            else
            {
                if (!instrument.IsTypeAcceptable(tran.Type, order.OrderType) || (tran.Owner.Setting(context.TradeDay).Type == AccountType.Agent && tran.OrderType != OrderType.SpotTrade))
                {
                    throw new TransactionServerException(TransactionError.OrderTypeIsNotAcceptable, "Order type is not allowd by the instrument");
                }
            }

            if ((tran.OrderType == OrderType.SpotTrade || order.TradeOption != TradeOption.Invalid) && order.SetPrice == null)
            {
                throw new TransactionServerException(TransactionError.InvalidPrice, "SetPrice is null");
            }
        }
        private InstrumentCloseQuotation GetQuotation(Settings.Instrument instrument, List <InstrumentCloseQuotation> quotations)
        {
            if (quotations.Count == 0)
            {
                return(null);
            }
            Dictionary <Guid, InstrumentCloseQuotation> quotationPerQuotePolicy = new Dictionary <Guid, InstrumentCloseQuotation>();

            foreach (var eachQuotation in quotations)
            {
                if (!quotationPerQuotePolicy.ContainsKey(eachQuotation.QuotePolicyId))
                {
                    quotationPerQuotePolicy.Add(eachQuotation.QuotePolicyId, eachQuotation);
                }
            }
            InstrumentCloseQuotation result = ((IQuotePolicyProvider)_account).Get <InstrumentCloseQuotation>(delegate(Guid id, out InstrumentCloseQuotation q)
            {
                return(quotationPerQuotePolicy.TryGetValue(id, out q));
            });

            return(result);
        }
Beispiel #14
0
        internal static Price CalculateAutoClosePrice(this Order order, PriceType priceType)
        {
            Debug.Assert(order.IsOpen);
            SpecialTradePolicyDetail policy = order.Owner.SpecialTradePolicyDetail;

            Settings.Instrument instrument = order.Owner.SettingInstrument;

            OrderLevelRiskBase autoCloseBase      = priceType == PriceType.Limit ? policy.AutoLimitBase : policy.AutoStopBase;
            decimal            autoCloseThreshold = priceType == PriceType.Limit ? policy.AutoLimitThreshold : policy.AutoStopThreshold;

            if (autoCloseBase == OrderLevelRiskBase.Necessary)
            {
                return(CalculateForOrderLevelRiskNecessay(order, autoCloseThreshold, instrument, priceType));
            }
            else if (autoCloseBase == OrderLevelRiskBase.OpenPrice)
            {
                return(CalculateForOrderLevelOpenPrice(order, autoCloseThreshold, instrument, priceType));
            }
            else
            {
                return(null);
            }
        }
Beispiel #15
0
        private static Price CalculateForOrderLevelRiskNecessay(Order order, decimal autoCloseThreshold, Settings.Instrument instrument, PriceType priceType)
        {
            decimal netNecessary = order.Owner.Owner.Setting.RateMarginD * order.Owner.TradePolicyDetail.MarginD * order.Necessary;

            if (priceType == PriceType.Stop)
            {
                netNecessary = -netNecessary;
            }

            decimal tradePLThreshold = netNecessary * autoCloseThreshold;

            tradePLThreshold = order.Owner.CurrencyRate.Exchange(tradePLThreshold, false);

            return(Calculate(instrument.TradePLFormula, instrument.NumeratorUnit, instrument.Denominator,
                             order.LotBalance, order.Owner.ContractSize, (decimal)order.ExecutePrice, order.IsBuy, tradePLThreshold));
        }
Beispiel #16
0
        private InstalmentResult CreateInstalmentResult(DateTime tradeDay, InstalmentDetail instalment, PhysicalOrder order, Account account, Settings.Instrument instrument, Settings.Currency accountCurrency, Settings.Currency instrumentCurrency)
        {
            InstalmentResult result = new InstalmentResult();

            result.OrderId          = instalment.OrderId;
            result.Code             = order.Code;
            result.ExecuteTime      = order.ExecuteTime.Value;
            result.Lot              = order.Lot;
            result.LotBalance       = order.LotBalance;
            result.CurrencyId       = account.IsMultiCurrency ? instrumentCurrency.Id : accountCurrency.Id;
            result.Code             = account.IsMultiCurrency ? instrumentCurrency.Code : accountCurrency.Code;
            result.CurrencyDecimals = account.IsMultiCurrency ? instrumentCurrency.Decimals : accountCurrency.Decimals;
            result.PaidPledge       = order.PaidPledgeBalance;
            result.Sequence         = instalment.Period;
            result.InterestRate     = instalment.InterestRate;
            result.Principal        = instalment.Principal;
            result.Interest         = instalment.Interest;
            var instalmentPolicyDetail = order.Instalment.InstalmentPolicyDetail(null);

            result.DebitInterest = InstalmentManager.CalculateDebitInterest(instalment.Principal, instalment.Interest, tradeDay.GetDateDiff(instalment.PaymentDateTimeOnPlan.Value), instalmentPolicyDetail.InterestRate, instalmentPolicyDetail.DebitInterestType,
                                                                            instalmentPolicyDetail.DebitInterestRatio, instalmentPolicyDetail.DebitFreeDays, instrument.InterestYearDays, result.CurrencyDecimals);
            result.PaymentDateTimeOnPlan = instalment.PaymentDateTimeOnPlan;
            return(result);
        }
Beispiel #17
0
 internal InstalmentPayOffParameter(List <PhysicalOrder> orders, Account account, Settings.Instrument instrument, Price buyPrice, Price sellPrice, DateTime tradeDay)
 {
     this.Orders     = orders;
     this.Account    = account;
     this.Instrument = instrument;
     this.BuyPrice   = buyPrice;
     this.SellPrice  = sellPrice;
     this.TradeDay   = tradeDay;
 }
Beispiel #18
0
 private bool CanTradeCommon(Settings.Instrument instrument, DateTime baseTime)
 {
     return(instrument.IsActive && instrument.DayOpenTime <= baseTime && baseTime <= instrument.DayCloseTime);
 }
 internal InstrumentCloseQuotation(Settings.Instrument instrument, iExchange.Common.TradingDailyQuotation quotation)
 {
     this.InstrumentId  = instrument.Id;
     this.QuotePolicyId = quotation.QuotePolicyId;
     this.InitializePrice(instrument, quotation.Ask, quotation.Bid);
 }
 internal InstrumentCloseQuotation(Settings.Instrument instrument, DB.DBMapping.InstrumentDayClosePrice quotation)
 {
     this.InstrumentId  = instrument.Id;
     this.QuotePolicyId = quotation.QuotePolicyID;
     this.InitializePrice(instrument, quotation.Ask, quotation.Bid);
 }
Beispiel #21
0
 internal TradingInstrument(Settings.Instrument instrument)
 {
     this.SettingInstrument = instrument;
     this.TradingStatus     = new TradingStatus();
 }
Beispiel #22
0
 public static Price CreatePrice(this string price, Settings.Instrument instrument)
 {
     return(Price.CreateInstance(price, instrument.NumeratorUnit, instrument.Denominator));
 }
Beispiel #23
0
        private static bool TryFillExecutePrice(this Protocal.TransactionBookData bookData, Settings.Instrument instrument, Account account)
        {
            foreach (OrderBookData eachOrderBookData in bookData.Orders)
            {
                PhysicalOrderBookData eachPhysicalOrderBookData = (PhysicalOrderBookData)eachOrderBookData;
                if (eachPhysicalOrderBookData.PhysicalTradeSide == PhysicalTradeSide.Deposit || eachPhysicalOrderBookData.PhysicalTradeSide == PhysicalTradeSide.Delivery)
                {
                    if (eachOrderBookData.ExecutePrice != null)
                    {
                        continue;
                    }

                    string executePrice = null;
                    if (eachPhysicalOrderBookData.PhysicalTradeSide == PhysicalTradeSide.Deposit)
                    {
                        executePrice = instrument.DepositPrice;
                    }
                    else if (eachPhysicalOrderBookData.PhysicalTradeSide == PhysicalTradeSide.Delivery)
                    {
                        Guid            physicalRequestId = eachPhysicalOrderBookData.PhysicalRequestId.Value;
                        DeliveryRequest deliveryRequest   = null;
                        if (DeliveryRequestManager.Default.TryGet(physicalRequestId, out deliveryRequest))
                        {
                            executePrice = deliveryRequest.Ask;
                        }
                    }

                    if (string.IsNullOrEmpty(executePrice))
                    {
                        return(false);
                    }
                    eachPhysicalOrderBookData.ExecutePrice = executePrice;
                }
            }
            return(true);
        }
        internal static decimal CalculateLevy(TradePolicyDetail tradePolicyDetail, SpecialTradePolicyDetail specialTradePolicyDetail,
                                              CurrencyRate currencyRate, Settings.Account account, Settings.Instrument instrument, decimal contractSize, decimal closeLot, Price closePrice)
        {
            decimal levy = tradePolicyDetail.LevyClose;

            if (specialTradePolicyDetail != null && specialTradePolicyDetail.IsFractionLevyOn)
            {
                decimal fractionLevy = specialTradePolicyDetail.LevyClose;

                levy = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * levy, (int)closeLot, contractSize, closePrice, currencyRate)
                       + FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * fractionLevy, closeLot - (int)closeLot, contractSize, closePrice, currencyRate);
            }
            else
            {
                levy = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * levy, closeLot, contractSize, closePrice, currencyRate);
            }

            return(levy);
        }
        internal static decimal CalculateCommission(TradePolicyDetail tradePolicyDetail, SpecialTradePolicyDetail specialTradePolicyDetail,
                                                    CurrencyRate currencyRate, DateTime tradeDayBeginTime, Settings.Account account, Settings.Instrument instrument,
                                                    decimal contractSize, decimal pairRelationFactor, DateTime openOrderExecuteTime, decimal closeLot, Price closePrice)
        {
            bool    isDayCloseRelation = openOrderExecuteTime >= tradeDayBeginTime;
            decimal commission         = pairRelationFactor * tradePolicyDetail.GetCommissionClose(isDayCloseRelation);

            if (specialTradePolicyDetail != null && specialTradePolicyDetail.IsFractionCommissionOn)
            {
                decimal fractionCommission = pairRelationFactor * specialTradePolicyDetail.GetCommissionClose(isDayCloseRelation);

                commission = FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * commission, (int)closeLot, contractSize, closePrice, currencyRate)
                             + FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * fractionCommission, closeLot - (int)closeLot, contractSize, closePrice, currencyRate);
            }
            else
            {
                commission = FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * commission, closeLot, contractSize, closePrice, currencyRate);
            }

            return(commission);
        }
Beispiel #26
0
        private static Price CalculateForOrderLevelOpenPrice(Order order, decimal autoCloseThreshold, Settings.Instrument instrument, PriceType priceType)
        {
            Price basePrice           = order.ExecutePrice;
            int   autoClosePips       = (int)autoCloseThreshold;
            int   setPriceMaxMovePips = order.SetPriceMaxMovePips;

            if (setPriceMaxMovePips > 0 && setPriceMaxMovePips < autoClosePips)
            {
                autoClosePips = setPriceMaxMovePips;
            }

            bool isLimit = priceType == PriceType.Limit;

            if (order.IsBuy == isLimit)
            {
                return(Price.Add(basePrice, autoClosePips, !instrument.IsNormal));
            }
            else
            {
                return(Price.Subtract(basePrice, autoClosePips, !instrument.IsNormal));
            }
        }
        internal static void CalculateFee(TradePolicyDetail tradePolicyDetail, SpecialTradePolicyDetail specialTradePolicyDetail,
                                          CurrencyRate currencyRate, DateTime tradeDayBeginTime, Settings.Account account, Settings.Instrument instrument,
                                          decimal contractSize, decimal pairRelationFactor, DateTime openOrderExecuteTime, decimal closedLot, Price executePrice,
                                          out decimal commission, out decimal levy)
        {
            bool isDayCloseRelation = openOrderExecuteTime >= tradeDayBeginTime;

            commission = pairRelationFactor * tradePolicyDetail.GetCommissionClose(isDayCloseRelation);
            levy       = tradePolicyDetail.LevyClose;

            if (specialTradePolicyDetail != null && specialTradePolicyDetail.IsFractionCommissionOn)
            {
                decimal fractionCommission = pairRelationFactor * specialTradePolicyDetail.GetCommissionClose(isDayCloseRelation);

                commission = FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * commission, (int)closedLot, contractSize, executePrice, currencyRate)
                             + FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * fractionCommission, closedLot - (int)closedLot, contractSize, executePrice, currencyRate);
            }
            else
            {
                commission = FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * commission, closedLot, contractSize, executePrice, currencyRate);
            }

            if (specialTradePolicyDetail != null && specialTradePolicyDetail.IsFractionLevyOn)
            {
                decimal fractionLevy = specialTradePolicyDetail.LevyClose;

                levy = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * levy, (int)closedLot, contractSize, executePrice, currencyRate)
                       + FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * fractionLevy, closedLot - (int)closedLot, contractSize, executePrice, currencyRate);
            }
            else
            {
                levy = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * levy, closedLot, contractSize, executePrice, currencyRate);
            }
        }
Beispiel #28
0
 internal TradeDayPrice(Price ask, Price bid, Settings.Instrument instrument)
 {
     _buyPrice  = bid;
     _sellPrice = ask;
 }
Beispiel #29
0
 internal AlertInstrument(Settings.Instrument instrument)
 {
     _instrument = instrument;
 }
Beispiel #30
0
        internal static CurrencyRate GetCGSELevyCurrencyRate(Settings.Account account, Settings.Instrument instrument, SpecialTradePolicyDetail specialTradePolicyDetail, CurrencyRate defaultCurrencyRate, ExecuteContext context)
        {
            if (specialTradePolicyDetail.CGSELevyCurrecyType == CGSELevyCurrecyType.UseInstrumentCurrencyType)
            {
                return(defaultCurrencyRate);
            }
            else
            {
                Guid sourceCurrencyId = account.CurrencyId;
                Guid targetCurrencyId = account.IsMultiCurrency ? instrument.CurrencyId : account.CurrencyId;

                return(context != null && context.ShouldUseHistorySettings ? Settings.Setting.Default.GetCurrencyRate(sourceCurrencyId, targetCurrencyId, context.TradeDay)
                                                                            : Settings.Setting.Default.GetCurrencyRate(sourceCurrencyId, targetCurrencyId));
            }
        }