Esempio n. 1
0
        /// <summary>
        /// Base implementation for a security object
        /// </summary>
        /// <param name="ticker"></param>
        /// <param name="exchangeModel"></param>
        /// <param name="details"></param>
        /// <param name="type"></param>
        /// <param name="conversion"></param>
        protected SecurityBase(TickerSymbol ticker, ExchangeModel exchangeModel, SecurityDetails details, SecurityType type, Currency conversion)
        {
            //Set references
            _currencyConversion = conversion;
            Exchange            = exchangeModel;
            BaseCurrency        = ticker.Currency;
            Details             = details;
            Ticker = ticker;
            Type   = type;

            //Defaults
            LastTickEventUtc  = DateTime.MinValue;
            LastTradeEventUtc = DateTime.MinValue;
        }
Esempio n. 2
0
 /// <summary>
 /// Create new Equity Security information
 /// </summary>
 /// <param name="ticker"></param>
 /// <param name="exchangeModel"></param>
 /// <param name="details"></param>
 /// <param name="conversion"></param>
 public EquitySecurity(TickerSymbol ticker, ExchangeModel exchangeModel, SecurityDetails details, Currency conversion)
     : base(ticker, exchangeModel, details, SecurityType.Equity, conversion)
 {
 }
Esempio n. 3
0
        /// <summary>
        /// Creates a security object based on requested security point
        /// </summary>
        /// <param name="tickername"></param>
        /// <returns></returns>
        public Security Create(string tickername)
        {
            //Set default details
            var details = SecurityDetails.NIL();

            //Get config
            var configured = Config.SecurityConfig.FirstOrDefault(x => x.Ticker == tickername);

            if (configured == null)
            {
                return(new UnknownSecurity(tickername));
            }

            //Get security type
            if (!Enum.TryParse(configured.Type, out SecurityType securitytype))
            {
                securitytype = SecurityType.NIL;
            }

            //Get Exchnage
            ExchangeModel exchangeModel = _exchangeModels.FirstOrDefault(x => x.Name == configured.Exchange);

            if (exchangeModel == null)
            {
                _log.Error(
                    $"Exchange with name {configured.Exchange} is not loaded, cannot load security {tickername}. This security is marked as unknown.");
                return(new UnknownSecurity(tickername));
            }

            //Convert
            CurrencyType basecurrency = (CurrencyType)Enum.Parse(typeof(CurrencyType), configured.Currency);

            //Get commodity
            string commodity = configured.Commodity;

            //Create security
            SecurityBase toreturn;

            switch (securitytype)
            {
            case SecurityType.NIL:
                return(new UnknownSecurity(tickername));

            case SecurityType.Equity:
                toreturn = new EquitySecurity(new TickerSymbol(tickername, commodity, basecurrency), exchangeModel, details, _currency);
                break;

            case SecurityType.Crypto:
                toreturn = GetCryptoCurrency(tickername, commodity, exchangeModel, details);
                break;

            default:
                return(new UnknownSecurity(tickername));
            }

            //Check if security is known by broker model
            try
            {
                if (!_brokerModel.IsSecuritySupported(toreturn))
                {
                    _log.Warn($"Security with ticker {tickername} is not supported by broker, it is marked as unknown");
                    return(new UnknownSecurity(tickername));
                }
            }
            catch (Exception exc)
            {
                _log.Error(exc, $"Error while invoking broker model IsSecuritySupported for security with ticker name {tickername}");
                return(new UnknownSecurity(tickername));
            }

            //Set details
            toreturn.Details = _brokerModel.GetSecurityDetails(toreturn);

            //Return what we have
            return(toreturn);
        }
Esempio n. 4
0
 /// <summary>
 /// Create unknown security type, cannot be used anywhere
 /// </summary>
 /// <param name="ticker"></param>
 public UnknownSecurity(string ticker)
     : base(TickerSymbol.NIL(ticker), null, SecurityDetails.NIL(), SecurityType.NIL, null)
 {
 }
Esempio n. 5
0
        /// <summary>
        /// Gets the crypto currency.
        /// </summary>
        /// <param name="tickername">The ticker name.</param>
        /// <param name="commodity"></param>
        /// <param name="exchangeModel">The exchangeModel.</param>
        /// <param name="details">The details.</param>
        /// <returns></returns>
        private SecurityBase GetCryptoCurrency(string tickername, string commodity, ExchangeModel exchangeModel, SecurityDetails details)
        {
            //Get all tickers associated to this crypto currency from config, for this broker model
            var configured = Config.SecurityConfig.Where(x => String.Equals(x.Ticker, tickername, StringComparison.CurrentCultureIgnoreCase) &&
                                                         String.Equals(x.Exchange, exchangeModel.Name, StringComparison.CurrentCultureIgnoreCase) &&
                                                         x.Brokers.Select(b => b.ToLower()).Contains(_brokerModel.BrokerType.ToString().ToLower()))
                             .ToArray();

            //Check if we have items
            if (!configured.Any())
            {
                return(new UnknownSecurity(tickername));
            }

            //Get shortest path for this currency for the account currency
            var found = configured.FirstOrDefault(x => String.Equals(x.Currency, _accountcurrency.ToString(), StringComparison.CurrentCultureIgnoreCase)) ?? configured.FirstOrDefault();

            //Return what we have
            if (found != null)
            {
                var basecurrency = (CurrencyType)Enum.Parse(typeof(CurrencyType), found.Currency);
                return(new CryptoSecurity(new TickerSymbol(tickername, commodity, basecurrency), exchangeModel, details, _currency));
            }
            else
            {
                return(new UnknownSecurity(tickername));
            }
        }