Beispiel #1
0
        //If Orders!=null , we get the potential
        protected double GetNetContracts(string firmId, string symbol, ClientPosition[] Positions, char?side = null, List <OrderDTO> Orders = null)
        {
            List <UserRecord> usersForFirm = UserRecords != null?UserRecords.Where(x => x.FirmId == firmId).ToList() : null;

            double potentialNetContracts = 0;

            if (usersForFirm != null)
            {
                foreach (UserRecord userForFirms in usersForFirm)
                {
                    Positions.Where(x => x.Symbol == symbol && x.UserId == userForFirms.UserId).ToList()
                    .ForEach(x => potentialNetContracts += x.Contracts);


                    if (Orders != null && side.HasValue)
                    {
                        Orders.Where(x => x.cSide == side.Value && x.cStatus == OrderDTO._STATUS_OPEN &&
                                     x.InstrumentId == symbol && x.UserId == userForFirms.UserId).ToList()
                        .ForEach(x => potentialNetContracts += (x.cSide == OrderDTO._SIDE_BUY) ? x.LvsQty : (-1 * x.LvsQty));
                    }
                }
            }
            else
            {
                Positions.Where(x => x.Symbol == symbol).ToList().ForEach(x => potentialNetContracts += x.Contracts);

                if (Orders != null && side.HasValue)
                {
                    Orders.Where(x => x.cSide == side.Value && x.cStatus == OrderDTO._STATUS_OPEN && x.InstrumentId == symbol).ToList()
                    .ForEach(x => potentialNetContracts += (x.cSide == OrderDTO._SIDE_BUY) ? x.LvsQty : (-1 * x.LvsQty));
                }
            }
            return(potentialNetContracts);
        }
        protected void ProcessUserRecord(IWebSocketConnection socket, WebSocketSubscribeMessage subscrMsg)
        {
            if (subscrMsg.ServiceKey != "*")
            {
                UserRecord userRecord = UserRecords.Where(x => x.UserId == subscrMsg.ServiceKey).FirstOrDefault();

                if (userRecord != null)
                {
                    DoSend <UserRecord>(socket, userRecord);
                }
            }
            else
            {
                foreach (UserRecord userRecord in UserRecords)
                {
                    DoSend <UserRecord>(socket, userRecord);
                }
            }
            ProcessSubscriptionResponse(socket, "TB", subscrMsg.ServiceKey, subscrMsg.UUID);
        }
        protected virtual void ProcessClientLoginMock(IWebSocketConnection socket, string m)
        {
            WebSocketLoginMessage wsLogin = JsonConvert.DeserializeObject <WebSocketLoginMessage>(m);


            UserRecord loggedUser = UserRecords.Where(x => x.UserId == wsLogin.UserId).FirstOrDefault();

            DoLog(string.Format("Incoming Login request for user {0}", wsLogin.UUID), MessageType.Information);

            if (loggedUser != null)
            {
                ClientLoginResponse resp = new ClientLoginResponse()
                {
                    Msg          = "ClientLoginResponse",
                    Sender       = wsLogin.Sender,
                    UUID         = wsLogin.UUID,
                    UserId       = wsLogin.UserId,
                    JsonWebToken = _TOKEN
                };


                DoLog(string.Format("user {0} Successfully logged in", wsLogin.UUID), MessageType.Information);
                UserLogged = true;
                DoSend <ClientLoginResponse>(socket, resp);
            }
            else
            {
                ClientReject reject = new ClientReject()
                {
                    Msg          = "ClientReject",
                    Sender       = wsLogin.Sender,
                    UUID         = wsLogin.UUID,
                    UserId       = wsLogin.UserId,
                    RejectReason = string.Format("Invalid user or password")
                };

                DoLog(string.Format("user {0} Rejected because of wrong user or password", wsLogin.UUID), MessageType.Information);
                DoSend <ClientReject>(socket, reject);
                socket.Close();
            }
        }