Beispiel #1
0
        private void CheckOrders()
        {
            var            openedOrders = new List <MtOrder>();
            var            closedOrders = new List <MtOrder>();
            List <MtOrder> prevOrders;

            // get current orders from MetaTrader
            var tradesOrders = ApiClient.GetOrders(OrderSelectSource.MODE_TRADES);

            lock (_locker)
                prevOrders = _prevOrders;

            if (prevOrders != null) //skip checking on first load orders
            {
                //check open orders
                openedOrders = tradesOrders.Where(to => prevOrders.Find(a => a.Ticket == to.Ticket) == null).ToList();

                //check closed orders
                var closeOrdersTemp = prevOrders.Where(po => tradesOrders.Find(a => a.Ticket == po.Ticket) == null).ToList();

                if (closeOrdersTemp.Count > 0)
                {
                    //get closed orders from history with actual values
                    var historyOrders = ApiClient.GetOrders(OrderSelectSource.MODE_HISTORY);
                    closedOrders = closeOrdersTemp.Where(cot => historyOrders.Find(a => a.Ticket == cot.Ticket) != null).ToList();
                }
            }

            lock (_locker)
                _prevOrders = tradesOrders;

            if (openedOrders.Count > 0 || closedOrders.Count > 0)
            {
                AvailabilityOrdersChanged?.Invoke(this, new AvailabilityOrdersEventArgs(openedOrders, closedOrders));
            }
        }
Beispiel #2
0
        private void CheckOrders()
        {
            var openedOrders = new List <MtOrder>();
            var closedOrders = new List <MtOrder>();

            // get current orders from MetaTrader
            var tradesOrders = _apiClient.GetOrders(OrderSelectSource.MODE_TRADES);

            List <MtOrder> prevOrders;

            lock (_locker)
            {
                prevOrders = _prevOrders;
            }

            if (_prevOrders != null) //skip checking on first load orders
            {
                //check open orders
                foreach (var order in tradesOrders)
                {
                    if (_prevOrders.Find(a => a.Ticket == order.Ticket) == null)
                    {
                        openedOrders.Add(order);
                    }
                }

                //check closed orders
                var closeOrdersTemp = new List <MtOrder>();
                foreach (var order in _prevOrders)
                {
                    if (tradesOrders.Find(a => a.Ticket == order.Ticket) == null)
                    {
                        closeOrdersTemp.Add(order);
                    }
                }

                if (closeOrdersTemp.Count > 0)
                {
                    //get closed orders from history with actual values
                    var historyOrders = _apiClient.GetOrders(OrderSelectSource.MODE_HISTORY);
                    foreach (var order in closeOrdersTemp)
                    {
                        var closedOrder = historyOrders.Find(a => a.Ticket == order.Ticket);
                        if (closedOrder != null)
                        {
                            closedOrders.Add(closedOrder);
                        }
                    }
                }
            }

            lock (_locker)
            {
                _prevOrders = tradesOrders;
            }

            if (openedOrders.Count > 0 || closedOrders.Count > 0)
            {
                AvailabilityOrdersChanged?.Invoke(this, new AvailabilityOrdersEventArgs(openedOrders, closedOrders));
            }
        }