示例#1
0
        public static IAppHost AddTrading(this IAppHost appHost, TradingOptions defaultOptions = null, AccountMode accountModesAllowed = AccountMode.Unspecified)
        {
            if (defaultOptions == null)
            {
                defaultOptions = DefaultTradingOptions;
            }

            // FUTURE: find another way to get this to app during ConfigureServices
            //TypeNamingContext tnc = ManualSingleton<TypeNamingContext>.GuaranteedInstance;
            //tnc.UseShortNamesForDataAssemblies = true;

            PrioritizeAndThrottleDataJobs();

            appHost.ConfigureServices((Action <IServiceCollection>)(serviceCollection =>
            {
                //var Configuration = LionFire.Structures.ManualSingleton<IConfigurationRoot>.Instance;
                //serviceCollection.Configure<TradingOptions>(opt => Configuration.GetSection("Trading").Bind(opt));

                //app.ServiceCollection.AddSingleton<IAccountProvider, AccountProvider>(); FUTURE
#if TOPORT
                var tradingOptions = "Default".Load <TradingOptions>().Result;
#else
                TradingOptions tradingOptions = null;
#endif
                if (tradingOptions == null)
                {
                    tradingOptions = defaultOptions;
                }
                if (accountModesAllowed != AccountMode.Unspecified)
                {
                    defaultOptions.AccountModes &= accountModesAllowed;
                }
                //tradingOptions.EnableAutoSave();

                var tradingContext = new TradingContext((TradingOptions)tradingOptions);

                //DependencyContext.Current.AddSingleton(tradingOptions);
                //DependencyContext.Current.AddSingleton(tradingContext);
                serviceCollection.AddSingleton((TradingContext)tradingContext);
                serviceCollection.AddSingleton((TradingOptions)tradingContext.Options);

                serviceCollection.AddSingleton <IndicatorProvider>();

                //DependencyContext.SetSingletonDefault<TypeNamingContext>(tnc);  RECENTCHANGE - should no lonber be needed now that the app's IServiceProvider is used as the default for DependencyContext.

                //serviceCollection.AddSingleton(tnc);
            }));


#if TOPORT
            AssetInstantiationStrategy.Enable();
#endif

            return(appHost);
        }
示例#2
0
 public TradingContext(TradingOptions options = null)
 {
     this.Options = options;
 }