Ejemplo n.º 1
0
 private void ResetState()
 {
     LiveAccounts.Clear();
     DemoAccounts.Clear();
     Accounts.Clear();
     accountsByName.Clear();
     Bots.Clear();
     //Alerts.Clear();
     Sessions.Clear();
     State = ExecutionStateEx.Uninitialized;
 }
Ejemplo n.º 2
0
        protected /*override*/ void OnInitializing(ref ValidationContext validationContext)
        {
            //base.OnInitializing(ref validationContext); // Injects dependencies

            if (Sessions.Count > 0)
            {
                throw new Exception("Sessions already populated");
            }

            ResetState();
            // TODO: Verify state

            State = Execution.ExecutionStateEx.Starting;

            if ((Template.TradingOptions.AccountModes & AccountMode.Live) == AccountMode.Live)
            {
                foreach (var accountId in Template.LiveAccounts)
                {
                    var feed = TradingTypeResolver.CreateAccount(accountId);
                    if (feed is IAccount account)
                    {
                        LiveAccounts.Add(account);
                        AddAccount(accountId, account);
                    }
                    Feeds.Add(feed);
                }
            }

            if ((Template.TradingOptions.AccountModes & AccountMode.Demo) == AccountMode.Demo)
            {
                foreach (var accountId in Template.DemoAccounts)
                {
                    var feed = TradingTypeResolver.CreateAccount(accountId);
                    if (feed is IAccount account)
                    {
                        DemoAccounts.Add(account);
                        AddAccount(accountId, account);
                    }
                    Feeds.Add(feed);
                }
            }

            if ((TradingOptions.Features &
                 (
                     TradingFeatures.Bots | TradingFeatures.Scanners
                 )) != TradingFeatures.None)
            {
                foreach (var tSession in Template.Sessions)
                {
                    var session = tSession.Create();
                    session.Workspace = this;
                    //session.Initialize().ConfigureAwait(continueOnCapturedContext: false); // Loads child collections
                    session.Initialize().Wait(); // Loads child collections;
                    this.Sessions.Add(session);
                }
            }

            if (TradingOptions.Features.HasFlag(TradingFeatures.WorkspaceInterface))
            {
                LoadWorkspaceItems();
            }
            State = ExecutionStateEx.Ready;
            //return true;
        }