Ejemplo n.º 1
0
        private void SendPositionsAndOrders()
        {
            try
            {
                JsonArray jPositions = new JsonArray();
                JsonArray jOrders    = new JsonArray();

                foreach (var panel in _traderMaster.PanelsArray)
                {
                    var allJournals = panel.GetJournals();

                    foreach (var journal in allJournals)
                    {
                        var allPos = journal.AllPosition;
                        foreach (var position in allPos)
                        {
                            jPositions.Add(GetJPosition(panel.NameStrategyUniq, position));

                            if (position.OpenOrders != null && position.OpenOrders.Count > 0)
                            {
                                foreach (var positionOpenOrder in position.OpenOrders)
                                {
                                    jOrders.Add(GetJOrder(position.NameBot, positionOpenOrder));
                                }
                            }
                            if (position.CloseOrders != null && position.CloseOrders.Count > 0)
                            {
                                foreach (var positionCloseOrder in position.CloseOrders)
                                {
                                    jOrders.Add(GetJOrder(position.NameBot, positionCloseOrder));
                                }
                            }
                        }
                    }
                }

                if (jPositions.Count != 0)
                {
                    _apiServer.Send("positionsSnapshot_" + jPositions.ToString());
                }

                if (jOrders.Count != 0)
                {
                    _apiServer.Send("ordersSnapshot_" + jOrders.ToString());
                }
            }
            catch (Exception e)
            {
                _traderMaster.SendNewLogMessage(e.ToString(), LogMessageType.Error);
            }
        }
Ejemplo n.º 2
0
        public AdminApiMaster(OsTraderMaster traderMaster)
        {
            _traderMaster = traderMaster;
            PrimeSettingsMaster.ApiState    = ApiState.Off;
            ServerMaster.ServerCreateEvent += ServerMasterOnServerCreateEvent;
            StartApi();
            _counter.Start();

            Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        Thread.Sleep(5000);
                        SendProcessId();
                        SendCounter();
                        SendPortfolios();
                        SendServers();

                        if (_traderMaster.PanelsArray != null)
                        {
                            SendBotList();
                            SendBot();
                            SendBotLog();
                            SendBotParams();
                            SendPositionsAndOrders();
                        }
                    }
                    catch (Exception e)
                    {
                        _traderMaster.SendNewLogMessage(e.ToString(), LogMessageType.Error);
                    }
                }
            });
        }