Exemplo n.º 1
0
        public IEnumerable <PositionInfo> GetAllPositions()
        {
            List <PositionInfo> pos = new List <PositionInfo>();

            try
            {
                pos = terminal.GetAllPositions();
            }
            catch
            {
            }

            return(pos);
        }
Exemplo n.º 2
0
        public void ProcessMessage(WsMessage wsMessage, IMessagingServer server)
        {
            switch (wsMessage.Type)
            {
            case WsMessageType.GetAllText:
            {
                wsMessage.Message = log.GetAllText();
                wsMessage.Type    = WsMessageType.GetAllText;
                var send = JsonConvert.SerializeObject(wsMessage);
                server.MulticastText(send);
            }
            break;

            case WsMessageType.ClearLog:
            {
                log.ClearLog();
            }
            break;

            case WsMessageType.WriteLog:
            {
                log.Info(wsMessage.Message);
            }
            break;

            case WsMessageType.GetAllPositions:
            {
                WsMessage message = new WsMessage();
                message.From    = wsMessage.From;
                message.Type    = WsMessageType.GetAllPositions;
                message.Message = JsonConvert.SerializeObject(terminals.GetAllPositions());
                var send = JsonConvert.SerializeObject(message);
                server.MulticastText(send);
            }
            break;

            case WsMessageType.GetAllPerformance:
            {
                WsMessage message = new WsMessage();
                message.From    = wsMessage.From;
                message.Type    = WsMessageType.GetAllPerformance;
                message.Message = "[]";
                var ds    = MainService.thisGlobal.Container.Resolve <DataService>();
                int month = int.Parse(wsMessage.Message);
                ds.StartPerf(month);
                var send = JsonConvert.SerializeObject(message);
                server.MulticastText(send);
            }
            break;

            case WsMessageType.GetAllCapital:
            {
                WsMessage message = new WsMessage();
                message.From    = wsMessage.From;
                message.Type    = WsMessageType.GetAllCapital;
                message.Message = "[]";
                var      result       = JsonConvert.DeserializeObject <Dictionary <string, string> >(wsMessage.Message);
                int      wallet       = int.Parse(result["WalletId"]);
                DateTime dateTimeFrom = DateTime.Parse(result["from"]);
                DateTime dateTimeTo   = DateTime.Parse(result["to"]);
                xtrade.GetWalletBalanceRangeAsync(wallet, dateTimeFrom, dateTimeTo);
                var send = JsonConvert.SerializeObject(message);
                server.MulticastText(send);
            }
            break;

            case WsMessageType.UpdatePosition:
            {
                var result = JsonConvert.DeserializeObject <PositionInfo>(wsMessage.Message);
                if (result != null)
                {
                    terminals.UpdatePositionFromClient(result);
                }
            }
            break;

            default:
            {
                log.Info("Undefined Message");
                // Multicast message to all connected sessions
                // ((WsServer)Server).MulticastText(message);
            }
            break;
            }
        }