private void ProcessResponseError(string rawMsg, ResponseError responseError)
        {
            string msg = Err.GetFullErrorMessage(responseError);

            if (responseError.Code == Err.ERR_SUB_FAIL)
            {
                ResponseErrorSubscribe res = CBitfinexJsonSerializer.DeserializeObject <ResponseErrorSubscribe>(rawMsg);
                msg += " Symbol=" + res.Symbol;
            }


            Log(msg);
            Error(msg);
        }
        public void ProcessData(string data)
        {
            LogRaw(data);


            if (data[0] == '{') //event message
            {
                MessageBase mb = CBitfinexJsonSerializer.DeserializeObject <MessageBase>(data);


                if (mb.Event == EnmMessageType.Info)
                {
                    ProcessResponseInfo(CBitfinexJsonSerializer.DeserializeObject <ResponseInfo>(data));
                }
                else if (mb.Event == EnmMessageType.Auth)
                {
                    ProcessResponseAuth(CBitfinexJsonSerializer.DeserializeObject <ResponseAuth>(data));
                }
                else if (mb.Event == EnmMessageType.Error)
                {
                    ProcessResponseError(data, CBitfinexJsonSerializer.DeserializeObject <ResponseError>(data));
                }
                else if (mb.Event == EnmMessageType.Subscribed)
                {
                    ResponseSubscribed rs = CBitfinexJsonSerializer.DeserializeObject <ResponseSubscribed>(data);
                    if (rs.Channel == "book")
                    {
                        ResponseSubscribedBook rsb = CBitfinexJsonSerializer.DeserializeObject <ResponseSubscribedBook>(data);

                        //string instrument = rs.Symbol[0] == 't' ? rs.Symbol.Remove(0, 1) : rs.Symbol;
                        CBookParams bp = new CBookParams
                        {
                            Instrument = rsb.Symbol[0] == 't' ? rsb.Symbol.Remove(0, 1) : rsb.Symbol,
                            Precision  = rsb.Prec
                        };


                        //string instrument = rs.Symbol;
                        UpdateBookChanInstr(rs.ChanId, bp);
                    }
                    else if (rs.Channel == "trades")
                    {
                        UpdateTradesChanInstr(rs.ChanId, rs.Symbol);
                    }
                }
            }
            else if (data[0] == '[') //channel data
            {
                JArray jArr = CBitfinexJsonSerializer.DeserializeObject <JArray>(data);

                if (jArr.Count() < 2)
                {
                    Error("Invalid message");
                    return;
                }

                long channelId = (int)jArr[0];

                string      instrument = "";
                CBookParams bookParam  = null;

                if (channelId == _chanIdPersonalData)
                {
                    string evnt = (string)jArr[1];

                    if (evnt == "ws")
                    {
                        ProcessWalletSnapshot(jArr);
                    }
                    else if (evnt == "wu")
                    {
                        ProcessWalletUpdate(jArr);
                    }
                    else if (evnt == "ps")
                    {
                        ProcessPositionsSnapshot((JArray)jArr[2]);
                    }
                    else if (evnt == "pn")
                    {
                        ProcessPositionNew((JArray)jArr[2]);
                    }
                    else if (evnt == "pu")
                    {
                        ProcessPositionUpdate((JArray)jArr[2]);
                    }
                    else if (evnt == "pc")
                    {
                        ProcessPositionClose((JArray)jArr[2]);
                    }
                    else if (evnt == "os")
                    {
                        ProcessOrdersSnapshot((JArray)jArr[2]);
                    }
                    else if (evnt == "on")
                    {
                        ProcessOrderNew((JArray)jArr[2]);
                    }
                    else if (evnt == "ou")
                    {
                        ProcessOrderUpdate((JArray)jArr[2]);
                    }
                    else if (evnt == "oc")
                    {
                        ProcessOrderCancell((JArray)jArr[2]);
                    }
                    else if (evnt == "fos")
                    {
                        ProcesFundingOrderSnapshot(jArr);
                    }
                    else if (evnt == "n")
                    {
                        ProcessNotification((JArray)jArr[2]);
                    }
                    else if (evnt == "te")
                    {
                        ProcessUserTradeExecute((JArray)jArr[2]);
                    }
                    else if (evnt == "tu")
                    {
                        ProcessUserTradeUpdate((JArray)jArr[2]);
                    }
                    else if (evnt == "hb")
                    {
                        if (_name.Contains("auth"))
                        {
                            ProcessHeartBeatAuth();
                        }
                    }
                }
                else if (GetBookParam(channelId, ref bookParam))
                {
                    if (jArr.Count() == 2)
                    {
                        if (IsHeartBeat(jArr[1]))
                        {
                            return;
                        }
                        JArray arr = (JArray)jArr[1];
                        if (arr[0].Type == JTokenType.Array)
                        {
                            ProcessOrderBookSnapshot(bookParam, arr);
                        }
                        else
                        {
                            ProcessOrderBookUpdate(bookParam, arr);
                        }
                    }
                }
                else if (GetTradesInst(channelId, ref instrument))
                {
                    if (jArr.Count() == 2)
                    {
                        if (IsHeartBeat(jArr[1]))
                        {
                            return;
                        }


                        ProcessTradesSnapshot(instrument, (JArray)jArr[1]);
                    }
                    else if (jArr.Count() == 3)
                    {
                        string evnt = (string)jArr[1];
                        //As we don't need trade id - use te, which must be recieved first,
                        //not tu using this docs:
                        // http://blog.bitfinex.com/api/websocket-api-update/
                        if (evnt == "te")
                        {
                            ProcessTradeExecute(instrument, (JArray)jArr[2]);
                        }
                    }
                }
            }
            else
            {
                Error("Websocket. Unknown message");
            }
        }