示例#1
0
        bool Construct()
        {
            if (_manager != null)
            {
                return(false);
            }

            StatusSynchronizationEnabled = true;

            lock (this)
            {
                _manager = new MBTradingConnectionManager(this);
                if (_manager.Quotes != null)
                {
                    _manager.Quotes.QuoteUpdateEvent += new MBTradingQuote.QuoteUpdateDelegate(Quotes_QuoteUpdateEvent);
                }

                DataSourceStub.Initialize(this);
                OrderExecutionStub.Initialize(_manager.Orders);

                foreach (string symbol in EquitiesSymbols)
                {
                    DataSourceStub.AddSuggestedSymbol(new Symbol(string.Empty, symbol));
                }

                foreach (string symbol in ForexSymbols)
                {
                    DataSourceStub.AddSuggestedSymbol(new Symbol("FX", symbol));
                }
            }

            return(true);
        }
示例#2
0
        void manager_QuoteUpdatedEvent(FXCMConnectionManager manager, string symbolName, DataTick dataTick)
        {
            Symbol symbol = new Symbol(Symbol.SymbolGroup.Forex, symbolName);

            DataSourceStub dataSourceStub = _dataSourceStub;

            if (dataSourceStub == null)
            {
                return;
            }

            RuntimeDataSessionInformation sessionInformation = dataSourceStub.GetSymbolSessionInformation(symbol);

            if (sessionInformation == null)
            {
                return;
            }

            CombinedDataSubscriptionInformation info = dataSourceStub.GetUnsafeSessionSubscriptions(sessionInformation.Info);

            if (info != null && info.GetCombinedDataSubscription().QuoteSubscription)
            {
                dataSourceStub.UpdateQuote(sessionInformation.Info, new Quote(dataTick.Ask, dataTick.Bid, null, dataTick.DateTime), null);
                foreach (TimeSpan supportedPeriod in DefaultAvailablePeriods)
                {
                    dataSourceStub.UpdateDataHistory(sessionInformation.Info, new DataHistoryUpdate(supportedPeriod, new DataTick[] { dataTick }));
                }
            }
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public FXCMAdapter()
        {
            DataSourceStub           dataSourceStub           = new DataSourceStub("FXCM Adapter Data", true);
            OrderExecutionSourceStub orderExecutionSourceStub = new OrderExecutionSourceStub("FXCM Adapter Execution", true);

            base.SetInitialParameters(dataSourceStub, orderExecutionSourceStub);
            Construct();
        }
示例#4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public FXCMAdapter()
        {
            _orderExecutionStub = new OrderExecutionSourceStub("FXCM Adapter Execution", false);
            _dataSourceStub     = new DataSourceStub("FXCM Adapter Data", true);

            base.SetStub(_dataSourceStub);
            base.SetStub(_orderExecutionStub);

            Construct();
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        public void SessionDataSubscriptionUpdate(DataSessionInfo session, bool subscribe, DataSubscriptionInfo?info)
        {
            SystemMonitor.CheckError(session.IsEmtpy == false, "Method needs valid session info assigned to operate.");

            DataSourceStub dataSourceStub = DataSourceStub;

            if (dataSourceStub == null)
            {
                return;
            }

            CombinedDataSubscriptionInformation combined = dataSourceStub.GetUnsafeSessionSubscriptions(session);

            if (combined == null)
            {
                SystemMonitor.OperationError("Update on not existing session.");
                return;
            }

            MBTradingConnectionManager manager = _manager;

            if (manager == null)
            {
                return;
            }

            DataSubscriptionInfo combinedInfo = combined.GetCombinedDataSubscription();

            if (combinedInfo.QuoteSubscription)
            {
                if (manager.Adapter != null)
                {
                    manager.Quotes.SubscribeSymbolSession(session.Symbol,
                                                          Commission.GenerateSymbolCommission(manager.Adapter, session.Symbol));
                }
                else
                {
                    SystemMonitor.OperationError("Failed to perform data subscription update, since manager adapter not assigned.");
                }

                GeneralHelper.FireAndForget(delegate()
                {// Run an async update of quotes.
                    string market;
                    Quote?quote = _manager.Quotes.GetSingleSymbolQuote(session.Symbol.Name, TimeSpan.FromSeconds(10), out market);
                    if (quote.HasValue)
                    {
                        DataSourceStub.UpdateQuote(session, quote, null);
                    }
                });
            }
            else
            {
                manager.Quotes.UnSubscribeSymbolSession(session.Symbol.Name);
            }
        }
示例#6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public MBTradingAdapter()
            : base()
        {
            DataSourceStub           dataSourceStub           = new DataSourceStub("MBTrading Adapter Data", true);
            OrderExecutionSourceStub orderExecutionSourceStub = new OrderExecutionSourceStub("MBTrading Adapter Execution", false);

            base.SetStub(dataSourceStub);
            base.SetStub(orderExecutionSourceStub);

            Construct();
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        public Dictionary <Symbol, TimeSpan[]> SearchSymbols(string symbolMatch, int resultLimit)
        {
            Dictionary <Symbol, TimeSpan[]> result = new Dictionary <Symbol, TimeSpan[]>();

            foreach (Symbol symbol in DataSourceStub.SearchSuggestedSymbols(symbolMatch, resultLimit))
            {
                result.Add(symbol, DefaultAvailablePeriods);
            }

            return(result);
        }
示例#8
0
        void Quotes_QuoteUpdateEvent(MBTradingQuote keeper, MBTradingQuote.SessionQuoteInformation information)
        {
            RuntimeDataSessionInformation session = DataSourceStub.GetSymbolSessionInformation(information.Symbol);

            if (session != null)
            {
                DataSourceStub.UpdateQuote(session.Info, information.Quote, null);
            }
            else
            {
                SystemMonitor.OperationWarning("Symbol session not found, quote missed.");
            }
        }
示例#9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public FXCMData(FXCMAdapter adapter, DataSourceStub stub)
        {
            _adapter = adapter;

            _dataSourceStub = stub;
            _dataSourceStub.Initialize(this);

            StatusSynchronizationEnabled = true;
            StatusSynchronizationSource  = adapter;

            foreach (string symbol in ForexSymbols)
            {
                _dataSourceStub.AddSuggestedSymbol(new Symbol(Symbol.SymbolGroup.Forex, symbol));
            }
        }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        public Symbol?EstablishSymbolUsage(Symbol inputSymbol, TimeSpan timeOut)
        {
            MBTradingConnectionManager manager = _manager;

            if (manager == null || manager.Quotes == null)
            {
                return(null);
            }

            // Filter the baseCurrency trough its name and what symbols we know of.
            Symbol?knownSymbol = DataSourceStub.MapSymbolToRunningSession(inputSymbol.Name);

            if (knownSymbol.HasValue == false)
            {
                if (DataSourceStub.IsSuggestedSymbol(inputSymbol) &&
                    string.IsNullOrEmpty(inputSymbol.Group) == false)
                {
                    knownSymbol = inputSymbol;
                }
                else
                {// Upper case input baseCurrency.
                    inputSymbol = new Symbol(inputSymbol.Group, inputSymbol.Name.ToUpper());

                    string symbolMarket;
                    if (manager.Quotes.GetSingleSymbolQuote(inputSymbol.Name, timeOut, out symbolMarket).HasValue)
                    {// BaseCurrency found and established from broker.
                        knownSymbol = new Symbol(symbolMarket, inputSymbol.Name);
                    }
                    else
                    {
                        SystemMonitor.OperationError("Failed to map symbol with this name.");
                        return(null);
                    }
                }
            }

            lock (this)
            {
                if (_usedSymbols.ContainsKey(knownSymbol.Value.Name) == false)
                {
                    _usedSymbols.Add(knownSymbol.Value.Name, knownSymbol.Value);
                }
            }

            return(knownSymbol);
        }
示例#11
0
        /// <summary>
        ///
        /// </summary>
        public void SessionDataSubscriptionUpdate(DataSessionInfo session, bool subscribe, DataSubscriptionInfo?info)
        {
            SystemMonitor.CheckError(session.IsEmtpy == false, "Method needs valid session info assigned to operate.");

            DataSourceStub dataSourceStub = _dataSourceStub;

            if (dataSourceStub == null)
            {
                return;
            }

            CombinedDataSubscriptionInformation combined = dataSourceStub.GetUnsafeSessionSubscriptions(session);

            if (combined == null)
            {
                SystemMonitor.OperationError("Update of a non-existing session.");
                return;
            }
        }
示例#12
0
        /// <summary>
        ///
        /// </summary>
        public void SessionDataSubscriptionUpdate(DataSessionInfo session, bool subscribe, DataSubscriptionInfo?info)
        {
            SystemMonitor.CheckError(session.IsEmtpy == false, "Method needs valid session info assigned to operate.");

            DataSourceStub dataSourceStub = _dataSourceStub;

            if (dataSourceStub == null)
            {
                return;
            }

            CombinedDataSubscriptionInformation combined = dataSourceStub.GetUnsafeSessionSubscriptions(session);

            if (combined == null)
            {
                SystemMonitor.OperationError("Update on not existing session.");
                return;
            }

            DataSubscriptionInfo combinedInfo = combined.GetCombinedDataSubscription();

            if (combinedInfo.QuoteSubscription)
            {
                if (!_subscribedSymbols.ContainsKey(session.Symbol.Name))
                {
                    _subscribedSymbols.Add(session.Symbol.Name, session.Symbol);
                }
            }
            else
            {
                if (_subscribedSymbols.ContainsKey(session.Symbol.Name))
                {
                    _subscribedSymbols.Remove(session.Symbol.Name);
                }
            }
        }
示例#13
0
 public void ValueIsNotCallable()
 {
     Assert.Throws <InvalidOperationException>(() => DataSourceStub.GetPropertyValue <object>(new object(), "Property"));
 }
示例#14
0
 public void SourceOfComposableFunctionIsNotCallable()
 {
     Assert.Throws <InvalidOperationException>(() => DataSourceStub.GetQueryableSource <object>("Namespace", "Function"));
 }
示例#15
0
 public void SourceOfEntityContainerElementIsNotCallable()
 {
     Assert.Throws <InvalidOperationException>(() => DataSourceStub.GetQueryableSource <object>("EntitySet"));
 }
示例#16
0
        public void ValueIsNotCallable()
        {
            Action invalidOperation = () => { DataSourceStub.GetPropertyValue <object>(new object(), "Property"); };

            invalidOperation.Should().Throw <InvalidOperationException>();
        }
示例#17
0
        public void SourceOfComposableFunctionIsNotCallable()
        {
            Action invalidOperation = () => { DataSourceStub.GetQueryableSource <object>("Namespace", "Function"); };

            invalidOperation.Should().Throw <InvalidOperationException>();
        }
示例#18
0
 public void Dispose()
 {
     _adapter        = null;
     _dataSourceStub = null;
 }
示例#19
0
 public MyReaderClassTest()
 {
     _dataSource = new DataSourceStub();
     _underTest  = new MyReaderClass(_dataSource);
 }
示例#20
0
 public void SetUp()
 {
     _dataSource = new DataSourceStub();
     _underTest  = new MyReaderClass(_dataSource);
 }
示例#21
0
        public void SourceOfEntityContainerElementIsNotCallable()
        {
            Action invalidOperation = () => { DataSourceStub.GetQueryableSource <object>("EntitySet"); };

            invalidOperation.Should().Throw <InvalidOperationException>();
        }