Exemplo n.º 1
0
        public static StockHandle CreateStockHandle( string companyName, string isin, string currency )
        {
            var company = new Company( companyName );
            var stock = new Stock( company, isin );
            var exchange = new StockExchange( "Xetra", "DE", new Currency( currency, currency ) );
            var tradedStock = new TradedStock( stock, exchange );

            return new StockHandle( tradedStock );
        }
Exemplo n.º 2
0
        private void AddStock()
        {
            var stock = new Stock();
            stock.Isin = myIsinTxt.Text;
            stock.Company = new Company();
            stock.Company.Name = myCompanyNameTxt.Text;

            var tradedStock = new TradedStock( stock, myTom.StockExchanges.First( se => se.Symbol == "F" ) );
            tradedStock.Symbol = mySymbolTxt.Text;
            tradedStock.Wpkn = myWpknTxt.Text;

            myTom.Stocks.AddObject( stock );
        }
Exemplo n.º 3
0
        protected void AddDummyStock(string isin)
        {
            var company = new Company( "C" );
            var stock = new Stock( company, isin );
            var exchange = new StockExchange( "Xetra", "De", new Currency( "Euro", "Euro" ) );
            var tradedStock = new TradedStock( stock, exchange );

            Interpreter.Context.Scope.Stock = new StockHandle( tradedStock );
        }
Exemplo n.º 4
0
        private void ShowStock( Stock stock )
        {
            if ( stock.EntityState != EntityState.Detached && stock.EntityState != EntityState.Added )
            {
                stock.CompanyReference.Load();
                stock.TradedStocks.Load();
            }

            if ( stock.TradedStocks.Count == 0 )
            {
                throw new ArgumentException( "TradedStock missing" );
            }
            if ( stock.TradedStocks.Count > 1 )
            {
                throw new ArgumentException( "Cannot handle multiple TradedStocks" );
            }

            var tradedStock = stock.TradedStocks.Single();

            mySymbolTxt.Text = tradedStock.Symbol;
            myWpknTxt.Text = tradedStock.Wpkn;
            myCompanyNameTxt.Text = stock.Company.Name;
        }
Exemplo n.º 5
0
 public TradedStock( Stock stock, StockExchange se )
 {
     Stock = stock;
     StockExchange = se;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Stocks EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToStocks(Stock stock)
 {
     base.AddObject("Stocks", stock);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Create a new Stock object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="isin">Initial value of the Isin property.</param>
 /// <param name="rawType">Initial value of the RawType property.</param>
 public static Stock CreateStock(global::System.Int64 id, global::System.String isin, global::System.Int64 rawType)
 {
     Stock stock = new Stock();
     stock.Id = id;
     stock.Isin = isin;
     stock.RawType = rawType;
     return stock;
 }
Exemplo n.º 8
0
        // TODO: dublicate of Functions.Stocks.GetOrCreateStock() but we first need some
        // kind of protocol (for user and developer) before we can remove this code here
        public StockHandle Create( StockDescriptor stockDescriptor )
        {
            if ( stockDescriptor.Isin.IsNullOrTrimmedEmpty() )
            {
                throw new ArgumentException( "Isin not set" );
            }
            if ( stockDescriptor.StockExchange.IsNullOrTrimmedEmpty() )
            {
                throw new ArgumentException( "Stock exchange not set" );
            }

            myLogger.Notice( "Creating stock: {0}", stockDescriptor.Isin );

            using ( var tom = Engine.ServiceProvider.CreateEntityRepository() )
            {
                var tradedStock = tom.TradedStocks.FindTradedStockByDescription( stockDescriptor );
                if ( tradedStock != null )
                {
                    var sh = new StockHandle( tradedStock );

                    myLogger.Info( "Stock already exists: Company = {0},Isin = {1}, Symbol = {2}, Exchange = {3}",
                        sh.Company.Name, stockDescriptor.Isin, sh.TradedStock.Symbol, stockDescriptor.StockExchange );

                    return sh;
                }

                // TODO: this is somehow duplicate code from StockHandle.GetOrCreate - remove StockHandle.GetOrCreate

                // ok - so no traded stock available for the given description - but maybe a stock is already there?
                var stock = tom.Stocks.FirstOrDefault( s => s.Isin == stockDescriptor.Isin );
                if ( stock == null )
                {
                    var companyName = stockDescriptor.Name;
                    if ( companyName.IsNullOrTrimmedEmpty() )
                    {
                        companyName = DatumLocatorDefinitions.Standing.CompanyName.FetchSingle<string>( stockDescriptor.Isin ).Value;
                    }

                    // company name is not uniq enough so lets create a new one
                    var company = new Company( companyName );
                    stock = new Stock( company, stockDescriptor.Isin );
                }

                // we got a stock so lets create a traded stock - we already checked that there is none

                // but first we need a stockexchange
                var se = tom.StockExchanges.FindBySymbolOrName( stockDescriptor.StockExchange );
                if ( se == null )
                {
                    throw new InvalidOperationException( "Could not find StockExchange by symbol or name with: " + stockDescriptor.StockExchange );
                }

                var symbol = stockDescriptor.Symbol;
                if ( symbol.IsNullOrTrimmedEmpty() )
                {
                    symbol = DatumLocatorDefinitions.Standing.StockSymbol.FetchSingle<string>( stockDescriptor.Isin ).Value;
                }
                var wpkn = DatumLocatorDefinitions.Standing.Wpkn.FetchSingle<string>( stockDescriptor.Isin ).Value;

                tradedStock = new TradedStock( stock, se );
                tradedStock.Symbol = symbol;
                tradedStock.Wpkn = wpkn;

                tom.TradedStocks.AddObject( tradedStock );

                tom.SaveChanges();

                myLogger.Info( "Created stock with: Company = {0},Isin = {1}, Symbol = {2}, Exchange = {3}",
                    stock.Company.Name, stock.Isin, symbol, stockDescriptor.StockExchange );

                return new StockHandle( tradedStock );
            }
        }