public StockHandle(TradedStock ts) { myHandle = ts; // TODO: have two factory methods? one to load on demand the other to create in memory? // the object context of the given traded stock will be disposed later on. // then we cannot access any property which requires the object context - e.g. // references that has not been loaded yet // - only check if attached to object context if (myHandle.EntityState == System.Data.EntityState.Unchanged || myHandle.EntityState == System.Data.EntityState.Modified) { if (myHandle.Stock == null) { myHandle.StockReference.Load(); } if (myHandle.StockExchange == null) { myHandle.StockExchangeReference.Load(); } if (myHandle.StockExchange.Currency == null) { myHandle.StockExchange.CurrencyReference.Load(); } if (myHandle.Stock.Company == null) { myHandle.Stock.CompanyReference.Load(); } } }
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 ); }
public StockPrice(TradedStock ts, DateTime date, double?open, double?high, double?low, double close, long?volume) { TradedStock = ts; Date = date; Open = open; High = high; Low = low; Close = close; Volume = volume; }
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 ); }
public Order( TradedStock code, string source ) { Source = source; TradedStock = code; }
public Order( TradedStock code ) : this(code, null) { }
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 ); }
public Order(TradedStock code, string source) { Source = source; TradedStock = code; }
public Order(TradedStock code) : this(code, null) { }
public StockPrice(long id, TradedStock ts, DateTime date, double?open, double?high, double?low, double close, long?volume) : this(ts, date, open, high, low, close, volume) { Id = id; }
/// <summary> /// Deprecated Method for adding a new object to the TradedStocks EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToTradedStocks(TradedStock tradedStock) { base.AddObject("TradedStocks", tradedStock); }
/// <summary> /// Create a new TradedStock object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="symbol">Initial value of the Symbol property.</param> public static TradedStock CreateTradedStock(global::System.Int64 id, global::System.String symbol) { TradedStock tradedStock = new TradedStock(); tradedStock.Id = id; tradedStock.Symbol = symbol; return tradedStock; }
// 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 ); } }
private static StockHandle GetOrCreateInternal <TPolicy>(Dictionary <string, string> args_in) where TPolicy : IScalarPolicy, new() { var args = args_in.ToDictionary(pair => pair.Key.ToLower(), pair => pair.Value); var GetPolicy = NMemorize.Cache(() => new TPolicy()); using (var tom = Engine.ServiceProvider.CreateEntityRepository()) { // lets try to find s.th. in DB first IEnumerable <TradedStock> tradedStocks = null; if (args.ContainsKey("isin")) { tradedStocks = tom.TradedStocks.FindByIsin(args["isin"]); } if (tradedStocks == null && args.ContainsKey("wpkn")) { tradedStocks = tom.TradedStocks.FindByWpkn(args["wpkn"]); } if (tradedStocks == null && args.ContainsKey("symbol")) { tradedStocks = tom.TradedStocks.FindBySymbol(args["symbol"]); } if (tradedStocks != null && tradedStocks.Any()) { // always filter so that we can check wether all given // parameters fit well var filteredTradedStocks = tradedStocks.Where(ts => (!args.ContainsKey("wpkn") || ts.Wpkn == args["wpkn"]) && (!args.ContainsKey("symbol") || ts.Symbol == args["symbol"])); if (filteredTradedStocks.Any()) { return(new StockHandle(GetPolicy().Single(filteredTradedStocks))); } } // ok we did not find anything so lets create a new stock // check required keys if (!args.ContainsKey("isin")) { throw new ArgumentException("Isin required when creating new stocks"); } if (!args.ContainsKey("symbol")) { throw new ArgumentException("Symbol required when creating new stocks"); } if (!(args.ContainsKey("exchange") || args.ContainsKey("stockexchange"))) { throw new ArgumentException("Exchange/StockExchange required when creating new stocks"); } if (!(args.ContainsKey("name") || args.ContainsKey("companyname"))) { throw new ArgumentException("Name/CompanyName required when creating new stocks"); } var companyName = GetOrDefault(args, "name") ?? GetOrDefault(args, "companyname"); var company = tom.Companies.GetOrCreate <TPolicy>(companyName); var stock = new Stock(company, args["isin"]); tom.Stocks.AddObject(stock); var exchange = GetOrDefault(args, "exchange") ?? GetOrDefault(args, "stockexchange"); var se = tom.StockExchanges.FindBySymbolOrName(exchange); if (se == null) { throw new InvalidOperationException("Could not find StockExchange by symbol or name with: " + exchange); } var tradedStock = new TradedStock(stock, se) { Wpkn = GetOrDefault(args, "wpkn"), Symbol = GetOrDefault(args, "symbol") }; tom.TradedStocks.AddObject(tradedStock); tom.SaveChanges(); return(new StockHandle(tradedStock)); } }