public void UnInitialize() { bool update = false; lock (_syncRoot) { if (_account != null) { _account.UpdatedEvent -= new Account.AccountUpdateDelegate(_account_UpdateEvent); _account.OperationalStateChangedEvent -= new CommonSupport.OperationalStateChangedDelegate(_account_OperationalStatusChangedEvent); IOrderSink executor = _account.OrderExecutionProvider; if (executor != null) { executor.OrdersUpdatedEvent -= new OrdersUpdateDelegate(OrderExecutionProvider_OrderUpdatedEvent); update = true; } _account = null; } } if (update) { UpdateOrdersStatistics(); } }
/// <summary> /// /// </summary> public void UnInitialize() { lock (this) { // Once the session is initialized - subscribe to its members. if (_provider != null) { _provider.OperationalStateChangedEvent -= new OperationalStateChangedDelegate(_provider_OperationalStatusChangedEvent); } if (TradeEntities != null) { //_tradeEntities.UnInitialize(); //_tradeEntities.SynchronizeOrdersEvent -= new TradeEntityKeeper.SynchronizeOrdersDelegate(_orderManagement_UpdateOrdersEvent); TradeEntities.OrdersAddedEvent -= new OrderManagementOrdersUpdateDelegate(Orders_OrdersAddedEvent); TradeEntities.OrdersRemovedEvent -= new OrderManagementOrdersUpdateDelegate(Orders_OrdersRemovedEvent); TradeEntities.OrdersUpdatedEvent -= new OrderManagementOrdersUpdateTypeDelegate(Orders_OrderUpdatedEvent); } if (_dataDelivery != null) { _dataDelivery.OperationalStateChangedEvent -= new OperationalStateChangedDelegate(DataProvider_OperationalStatusChangedEvent); _dataDelivery.QuoteUpdateEvent -= new QuoteUpdateDelegate(dataDelivery_QuoteUpdateEvent); } _implementation = null; _statistics.UnInitialize(); } }
void OrderExecutionProvider_AccountInfoUpdateEvent(IOrderSink provider, AccountInfo accountInfo) { if (accountControl1.Account == null) { accountControl1.Account = _expert.Manager.SessionsArray[0].OrderExecutionProvider.DefaultAccount; } }
void _provider_AccountInfoUpdateEvent(IOrderSink provider, AccountInfo accountInfo) { if (((ISourceOrderExecution)provider).DefaultAccount != Account) { Account = ((ISourceOrderExecution)provider).DefaultAccount; } WinFormsHelper.BeginFilteredManagedInvoke(this, UpdateUI); }
void _provider_AccountInfoUpdateEvent(IOrderSink provider, AccountInfo accountInfo) { lock (this) { _accountInfo.Update(accountInfo); } RaiseUpdateEvent(); }
/// <summary> /// /// </summary> public void Initialize(ISessionDataProvider dataProvider, ISourceOrderExecution orderExecutionProvider) { if (dataProvider == null) { return; } lock (this) { _dataProvider = dataProvider; if (_dataProvider != null) { _dataProvider.CurrentDataBarProviderChangedEvent += new DataProviderUpdateDelegate(_dataProvider_CurrentDataBarProviderChangedEvent); CurrentDataBarProvider = _dataProvider.DataBars; if (_dataProvider.Quotes != null) { _dataProvider.Quotes.QuoteUpdateEvent += new QuoteProviderUpdateDelegate(Quotes_QuoteUpdateEvent); } } _orderExecutionProvider = orderExecutionProvider; if (_orderExecutionProvider != null) { IOrderSink executor = _orderExecutionProvider; if (executor != null) { executor.OrdersUpdatedEvent += new OrdersUpdateDelegate(executor_OrderUpdatedEvent); } ITradeEntityManagement management = _orderExecutionProvider.TradeEntities; if (management != null) { management.OrdersAddedEvent += new OrderManagementOrdersUpdateDelegate(management_OrdersAddedEvent); management.OrdersRemovedEvent += new OrderManagementOrdersUpdateDelegate(management_OrdersRemovedEvent); management.OrdersUpdatedEvent += new OrderManagementOrdersUpdateTypeDelegate(management_OrderUpdatedEvent); } } ComponentResourceManager resources = new ComponentResourceManager(typeof(ProviderTradeChartSeries)); _imageDown = ((Image)(resources.GetObject("imageDown"))); _imageUp = ((Image)(resources.GetObject("imageUp"))); _imageCross = ((Image)(resources.GetObject("imageCross"))); _buyDashedPen.DashPattern = new float[] { 5, 5 }; _buyDashedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; _priceLevelPen.DashPattern = new float[] { 3, 3 }; _priceLevelPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; _sellDashedPen.DashPattern = new float[] { 5, 5 }; _sellDashedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; } }
/// <summary> /// /// </summary> /// <returns></returns> public virtual bool Initialize(IOrderSink implementation) { SystemMonitor.CheckError(_implementation == null, "Account already initialized."); _implementation = implementation; lock (this) { // Once the session is initialized - subscribe to its members. if (_provider != null) { _provider.OperationalStateChangedEvent += new OperationalStateChangedDelegate(_provider_OperationalStatusChangedEvent); _provider.AccountInfoUpdateEvent += new AccountInfoUpdateDelegate(_provider_AccountInfoUpdateEvent); } if (TradeEntities != null) { //if (_tradeEntities.Initialize() == false) //{ // SystemMonitor.OperationError("Failed to initialize order management."); // return false; //} //_tradeEntities.SynchronizeOrdersEvent += new TradeEntityKeeper.SynchronizeOrdersDelegate(_orderManagement_UpdateOrdersEvent); TradeEntities.OrdersAddedEvent += new OrderManagementOrdersUpdateDelegate(Orders_OrdersAddedEvent); TradeEntities.OrdersRemovedEvent += new OrderManagementOrdersUpdateDelegate(Orders_OrdersRemovedEvent); TradeEntities.OrdersUpdatedEvent += new OrderManagementOrdersUpdateTypeDelegate(Orders_OrderUpdatedEvent); } if (_provider != null && _dataDelivery != null) { _dataDelivery.OperationalStateChangedEvent += new OperationalStateChangedDelegate(DataProvider_OperationalStatusChangedEvent); _dataDelivery.QuoteUpdateEvent += new QuoteUpdateDelegate(dataDelivery_QuoteUpdateEvent); } _statistics.Initialize(this); //SystemMonitor.OperationWarning("Initial order synchronization not done."); //GeneralHelper.FireAndForget(delegate() //{// Run an initial order syncrhonization. // Thread.Sleep(2500); // string operationResultMessage; // //_orderManagement_UpdateOrdersEvent(_tradeEntities, null, out operationResultMessage); // _provider.Account.SynchronizeOrders(null, out operationResultMessage); //}); } return(true); }
void _provider_PositionsUpdateEvent(IOrderSink provider, AccountInfo accountInfo, PositionInfo[] positionsInfos) { foreach (PositionInfo info in positionsInfos) { if (info.Symbol.IsEmpty) { SystemMonitor.Warning("Empty symboled position."); continue; } Position position = ObtainPositionBySymbol(info.Symbol); if (position != null) { position.UpdateInfo(info); } } }
public void UnInitialize() { lock (this) { _ordersArrows.Clear(); GeneralHelper.FireAndForget(SelectedOrderChangedEvent, _selectedOrder, null); _selectedOrder = null; CurrentDataBarProvider = null; if (_dataProvider != null) { if (_dataProvider.Quotes != null) { _dataProvider.Quotes.QuoteUpdateEvent += new QuoteProviderUpdateDelegate(Quotes_QuoteUpdateEvent); } _dataProvider.CurrentDataBarProviderChangedEvent -= new DataProviderUpdateDelegate(_dataProvider_CurrentDataBarProviderChangedEvent); _dataProvider = null; } if (_orderExecutionProvider != null) { IOrderSink executor = _orderExecutionProvider; ITradeEntityManagement management = _orderExecutionProvider.TradeEntities; if (executor != null) { executor.OrdersUpdatedEvent -= new OrdersUpdateDelegate(executor_OrderUpdatedEvent); } if (management != null) { management.OrdersAddedEvent -= new OrderManagementOrdersUpdateDelegate(management_OrdersAddedEvent); management.OrdersRemovedEvent -= new OrderManagementOrdersUpdateDelegate(management_OrdersRemovedEvent); management.OrdersUpdatedEvent -= new OrderManagementOrdersUpdateTypeDelegate(management_OrderUpdatedEvent); } _orderExecutionProvider = null; } _buyDashedPen.Dispose(); _sellDashedPen.Dispose(); } }
public void UnInitialize() { lock (this) { if (_account != null) { _account.UpdatedEvent -= new Account.AccountUpdateDelegate(_account_UpdateEvent); _account.OperationalStateChangedEvent -= new CommonSupport.OperationalStateChangedDelegate(_account_OperationalStatusChangedEvent); IOrderSink executor = _account.OrderExecutionProvider; if (executor != null) { executor.OrdersUpdatedEvent -= new OrdersUpdateDelegate(OrderExecutionProvider_OrderUpdatedEvent); UpdateOrdersStatistics(); } _account = null; } } }
public bool Initialize(Account account) { SystemMonitor.CheckWarning(IsInitialized == false, "Instance already initialized."); if (IsInitialized) { return(false); } lock (this) { _equityHistory = new Dictionary <DateTime, Decimal>(); _account = account; _account.UpdatedEvent += new Account.AccountUpdateDelegate(_account_UpdateEvent); _account.OperationalStateChangedEvent += new CommonSupport.OperationalStateChangedDelegate(_account_OperationalStatusChangedEvent); if (account.Info.Equity.HasValue) { _initialEquity = account.Info.Equity.Value; } else { _initialEquity = null; } IOrderSink executor = account.OrderExecutionProvider; if (executor != null) { executor.OrdersUpdatedEvent += new OrdersUpdateDelegate(OrderExecutionProvider_OrderUpdatedEvent); //OrderExecutionProvider_OrderUpdatedEvent(executor, _account.Info, new string[] { }, new OrderInfo[] { }, new Order.UpdateTypeEnum[] { }); } } return(true); }
public virtual void OrderExecutionProvider_OrderUpdatedEvent(IOrderSink executor, AccountInfo account, string[] previousOrdersIds, OrderInfo[] providerOrders, ActiveOrder.UpdateTypeEnum[] updatesType) { UpdateOrdersStatistics(); }
/// <summary> /// /// </summary> /// <returns></returns> public virtual bool Initialize(IOrderSink implementation) { SystemMonitor.CheckError(_implementation == null, "Account already initialized."); _implementation = implementation; lock (this) { // Once the session is initialized - subscribe to its members. if (_provider != null) { _provider.OperationalStateChangedEvent += new OperationalStateChangedDelegate(_provider_OperationalStatusChangedEvent); _provider.AccountInfoUpdateEvent += new AccountInfoUpdateDelegate(_provider_AccountInfoUpdateEvent); } if (TradeEntities != null) { //if (_tradeEntities.Initialize() == false) //{ // SystemMonitor.OperationError("Failed to initialize order management."); // return false; //} //_tradeEntities.SynchronizeOrdersEvent += new TradeEntityKeeper.SynchronizeOrdersDelegate(_orderManagement_UpdateOrdersEvent); TradeEntities.OrdersAddedEvent += new OrderManagementOrdersUpdateDelegate(Orders_OrdersAddedEvent); TradeEntities.OrdersRemovedEvent += new OrderManagementOrdersUpdateDelegate(Orders_OrdersRemovedEvent); TradeEntities.OrdersUpdatedEvent += new OrderManagementOrdersUpdateTypeDelegate(Orders_OrderUpdatedEvent); } if (_provider != null && _dataDelivery != null) { _dataDelivery.OperationalStateChangedEvent += new OperationalStateChangedDelegate(DataProvider_OperationalStatusChangedEvent); _dataDelivery.QuoteUpdateEvent += new QuoteUpdateDelegate(dataDelivery_QuoteUpdateEvent); } _statistics.Initialize(this); //SystemMonitor.OperationWarning("Initial order synchronization not done."); //GeneralHelper.FireAndForget(delegate() //{// Run an initial order syncrhonization. // Thread.Sleep(2500); // string operationResultMessage; // //_orderManagement_UpdateOrdersEvent(_tradeEntities, null, out operationResultMessage); // _provider.Account.SynchronizeOrders(null, out operationResultMessage); //}); } return true; }
void executor_OrderUpdatedEvent(IOrderSink executor, AccountInfo account, string[] previousOrdersIds, OrderInfo[] orderInfos, Order.UpdateTypeEnum[] updatesType) { //RaiseSeriesValuesUpdated(true); }
/// <summary> /// Updates some parts of the UI, since others must be updated on given events only. /// </summary> public void UpdateUI() { this.Enabled = ((_selectedSession != null && _selectedSession.OrderExecutionProvider != null) || _sessionManager != null); if (this.Enabled == false) { return; } // Update SessionsArray UI combobox for (int i = 0; i < _sessions.Count + 1; i++) { if (toolStripComboBoxAccount.Items.Count <= i) { toolStripComboBoxAccount.Items.Add(""); } if (i == 0) {// All accountInfos go first. if ((string)toolStripComboBoxAccount.Items[0] != "All") { toolStripComboBoxAccount.Items[0] = "All"; } } else { string name = GetSessionName(_sessions[i - 1]); if ((string)toolStripComboBoxAccount.Items[i] != name) { toolStripComboBoxAccount.Items[i] = name; } } } while (_sessions.Count + 1 < toolStripComboBoxAccount.Items.Count) { toolStripComboBoxAccount.Items.RemoveAt(toolStripComboBoxAccount.Items.Count - 1); } if (toolStripComboBoxAccount.SelectedIndex < 0) { toolStripComboBoxAccount.SelectedIndex = 0; } // Update this.listViewOrders.Visible = _compactMode == false; this.toolStripButtonCloseOrder.Visible = _compactMode == false; this.toolStripButtonModifyOrder.Visible = _compactMode == false; toolStripButtonDisplayMode.Visible = _allowCompactMode; toolStripSeparatorDisplayMode.Visible = _allowCompactMode; this.toolStripButtonNewOrder.Enabled = _selectedSession != null; //this.toolStripButtonObtainOrders.Enabled = true; this.toolStripButtonCloseOrder.Enabled = listViewOrders.SelectedItems.Count > 0; this.toolStripButtonModifyOrder.Enabled = listViewOrders.SelectedItems.Count > 0; if (_compactMode) { toolStripButtonDisplayMode.Text = "Full Mode"; } else { toolStripButtonDisplayMode.Text = "Compact Mode"; } if (_alwaysShowAccountSelectionTools) { toolStripLabelAccount.Visible = true; toolStripComboBoxAccount.Visible = true; toolStripSeparatorAccount.Visible = true; } else { // If only 1 account to manage, do not show toolStripLabelAccount.Visible = _sessions.Count > 1; toolStripComboBoxAccount.Visible = _sessions.Count > 1; toolStripSeparatorAccount.Visible = _sessions.Count > 1; } List <ListViewItem> items = new List <ListViewItem>(); foreach (ListViewItem item in listViewOrders.Items) { items.Add(item); } foreach (ExpertSession session in _sessions) { if (IsSessionVisible(session)) { lock (session) { GeneralHelper.GenericDelegate <Order, AccountInfo> UpdateOrder = delegate(Order order, AccountInfo account) { if (IsOrderVisible(order) == false) { return; } bool orderFound = false; foreach (ListViewItem item in items) { if (item.Tag == order) { SetItemAsOrder(item, order, account); orderFound = true; items.Remove(item); break; } } if (orderFound == false) { ListViewItem item = new ListViewItem(); listViewOrders.Items.Add(item); SetItemAsOrder(item, order, account); } }; IOrderSink executor = session.OrderExecutionProvider; ITradeEntityManagement ordersManagement = session.OrderExecutionProvider.TradeEntities; if (ordersManagement != null && session.OrderExecutionProvider.DefaultAccount != null) { lock (ordersManagement) { foreach (Order order in ordersManagement.OrdersUnsafe) { UpdateOrder(order, session.OrderExecutionProvider.DefaultAccount.Info); } } } } } } foreach (ListViewItem item in items) { listViewOrders.Items.Remove(item); } }
void _executor_OrderUpdatedEvent(IOrderSink providerSink, AccountInfo accountInfo, string[] previousOrdersIds, OrderInfo[] ordersInfos, Order.UpdateTypeEnum[] updatesType) { ISourceOrderExecution provider = _provider; if (providerSink != _provider) { SystemMonitor.Warning("Provider mismatch."); return; } List <Order> updatedOrders = new List <Order>(); List <Order.UpdateTypeEnum> updatedOrdersUpdateTypes = new List <Order.UpdateTypeEnum>(); for (int i = 0; i < ordersInfos.Length; i++) { if (string.IsNullOrEmpty(ordersInfos[i].Id)) { SystemMonitor.Warning("Order update of order with no ID."); continue; } if (previousOrdersIds.Length > i && previousOrdersIds[i] != ordersInfos[i].Id && string.IsNullOrEmpty(previousOrdersIds[i]) == false) {// Order Id has changed, remove old order. Order superceededOrder = GetOrderById(previousOrdersIds[i]); RemoveOrder(superceededOrder); } Order order = GetOrderById(ordersInfos[i].Id); if (order == null) {// Create new order based on incoming information. if (provider.SupportsActiveOrderManagement) { order = new ActiveOrder(_manager, provider, _delivery.SourceId, true); } else { order = new PassiveOrder(_manager, _delivery.SourceId, provider.SourceId); } order.AdoptInfo(ordersInfos[i]); if (AddOrder(order) == false) { SystemMonitor.OperationError("Failed to add order to keeper (id [" + order.Id + "] already used for another order).", TracerItem.PriorityEnum.Medium); } } else {// Existing order, to be updated. OrderInfo info = ordersInfos[i]; // First, check for critical modifications (price changes). if (order.Info.IsCriticalUpdate(info)) { SystemMonitor.Report(string.Format("Order has received a critical data modication Id[{0}], Open[{1} / {2}], Close[{3} / {4}].", order.Id, order.OpenPrice.ToString(), info.OpenPrice.ToString(), order.ClosePrice.ToString(), info.ClosePrice.ToString()), TracerItem.PriorityEnum.High); if (OrdersCriticalInformationChangedEvent != null) { OrdersCriticalInformationChangedEvent(this, accountInfo, order, info); } } if (order.UpdateInfo(info) == false) { SystemMonitor.OperationError("Failed to update order [" + order.Id + "]."); continue; } lock (this) { // Remove from any of the sub arrays it may be in. foreach (OrderStateEnum state in Enum.GetValues(typeof(OrderStateEnum))) { if (_ordersByState.ContainsKey(state) && _ordersByState[state].Contains(order)) { _ordersByState[state].Remove(order); } } _ordersByState[info.State].Add(order); } updatedOrders.Add(order); updatedOrdersUpdateTypes.Add(updatesType[i]); } } if (updatedOrders.Count > 0 && OrdersUpdatedEvent != null) { OrdersUpdatedEvent(this, accountInfo, updatedOrders.ToArray(), updatedOrdersUpdateTypes.ToArray()); } }
void _executor_OrderUpdatedEvent(IOrderSink providerSink, AccountInfo accountInfo, string[] previousOrdersIds, OrderInfo[] ordersInfos, Order.UpdateTypeEnum[] updatesType) { ISourceOrderExecution provider = _provider; if (providerSink != _provider) { SystemMonitor.Warning("Provider mismatch."); return; } List<Order> updatedOrders = new List<Order>(); List<Order.UpdateTypeEnum> updatedOrdersUpdateTypes = new List<Order.UpdateTypeEnum>(); for (int i = 0; i < ordersInfos.Length; i++) { if (string.IsNullOrEmpty(ordersInfos[i].Id)) { SystemMonitor.Warning("Order update of order with no ID."); continue; } if (previousOrdersIds.Length > i && previousOrdersIds[i] != ordersInfos[i].Id && string.IsNullOrEmpty(previousOrdersIds[i]) == false) {// Order Id has changed, remove old order. Order superceededOrder = GetOrderById(previousOrdersIds[i]); RemoveOrder(superceededOrder); } Order order = GetOrderById(ordersInfos[i].Id); if (order == null) {// Create new order based on incoming information. if (provider.SupportsActiveOrderManagement) { order = new ActiveOrder(_manager, provider, _delivery.SourceId, true); } else { order = new PassiveOrder(_manager, _delivery.SourceId, provider.SourceId); } order.AdoptInfo(ordersInfos[i]); if (AddOrder(order) == false) { SystemMonitor.OperationError("Failed to add order to keeper (id [" + order.Id + "] already used for another order).", TracerItem.PriorityEnum.Medium); } } else {// Existing order, to be updated. OrderInfo info = ordersInfos[i]; // First, check for critical modifications (price changes). if (order.Info.IsCriticalUpdate(info)) { SystemMonitor.Report(string.Format("Order has received a critical data modication Id[{0}], Open[{1} / {2}], Close[{3} / {4}].", order.Id, order.OpenPrice.ToString(), info.OpenPrice.ToString(), order.ClosePrice.ToString(), info.ClosePrice.ToString()), TracerItem.PriorityEnum.High); if (OrdersCriticalInformationChangedEvent != null) { OrdersCriticalInformationChangedEvent(this, accountInfo, order, info); } } if (order.UpdateInfo(info) == false) { SystemMonitor.OperationError("Failed to update order [" + order.Id + "]."); continue; } lock (this) { // Remove from any of the sub arrays it may be in. foreach (OrderStateEnum state in Enum.GetValues(typeof(OrderStateEnum))) { if (_ordersByState.ContainsKey(state) && _ordersByState[state].Contains(order)) { _ordersByState[state].Remove(order); } } _ordersByState[info.State].Add(order); } updatedOrders.Add(order); updatedOrdersUpdateTypes.Add(updatesType[i]); } } if (updatedOrders.Count > 0 && OrdersUpdatedEvent != null) { OrdersUpdatedEvent(this, accountInfo, updatedOrders.ToArray(), updatedOrdersUpdateTypes.ToArray() ); } }
void _provider_PositionUpdateEvent(IOrderSink provider, AccountInfo accountInfo, PositionInfo[] positionInfo) { WinFormsHelper.BeginFilteredManagedInvoke(this, TimeSpan.FromMilliseconds(250), UpdateUI); }