Esempio n. 1
0
 /// <summary>
 /// Temporary convenience constructor
 /// </summary>
 protected Security(SubscriptionDataConfig config,
                    Cash quoteCurrency,
                    SymbolProperties symbolProperties,
                    SecurityExchange exchange,
                    SecurityCache cache,
                    ISecurityPortfolioModel portfolioModel,
                    IFillModel fillModel,
                    IFeeModel feeModel,
                    ISlippageModel slippageModel,
                    ISettlementModel settlementModel,
                    IVolatilityModel volatilityModel,
                    IBuyingPowerModel buyingPowerModel,
                    ISecurityDataFilter dataFilter,
                    IPriceVariationModel priceVariationModel
                    )
     : this(config.Symbol,
            quoteCurrency,
            symbolProperties,
            exchange,
            cache,
            portfolioModel,
            fillModel,
            feeModel,
            slippageModel,
            settlementModel,
            volatilityModel,
            buyingPowerModel,
            dataFilter,
            priceVariationModel
            )
 {
     SubscriptionsBag.Add(config);
     UpdateSubscriptionProperties();
 }
Esempio n. 2
0
        public void Initialize()
        {
            _feeModel = GetFeeModel();
            SetBrokerageFees();
            var spdb = SymbolPropertiesDatabase.FromDataFolder();
            var tz   = TimeZones.Utc;

            _xrpusdt = new Crypto(
                SecurityExchangeHours.AlwaysOpen(tz),
                new Cash("USDT", 0, 1),
                new SubscriptionDataConfig(typeof(TradeBar), Symbol.Create("XRPUSDT", SecurityType.Crypto, Market.FTX), Resolution.Minute, tz, tz, true, false, false),
                spdb.GetSymbolProperties(Market.FTX, Symbol.Create("XRPUSDT", SecurityType.Crypto, Market.FTX), SecurityType.Crypto, "USDT"),
                ErrorCurrencyConverter.Instance,
                RegisteredSecurityDataTypesProvider.Null
                );
            _xrpusdt.SetMarketPrice(new Tick(DateTime.UtcNow, _xrpusdt.Symbol, 100, 100));

            _ethusd = new Crypto(
                SecurityExchangeHours.AlwaysOpen(tz),
                new Cash(Currencies.USD, 0, 10),
                new SubscriptionDataConfig(typeof(TradeBar), Symbol.Create("ETHUSD", SecurityType.Crypto, Market.FTX), Resolution.Minute, tz, tz, true, false, false),
                spdb.GetSymbolProperties(Market.FTX, Symbol.Create("ETHUSD", SecurityType.Crypto, Market.FTX), SecurityType.Crypto, Currencies.USD),
                ErrorCurrencyConverter.Instance,
                RegisteredSecurityDataTypesProvider.Null
                );
            _ethusd.SetMarketPrice(new Tick(DateTime.UtcNow, _ethusd.Symbol, 100, 100));
        }
Esempio n. 3
0
 /// <summary>
 /// Temporary convenience constructor
 /// </summary>
 protected Security(SubscriptionDataConfig config,
                    Cash quoteCurrency,
                    SymbolProperties symbolProperties,
                    SecurityExchange exchange,
                    SecurityCache cache,
                    ISecurityPortfolioModel portfolioModel,
                    IFillModel fillModel,
                    IFeeModel feeModel,
                    ISlippageModel slippageModel,
                    ISettlementModel settlementModel,
                    IVolatilityModel volatilityModel,
                    ISecurityMarginModel marginModel,
                    ISecurityDataFilter dataFilter
                    )
     : this(config.Symbol,
            quoteCurrency,
            symbolProperties,
            exchange,
            cache,
            portfolioModel,
            fillModel,
            feeModel,
            slippageModel,
            settlementModel,
            volatilityModel,
            marginModel,
            dataFilter
            )
 {
     SubscriptionsBag.Add(config);
 }
Esempio n. 4
0
        /// <summary>
        /// Gets the order fee associated with the specified order. This returns the cost
        /// of the transaction in the account currency
        /// </summary>
        /// <param name="model">The fee model</param>
        /// <param name="security">The security matching the order</param>
        /// <param name="order">The order to compute fees for</param>
        /// <returns>The cost of the order in units of the account currency</returns>
        public static decimal GetOrderFee(this IFeeModel model, Security security, Order order)
        {
            var parameters = new OrderFeeParameters(security, order, security.QuoteCurrency.Symbol);
            var fee        = model.GetOrderFee(parameters);

            return(fee.Value.Amount);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the order fee associated with the specified order. This returns the cost
        /// of the transaction in the account currency
        /// </summary>
        /// <param name="model">The fee model</param>
        /// <param name="security">The security matching the order</param>
        /// <param name="order">The order to compute fees for</param>
        /// <returns>The cost of the order in units of the account currency</returns>
        public static decimal GetOrderFee(this IFeeModel model, Security security, Order order)
        {
            var parameters = new OrderFeeParameters(security, order);
            var fee        = model.GetOrderFee(parameters);

            if (fee.Value.Currency != security.QuoteCurrency.AccountCurrency)
            {
                throw new InvalidOperationException("The GetOrderFee extension method is only valid" +
                                                    " for fee models returning fees in the account currency");
            }
            return(fee.Value.Amount);
        }
Esempio n. 6
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(Symbol symbol,
                           Cash quoteCurrency,
                           SymbolProperties symbolProperties,
                           SecurityExchange exchange,
                           SecurityCache cache,
                           ISecurityPortfolioModel portfolioModel,
                           IFillModel fillModel,
                           IFeeModel feeModel,
                           ISlippageModel slippageModel,
                           ISettlementModel settlementModel,
                           IVolatilityModel volatilityModel,
                           IBuyingPowerModel buyingPowerModel,
                           ISecurityDataFilter dataFilter,
                           IPriceVariationModel priceVariationModel,
                           ICurrencyConverter currencyConverter,
                           IRegisteredSecurityDataTypesProvider registeredTypesProvider
                           )
        {
            if (symbolProperties == null)
            {
                throw new ArgumentNullException(nameof(symbolProperties), "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            this._currencyConverter = currencyConverter;

            Symbol              = symbol;
            SubscriptionsBag    = new ConcurrentBag <SubscriptionDataConfig>();
            QuoteCurrency       = quoteCurrency;
            SymbolProperties    = symbolProperties;
            IsTradable          = true;
            Cache               = cache;
            Exchange            = exchange;
            DataFilter          = dataFilter;
            PriceVariationModel = priceVariationModel;
            PortfolioModel      = portfolioModel;
            BuyingPowerModel    = buyingPowerModel;
            FillModel           = fillModel;
            FeeModel            = feeModel;
            SlippageModel       = slippageModel;
            SettlementModel     = settlementModel;
            VolatilityModel     = volatilityModel;
            Holdings            = new SecurityHolding(this, currencyConverter);
            Data              = new DynamicSecurityData(registeredTypesProvider);
            Cache.DataStored += (sender, args) => Data.StoreData(args.DataType, args.Data);

            UpdateSubscriptionProperties();
        }
Esempio n. 7
0
        public ActionResult <OrderDTO> Confirm(
            [FromServices] IFeeModel feeModel,
            OrderDTO orderDTO)
        {
            if (DataHelper.IsEmptyString(orderDTO.OrderItems))
            {
                return(BadRequest());
            }
            //Parse list order Item
            var orderDetailDTOs = DataHelper.ParserJsonTo <List <OrderDetailDTO> >(orderDTO.OrderItems);
            var pramOrder       = _orderModel.GetPramOrder(orderDetailDTOs);
            //
            double promBill   = 0;
            double promMethod = 0;
            // double promPoint = 0;
            int point = 0;
            //bills
            var bills = _promModel.GetListDTOsPromBill();

            if (bills != null || bills?.Count > 0)
            {
                promBill = _orderModel.FindPromBill(pramOrder.Item2, pramOrder.Item1, bills);
            }
            //point
            // var points = _promModel.GetListDTOsPromPoint();
            // if (points != null || points?.Count > 0)
            // {
            //     if (orderDTO.PointUse != 0)
            //         promPoint = _orderModel.FindPromPoint((int)orderDTO.PointUse, points);
            //     point = _orderModel.GetdPoint(pramOrder.Item2, points);
            // }
            //Get point
            var fees = feeModel.GetListDTOs();

            if (fees != null || fees.Count > 0)
            {
                orderDTO.Fees = DataHelper.ParserObjToJson(fees);
            }
            orderDTO.Point     = point;
            orderDTO.Promotion = DataHelper.ParserObjToJson(new
            {
                bill      = promBill,
                methodPay = promMethod,
                // promPoint = promPoint
            });
            return(orderDTO);
        }
Esempio n. 8
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(Symbol symbol,
                           Cash quoteCurrency,
                           SymbolProperties symbolProperties,
                           SecurityExchange exchange,
                           SecurityCache cache,
                           ISecurityPortfolioModel portfolioModel,
                           IFillModel fillModel,
                           IFeeModel feeModel,
                           ISlippageModel slippageModel,
                           ISettlementModel settlementModel,
                           IVolatilityModel volatilityModel,
                           IBuyingPowerModel buyingPowerModel,
                           ISecurityDataFilter dataFilter,
                           IPriceVariationModel priceVariationModel
                           )
        {
            if (symbolProperties == null)
            {
                throw new ArgumentNullException("symbolProperties", "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            Symbol              = symbol;
            SubscriptionsBag    = new ConcurrentBag <SubscriptionDataConfig>();
            QuoteCurrency       = quoteCurrency;
            SymbolProperties    = symbolProperties;
            IsTradable          = true;
            Cache               = cache;
            Exchange            = exchange;
            DataFilter          = dataFilter;
            PriceVariationModel = priceVariationModel;
            PortfolioModel      = portfolioModel;
            BuyingPowerModel    = buyingPowerModel;
            FillModel           = fillModel;
            FeeModel            = feeModel;
            SlippageModel       = slippageModel;
            SettlementModel     = settlementModel;
            VolatilityModel     = volatilityModel;
            Holdings            = new SecurityHolding(this);

            UpdateSubscriptionProperties();
        }
Esempio n. 9
0
 /// <summary>
 /// Creates instance of the Option class.
 /// </summary>
 /// <remarks>
 /// Allows for the forwarding of the security configuration to the
 /// base Security constructor
 /// </remarks>
 protected Option(Symbol symbol,
                  Cash quoteCurrency,
                  SymbolProperties symbolProperties,
                  SecurityExchange exchange,
                  SecurityCache cache,
                  ISecurityPortfolioModel portfolioModel,
                  IFillModel fillModel,
                  IFeeModel feeModel,
                  ISlippageModel slippageModel,
                  ISettlementModel settlementModel,
                  IVolatilityModel volatilityModel,
                  IBuyingPowerModel buyingPowerModel,
                  ISecurityDataFilter dataFilter,
                  IPriceVariationModel priceVariationModel,
                  ICurrencyConverter currencyConverter,
                  IRegisteredSecurityDataTypesProvider registeredTypesProvider,
                  Security underlying
                  ) : base(
         symbol,
         quoteCurrency,
         symbolProperties,
         exchange,
         cache,
         portfolioModel,
         fillModel,
         feeModel,
         slippageModel,
         settlementModel,
         volatilityModel,
         buyingPowerModel,
         dataFilter,
         priceVariationModel,
         currencyConverter,
         registeredTypesProvider
         )
 {
     ExerciseSettlement = SettlementType.PhysicalDelivery;
     SetDataNormalizationMode(DataNormalizationMode.Raw);
     OptionExerciseModel = new DefaultExerciseModel();
     PriceModel          = new CurrentPriceOptionPriceModel();
     Holdings            = new OptionHolding(this, currencyConverter);
     _symbolProperties   = (OptionSymbolProperties)symbolProperties;
     SetFilter(-1, 1, TimeSpan.Zero, TimeSpan.FromDays(35));
     Underlying = underlying;
 }
Esempio n. 10
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(SubscriptionDataConfig config,
                           Cash quoteCurrency,
                           SymbolProperties symbolProperties,
                           SecurityExchange exchange,
                           SecurityCache cache,
                           ISecurityPortfolioModel portfolioModel,
                           IFillModel fillModel,
                           IFeeModel feeModel,
                           ISlippageModel slippageModel,
                           ISettlementModel settlementModel,
                           IVolatilityModel volatilityModel,
                           ISecurityMarginModel marginModel,
                           ISecurityDataFilter dataFilter
                           )
        {
            if (symbolProperties == null)
            {
                throw new ArgumentNullException("symbolProperties", "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            _config          = config;
            QuoteCurrency    = quoteCurrency;
            SymbolProperties = symbolProperties;
            IsTradable       = !config.IsInternalFeed;
            Cache            = cache;
            Exchange         = exchange;
            DataFilter       = dataFilter;
            PortfolioModel   = portfolioModel;
            MarginModel      = marginModel;
            FillModel        = fillModel;
            FeeModel         = feeModel;
            SlippageModel    = slippageModel;
            SettlementModel  = settlementModel;
            VolatilityModel  = volatilityModel;
            Holdings         = new SecurityHolding(this);
        }
Esempio n. 11
0
 /// <summary>
 /// Construct a new security vehicle based on the user options.
 /// </summary>
 protected Security(SubscriptionDataConfig config,
                    SecurityExchange exchange,
                    SecurityCache cache,
                    ISecurityPortfolioModel portfolioModel,
                    IFillModel fillModel,
                    IFeeModel feeModel,
                    ISlippageModel slippageModel,
                    ISettlementModel settlementModel,
                    ISecurityMarginModel marginModel,
                    ISecurityDataFilter dataFilter
                    )
 {
     _config         = config;
     Cache           = cache;
     Exchange        = exchange;
     DataFilter      = dataFilter;
     PortfolioModel  = portfolioModel;
     MarginModel     = marginModel;
     FillModel       = fillModel;
     FeeModel        = feeModel;
     SlippageModel   = slippageModel;
     SettlementModel = settlementModel;
     Holdings        = new SecurityHolding(this);
 }
Esempio n. 12
0
 public FeeController(IFeeModel feeModel, ICacheHelper cache)
 {
     _feeModel = feeModel;
     _cache    = cache;
 }
Esempio n. 13
0
 /// <summary>
 /// Initializes a new default instance of the <see cref="SecurityTransactionModel"/> class.
 /// This will use default slippage and fill models.
 /// </summary>
 public SecurityTransactionModel()
 {
     _slippageModel = new SpreadSlippageModel();
     _fillModel = new ImmediateFillModel();
     _feeModel = new ConstantFeeModel(0);
 }
Esempio n. 14
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(SubscriptionDataConfig config,
            Cash quoteCurrency,
            SymbolProperties symbolProperties,
            SecurityExchange exchange,
            SecurityCache cache,
            ISecurityPortfolioModel portfolioModel,
            IFillModel fillModel,
            IFeeModel feeModel,
            ISlippageModel slippageModel,
            ISettlementModel settlementModel,
            ISecurityMarginModel marginModel,
            ISecurityDataFilter dataFilter
            )
        {

            if (symbolProperties == null)
            {
                throw new ArgumentNullException("symbolProperties", "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            _config = config;
            QuoteCurrency = quoteCurrency;
            SymbolProperties = symbolProperties;
            Cache = cache;
            Exchange = exchange;
            DataFilter = dataFilter;
            PortfolioModel = portfolioModel;
            MarginModel = marginModel;
            FillModel = fillModel;
            FeeModel = feeModel;
            SlippageModel = slippageModel;
            SettlementModel = settlementModel;
            Holdings = new SecurityHolding(this);
        }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SecurityTransactionManager"/> class
 /// </summary>
 /// <param name="fillModel">The fill model to use</param>
 /// <param name="feeModel">The order fee model to use</param>
 /// <param name="slippageModel">The slippage model to use</param>
 public SecurityTransactionModel(IFillModel fillModel, IFeeModel feeModel, ISlippageModel slippageModel)
 {
     _fillModel     = fillModel;
     _feeModel      = feeModel;
     _slippageModel = slippageModel;
 }
Esempio n. 16
0
 /// <summary>
 /// Initializes a new default instance of the <see cref="SecurityTransactionModel"/> class.
 /// This will use default slippage and fill models.
 /// </summary>
 public SecurityTransactionModel()
 {
     _slippageModel = new SpreadSlippageModel();
     _fillModel     = new ImmediateFillModel();
     _feeModel      = new ConstantFeeModel(0);
 }
Esempio n. 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SecurityTransactionManager"/> class
 /// </summary>
 /// <param name="fillModel">The fill model to use</param>
 /// <param name="feeModel">The order fee model to use</param>
 /// <param name="slippageModel">The slippage model to use</param>
 public SecurityTransactionModel(IFillModel fillModel, IFeeModel feeModel, ISlippageModel slippageModel)
 {
     _fillModel = fillModel;
     _feeModel = feeModel;
     _slippageModel = slippageModel;
 }
Esempio n. 18
0
 /// <summary>
 /// Construct a new security vehicle based on the user options.
 /// </summary>
 protected Security(SubscriptionDataConfig config,
     SecurityExchange exchange,
     SecurityCache cache,
     ISecurityPortfolioModel portfolioModel,
     IFillModel fillModel,
     IFeeModel feeModel,
     ISlippageModel slippageModel,
     ISettlementModel settlementModel,
     ISecurityMarginModel marginModel,
     ISecurityDataFilter dataFilter
     )
 {
     _config = config;
     Cache = cache;
     Exchange = exchange;
     DataFilter = dataFilter;
     PortfolioModel = portfolioModel;
     MarginModel = marginModel;
     FillModel = fillModel;
     FeeModel = feeModel;
     SlippageModel = slippageModel;
     SettlementModel = settlementModel;
     Holdings = new SecurityHolding(this);
 }
Esempio n. 19
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(Symbol symbol,
            Cash quoteCurrency,
            SymbolProperties symbolProperties,
            SecurityExchange exchange,
            SecurityCache cache,
            ISecurityPortfolioModel portfolioModel,
            IFillModel fillModel,
            IFeeModel feeModel,
            ISlippageModel slippageModel,
            ISettlementModel settlementModel,
            IVolatilityModel volatilityModel,
            ISecurityMarginModel marginModel,
            ISecurityDataFilter dataFilter,
            IPriceVariationModel priceVariationModel
            )
        {

            if (symbolProperties == null)
            {
                throw new ArgumentNullException("symbolProperties", "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            _symbol = symbol;
            SubscriptionsBag = new ConcurrentBag<SubscriptionDataConfig>();
            QuoteCurrency = quoteCurrency;
            SymbolProperties = symbolProperties;
            IsTradable = true;
            Cache = cache;
            Exchange = exchange;
            DataFilter = dataFilter;
            PriceVariationModel = priceVariationModel;
            PortfolioModel = portfolioModel;
            MarginModel = marginModel;
            FillModel = fillModel;
            FeeModel = feeModel;
            SlippageModel = slippageModel;
            SettlementModel = settlementModel;
            VolatilityModel = volatilityModel;
            Holdings = new SecurityHolding(this);
        }
Esempio n. 20
0
 /// <summary>
 /// Sets the fee model
 /// </summary>
 /// <param name="feelModel">Model that represents a fee model</param>
 public void SetFeeModel(IFeeModel feelModel)
 {
     FeeModel = feelModel;
 }
Esempio n. 21
0
 /// <summary>
 /// Temporary convenience constructor
 /// </summary>
 protected Security(SubscriptionDataConfig config,
     Cash quoteCurrency,
     SymbolProperties symbolProperties,
     SecurityExchange exchange,
     SecurityCache cache,
     ISecurityPortfolioModel portfolioModel,
     IFillModel fillModel,
     IFeeModel feeModel,
     ISlippageModel slippageModel,
     ISettlementModel settlementModel,
     IVolatilityModel volatilityModel,
     ISecurityMarginModel marginModel,
     ISecurityDataFilter dataFilter
     )
     : this(config.Symbol,
         quoteCurrency,
         symbolProperties,
         exchange,
         cache,
         portfolioModel,
         fillModel,
         feeModel,
         slippageModel,
         settlementModel,
         volatilityModel,
         marginModel,
         dataFilter
         )
 {
     SubscriptionsBag.Add(config);
 }