Ejemplo n.º 1
0
        public bool Initialize(MbtHistMgr historyClient)
        {
            SystemMonitor.CheckError(_messageLoopOperator.InvokeRequred == false, "Init must better be called on message loop method.");

            _historyClient = historyClient;

            // *Never* subscribe to COM events of a property, always make sure to hold the object alive
            // http://www.codeproject.com/Messages/2189754/Re-Losing-COM-events-handler-in-Csharp-client.aspx

            _historyClient.OnDataEvent += new _IMbtHistEvents_OnDataEventEventHandler(_historyClient_OnDataEvent);
            _historyClient.OnError     += new _IMbtHistEvents_OnErrorEventHandler(_historyClient_OnError);

            return(true);
        }
Ejemplo n.º 2
0
        public void Dispose()
        {
            if (_historyClient != null)
            {
                _historyClient.OnDataEvent -= new _IMbtHistEvents_OnDataEventEventHandler(_historyClient_OnDataEvent);
                _historyClient.OnError     -= new _IMbtHistEvents_OnErrorEventHandler(_historyClient_OnError);
                _historyClient              = null;
            }

            if (_messageLoopOperator != null)
            {
                _messageLoopOperator = null;
            }
        }
        public bool Initialize(MbtHistMgr historyClient)
        {
            SystemMonitor.CheckError(_messageLoopOperator.InvokeRequred == false, "Init must better be called on message loop method.");

            _historyClient = historyClient;

            // *Never* subscribe to COM events of a property, always make sure to hold the object alive
            // http://www.codeproject.com/Messages/2189754/Re-Losing-COM-events-handler-in-Csharp-client.aspx

            _historyClient.OnDataEvent += new _IMbtHistEvents_OnDataEventEventHandler(_historyClient_OnDataEvent);
            _historyClient.OnError += new _IMbtHistEvents_OnErrorEventHandler(_historyClient_OnError);

            return true;
        }
        public void Dispose()
        {
            if (_historyClient != null)
            {
                _historyClient.OnDataEvent -= new _IMbtHistEvents_OnDataEventEventHandler(_historyClient_OnDataEvent);
                _historyClient.OnError -= new _IMbtHistEvents_OnErrorEventHandler(_historyClient_OnError);
                _historyClient = null;
            }

            if (_messageLoopOperator != null)
            {
                _messageLoopOperator = null;
            }
        }
Ejemplo n.º 5
0
        public bool StartOperation(OperationInformation operationInformation)
        {
            DataHistoryOperation operation = (DataHistoryOperation)operationInformation;

            bool result = true;

            _messageLoopOperator.Invoke(delegate()
            {// Placing the request on the stolen main application thread, since we need the requestMessage pump for this to work properly.
                MbtHistMgr historyClient = _historyClient;
                if (historyClient == null)
                {
                    result = false;
                    return;
                }

                if (operation.Request.IsMinuteBased == false && operation.Request.IsDayBased == false)
                {
                    result = false;
                    return;
                }

                int?time = GetConvertedTime(operation);

                if (operation.Request.IsDayBased)
                {
                    MbtHistDayBar histBar;
                    histBar = historyClient.CreateHistDayBar();
                    histBar.Clear();
                    histBar.SendRequest(operation.Symbol, Int32.Parse(operation.Id), time.Value,
                                        new DateTime(0), new DateTime(0), operation.Request.MaxValuesRetrieved.HasValue ? operation.Request.MaxValuesRetrieved.Value : int.MaxValue, true);
                }
                else if (operation.Request.IsMinuteBased)
                {
                    MbtHistMinBar histBar = historyClient.CreateHistMinBar();
                    histBar.Clear();
                    histBar.SendRequest(operation.Symbol, Int32.Parse(operation.Id), time.Value,
                                        new DateTime(0), new DateTime(0), operation.Request.MaxValuesRetrieved.HasValue ? operation.Request.MaxValuesRetrieved.Value : int.MaxValue, true);
                }
            });

            return(result);
        }
Ejemplo n.º 6
0
		 public ServerMB(TLServer tls)
        {
			  v("VerboseDebugging: " + VerboseDebugging);
            tl = tls;
            m_ComMgr = null;
            try
            {
					m_ComMgr = new MbtComMgr();  //pmh - Preferred. Was MbtComMgrClass(). Either should work.
            }
            catch (Exception ex)
            {
                System.Diagnostics.Process.Start(@"http://code.google.com/p/tradelink/wiki/ComFactoryErrors");
					 debug("m_ComMgr = new MbtComMgr() failed: " + ex.Message + ex.StackTrace); //pmh
					 return;
            }
//            m_ComMgr.SilentMode = true; //pmh - 9/18/12 - display login dialog if blank UID/Pwd (this allows me/pmh to connect to special servers for advanced testing)
            m_ComMgr.EnableSplash(false);
            m_OrderClient = m_ComMgr.OrderClient;
            m_OrderClient.SilentMode = true;
/* //pmh - OnDemandMode has been deprecated 
	if (!m_ComMgr.IsPreviousInstanceDetected("tradelink"))
	{
		m_OrderClient.OnDemandMode = false;                                             
		v("order client on demand mode disabled as previous tradelink was running.");   
	}
*/
            m_Quotes = m_ComMgr.Quotes;
            m_OpenOrders = m_OrderClient.OpenOrders;
            m_HistMgr = m_ComMgr.HistMgr;

            // tradelink bindings
            tl.newProviderName = Providers.MBTrading;
            tl.newFeatureRequest += new MessageArrayDelegate(tl_newFeatureRequest);
            tl.newSendOrderRequest += new OrderDelegateStatus(tl_newSendOrderRequest);
            tl.newRegisterSymbols += new SymbolRegisterDel(tl_newRegisterSymbols);
            tl.newOrderCancelRequest += new LongDelegate(tl_newOrderCancelRequest);
            tl.newAcctRequest += new StringDelegate(tl_newAcctRequest);
            tl.newPosList += new PositionAccountArrayDelegate(tl_newPosList);
            tl.newUnknownRequest += new UnknownMessageDelegate(tl_newUnknownRequest);

				//pmh - 8/29/12 - reordered alphabetically and added almost all remaining events

				// MB Trading MbtComMgr bindings
				m_ComMgr.OnAlertAdded += new IMbtComMgrEvents_OnAlertAddedEventHandler(m_ComMgr_OnAlertAdded); //pmh
				m_ComMgr.OnAlertsRefresh += new IMbtComMgrEvents_OnAlertsRefreshEventHandler(m_ComMgr_OnAlertsRefresh); //pmh
				m_ComMgr.OnCriticalShutdown += new IMbtComMgrEvents_OnCriticalShutdownEventHandler(m_ComMgr_OnCriticalShutdown); //pmh
				m_ComMgr.OnHealthUpdate += new IMbtComMgrEvents_OnHealthUpdateEventHandler(m_ComMgr_OnHealthUpdate);
				m_ComMgr.OnLogonDeny += new IMbtComMgrEvents_OnLogonDenyEventHandler(m_ComMgr_OnLogonDeny);
				m_ComMgr.OnLogonSucceed += new IMbtComMgrEvents_OnLogonSucceedEventHandler(m_ComMgr_OnLogonSucceed);
			  /*
			   * pmh - add later if desired
			   * 
				m_ComMgr.OnMATAccountPercentSet += new IMbtComMgrEvents_OnMATAccountPercentSetEventHandler(m_ComMgr_OnMATAccountPercentSet); //pmh
				m_ComMgr.OnMATGroupAccountAdded += new IMbtComMgrEvents_OnMATGroupAccountAddedEventHandler(m_ComMgr_OnMATGroupAccountAdded); //pmh
				m_ComMgr.OnMATGroupAccountRemoved += new IMbtComMgrEvents_OnMATGroupAccountRemovedEventHandler(m_ComMgr_OnMATGroupAccountRemoved); //pmh
				m_ComMgr.OnMATGroupsGroupAdded += new IMbtComMgrEvents_OnMATGroupsGroupAddedEventHandler(m_ComMgr_OnMATGroupsGroupAdded); //pmh
				m_ComMgr.OnMATGroupsGroupRemoved += new IMbtComMgrEvents_OnMATGroupsGroupRemovedEventHandler(m_ComMgr_OnMATGroupsGroupRemoved); //pmh
				m_ComMgr.OnMATGroupsGroupRenamed += new IMbtComMgrEvents_OnMATGroupsGroupRenamedEventHandler(m_ComMgr_OnMATGroupsGroupRenamed); //pmh
			   */
				
			  // MB Trading MbtOrderClient bindings
				m_OrderClient.OnAccountLoaded += new _IMbtOrderClientEvents_OnAccountLoadedEventHandler(m_OrderClient_OnAccountLoaded);
				m_OrderClient.OnAccountLoading += new _IMbtOrderClientEvents_OnAccountLoadingEventHandler(m_OrderClient_OnAccountLoading);
				m_OrderClient.OnAccountUnavailable += new _IMbtOrderClientEvents_OnAccountUnavailableEventHandler(m_OrderClient_OnAccountUnavailable); //pmh
				m_OrderClient.OnAcknowledge += new _IMbtOrderClientEvents_OnAcknowledgeEventHandler(m_OrderClient_OnAcknowledge); //pmh
				m_OrderClient.OnBalanceUpdate += new _IMbtOrderClientEvents_OnBalanceUpdateEventHandler(m_OrderClient_OnBalanceUpdate); //pmh
				m_OrderClient.OnCancelPlaced += new _IMbtOrderClientEvents_OnCancelPlacedEventHandler(m_OrderClient_OnCancelPlaced);
				m_OrderClient.OnCancelRejected += new _IMbtOrderClientEvents_OnCancelRejectedEventHandler(m_OrderClient_OnCancelRejected);
				m_OrderClient.OnClose += new _IMbtOrderClientEvents_OnCloseEventHandler(m_OrderClient_OnClose);
				m_OrderClient.OnConnect += new _IMbtOrderClientEvents_OnConnectEventHandler(m_OrderClient_OnConnect);
				//pmh - 9/21/12 - See note on DefaultAccount at end of document!
				//m_OrderClient.OnDefaultAccountChanged += new _IMbtOrderClientEvents_OnDefaultAccountChangedEventHandler(m_OrderClient_OnDefaultAccountChanged); //pmh
				m_OrderClient.OnExecute += new _IMbtOrderClientEvents_OnExecuteEventHandler(m_OrderClient_OnExecute); //pmh
				m_OrderClient.OnHistoryAdded += new _IMbtOrderClientEvents_OnHistoryAddedEventHandler(m_OrderClient_OnHistoryAdded);
				m_OrderClient.OnLogonSucceed += new _IMbtOrderClientEvents_OnLogonSucceedEventHandler(m_OrderClient_OnLogonSucceed);
				m_OrderClient.OnPositionAdded += new _IMbtOrderClientEvents_OnPositionAddedEventHandler(m_OrderClient_OnPositionAdded);
				m_OrderClient.OnPositionStrategyGroupAdded += new _IMbtOrderClientEvents_OnPositionStrategyGroupAddedEventHandler(m_OrderClient_OnPositionStrategyGroupAdded); //pmh
				m_OrderClient.OnPositionStrategyGroupRemoved += new _IMbtOrderClientEvents_OnPositionStrategyGroupRemovedEventHandler(m_OrderClient_OnPositionStrategyGroupRemoved); //pmh
				m_OrderClient.OnPositionStrategyGroupUpdated += new _IMbtOrderClientEvents_OnPositionStrategyGroupUpdatedEventHandler(m_OrderClient_OnPositionStrategyGroupUpdated); //pmh
				m_OrderClient.OnPositionUpdated += new _IMbtOrderClientEvents_OnPositionUpdatedEventHandler(m_OrderClient_OnPositionUpdated);
				m_OrderClient.OnRemove += new _IMbtOrderClientEvents_OnRemoveEventHandler(m_OrderClient_OnRemove); //pmh
				m_OrderClient.OnReplacePlaced += new _IMbtOrderClientEvents_OnReplacePlacedEventHandler(m_OrderClient_OnReplacePlaced); //pmh
				m_OrderClient.OnReplaceRejected += new _IMbtOrderClientEvents_OnReplaceRejectedEventHandler(m_OrderClient_OnReplaceRejected); //pmh
				m_OrderClient.OnSubmit += new _IMbtOrderClientEvents_OnSubmitEventHandler(m_OrderClient_OnSubmit);

				// MB Trading MbtQuote bindings
				m_Quotes.OnClose += new _IMbtQuotesEvents_OnCloseEventHandler(m_Quotes_OnClose);
            m_Quotes.OnConnect += new _IMbtQuotesEvents_OnConnectEventHandler(m_Quotes_OnConnect);
            m_Quotes.OnLogonSucceed += new _IMbtQuotesEvents_OnLogonSucceedEventHandler(m_Quotes_OnLogonSucceed);

				// MB Trading MbtHist bindings
				m_HistMgr.OnDataEvent += new _IMbtHistEvents_OnDataEventEventHandler(m_HistMgr_OnDataEvent);
				m_HistMgr.OnError += new _IMbtHistEvents_OnErrorEventHandler(m_HistMgr_OnError);

				//disable old ticks
            //DisableOldTicks = Convert.ToBoolean(ConfigurationSettings.AppSettings["DisableOldTicks"]);
            DisableOldTicks = true;
            debug("TL binding and MBT Desktop event mapping complete.");
        }
Ejemplo n.º 7
0
        public void Stop()
        {
            v("stopping ServerMB connector.");
				pt = null;
				m_HistMgr = null;
				m_OpenOrders = null;
				m_Quotes.UnadviseAll(this); //pmh - 9/18/12 - MUST NOT FORGET THIS!
            m_Quotes.Disconnect();
            m_OrderClient.Disconnect();
				m_Quotes = null;
				m_OrderClient = null;
				m_HistMgr = null;
			  
        }
Ejemplo n.º 8
0
        public ServerMB(TLServer tls)
        {
            tl = tls;
            m_ComMgr = null;
            try
            {
                m_ComMgr = new MbtComMgrClass();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Process.Start(@"http://code.google.com/p/tradelink/wiki/ComFactoryErrors");
                debug("An error occured: " + ex.Message + ex.StackTrace);
                return;
            }
            m_ComMgr.SilentMode = true;
            m_ComMgr.EnableSplash(false);
            m_OrderClient = m_ComMgr.OrderClient;
            m_OrderClient.SilentMode = true;
            if (!m_ComMgr.IsPreviousInstanceDetected("tradelink"))
            {
                m_OrderClient.OnDemandMode = false;
                v("order client on demand mode disabled as previous tradelink was running.");
            }
            m_Quotes = m_ComMgr.Quotes;
            m_Orders = m_OrderClient.OpenOrders;
            m_Hist = m_ComMgr.HistMgr;

            // tradelink bindings
            tl.newProviderName = Providers.MBTrading;
            tl.newFeatureRequest += new MessageArrayDelegate(tl_newFeatureRequest);
            tl.newSendOrderRequest += new OrderDelegateStatus(tl_newSendOrderRequest);
            tl.newRegisterSymbols += new SymbolRegisterDel(tl_newRegisterSymbols);
            tl.newOrderCancelRequest += new LongDelegate(tl_newOrderCancelRequest);
            tl.newAcctRequest += new StringDelegate(tl_newAcctRequest);
            tl.newPosList += new PositionArrayDelegate(tl_newPosList);
            tl.newUnknownRequest += new UnknownMessageDelegate(tl_newUnknownRequest);

            // mb bindings
            m_OrderClient.OnAccountLoaded += new _IMbtOrderClientEvents_OnAccountLoadedEventHandler(m_OrderClient_OnAccountLoaded);
            m_OrderClient.OnAccountLoading += new _IMbtOrderClientEvents_OnAccountLoadingEventHandler(m_OrderClient_OnAccountLoading);
            m_OrderClient.OnSubmit += new _IMbtOrderClientEvents_OnSubmitEventHandler(m_OrderClient_OnSubmit);
            m_OrderClient.OnClose += new _IMbtOrderClientEvents_OnCloseEventHandler(m_OrderClient_OnClose);
            m_OrderClient.OnConnect += new _IMbtOrderClientEvents_OnConnectEventHandler(m_OrderClient_OnConnect);
            m_OrderClient.OnLogonSucceed += new _IMbtOrderClientEvents_OnLogonSucceedEventHandler(m_OrderClient_OnLogonSucceed);
            m_ComMgr.OnCriticalShutdown += new IMbtComMgrEvents_OnCriticalShutdownEventHandler(m_ComMgr_OnCriticalShutdown);
            m_ComMgr.OnHealthUpdate += new IMbtComMgrEvents_OnHealthUpdateEventHandler(m_ComMgr_OnHealthUpdate);
            m_ComMgr.OnLogonSucceed += new IMbtComMgrEvents_OnLogonSucceedEventHandler(m_ComMgr_OnLogonSucceed);
            m_ComMgr.OnLogonDeny += new IMbtComMgrEvents_OnLogonDenyEventHandler(m_ComMgr_OnLogonDeny);
            m_Quotes.OnClose += new _IMbtQuotesEvents_OnCloseEventHandler(m_Quotes_OnClose);
            m_Quotes.OnConnect += new _IMbtQuotesEvents_OnConnectEventHandler(m_Quotes_OnConnect);
            m_Quotes.OnLogonSucceed += new _IMbtQuotesEvents_OnLogonSucceedEventHandler(m_Quotes_OnLogonSucceed);
            m_OrderClient.OnPositionAdded += new _IMbtOrderClientEvents_OnPositionAddedEventHandler(m_OrderClient_OnPositionAdded);
            m_OrderClient.OnPositionUpdated += new _IMbtOrderClientEvents_OnPositionUpdatedEventHandler(m_OrderClient_OnPositionUpdated);
            //m_OrderClient.OnExecute += new _IMbtOrderClientEvents_OnExecuteEventHandler( m_OrderClient_OnExecute );
            m_OrderClient.OnCancelPlaced += new _IMbtOrderClientEvents_OnCancelPlacedEventHandler(m_OrderClient_OnCancelPlaced);
            m_OrderClient.OnCancelRejected += new _IMbtOrderClientEvents_OnCancelRejectedEventHandler(m_OrderClient_OnCancelRejected);
            //m_OrderClient.OnRemove += new _IMbtOrderClientEvents_OnRemoveEventHandler( m_OrderClient_OnRemove );
            m_OrderClient.OnHistoryAdded += new _IMbtOrderClientEvents_OnHistoryAddedEventHandler(m_OrderClient_OnHistoryAdded);
            m_Hist.OnDataEvent += new _IMbtHistEvents_OnDataEventEventHandler(m_Hist_OnDataEvent);
            //disable old ticks
            //DisableOldTicks = Convert.ToBoolean(ConfigurationSettings.AppSettings["DisableOldTicks"]);
            DisableOldTicks = true;
            debug("all binding configured successfully.");
        }