/// <summary> /// 通过流获取登录信息 /// </summary> /// <param name="loginInfos">登录信息</param> /// <param name="body">包体</param> /// <param name="bodyLength">包体长度</param> public static int GetLoginInfos(List <LoginInfo> loginInfos, byte[] body, int bodyLength) { Binary br = new Binary(); br.Write(body, bodyLength); int size = br.ReadInt(); if (size > 0) { for (int i = 0; i < size; i++) { LoginInfo loginInfo = new LoginInfo(); loginInfo.m_userID = br.ReadInt(); loginInfo.m_userName = br.ReadString(); loginInfo.m_passWord = br.ReadString(); loginInfo.m_nickName = br.ReadString(); loginInfo.m_type = br.ReadInt(); loginInfo.m_state = br.ReadInt(); loginInfo.m_sessionID = br.ReadInt(); loginInfos.Add(loginInfo); } } br.Close(); return(1); }
public static int GetFilterResults(Dictionary <string, double[]> datas, ref int currentBatch, ref int totalBatch, byte[] body, int bodyLength) { Binary binary = new Binary(); binary.Write(body, bodyLength); int num = binary.ReadInt(); currentBatch = binary.ReadInt(); totalBatch = binary.ReadInt(); if (num > 0) { for (int i = 0; i < num; i++) { string str = binary.ReadString(); int num3 = binary.ReadInt(); double[] numArray = new double[num3]; for (int j = 0; j < num3; j++) { numArray[j] = binary.ReadDouble(); } datas[str] = numArray; } } binary.Close(); return(1); }
public static int GetTemplates(List <SecurityFilterTemplate> templates, byte[] body, int bodyLength) { Binary binary = new Binary(); binary.Write(body, bodyLength); int num = binary.ReadInt(); if (num > 0) { for (int i = 0; i < num; i++) { SecurityFilterTemplate item = new SecurityFilterTemplate(); item.m_templateID = binary.ReadString(); item.m_userID = binary.ReadInt(); item.m_name = binary.ReadString(); item.m_codes = binary.ReadString(); item.m_indicator = binary.ReadString(); item.m_parameters = binary.ReadString(); item.m_filter = binary.ReadString(); item.m_cycle = binary.ReadInt(); item.m_subscription = binary.ReadInt(); item.m_orderNum = binary.ReadInt(); templates.Add(item); } } binary.Close(); return(1); }
/// <summary> /// 获取历史数据 /// </summary> /// <param name="dataInfo"></param> /// <param name="datas"></param> /// <param name="body"></param> /// <param name="bodyLength"></param> /// <returns></returns> public static int GetHistoryDatas(ref HistoryDataInfo dataInfo, List <SecurityData> datas, byte[] body, int bodyLength) { Binary binary = new Binary(); binary.Write(body, bodyLength); dataInfo.m_securityCode = binary.ReadString(); dataInfo.m_type = binary.ReadChar(); dataInfo.m_size = binary.ReadInt(); dataInfo.m_cycle = binary.ReadInt(); dataInfo.m_subscription = binary.ReadInt(); dataInfo.m_startDate = binary.ReadDouble(); dataInfo.m_endDate = binary.ReadDouble(); dataInfo.m_pushData = binary.ReadBool(); int size = dataInfo.m_size; for (int i = 0; i < size; i++) { SecurityData item = new SecurityData(); item.m_date = binary.ReadDouble(); item.m_close = binary.ReadFloat(); item.m_high = binary.ReadFloat(); item.m_low = binary.ReadFloat(); item.m_open = binary.ReadFloat(); item.m_volume = binary.ReadDouble(); item.m_amount = binary.ReadDouble(); if (dataInfo.m_cycle == 0) { item.m_avgPrice = binary.ReadFloat(); } datas.Add(item); } binary.Close(); return(1); }
public static int GetIndicators(List <Indicator> indicators, byte[] body, int bodyLength) { Binary binary = new Binary(); binary.Write(body, bodyLength); int num = binary.ReadInt(); if (num > 0) { for (int i = 0; i < num; i++) { Indicator item = new Indicator(); item.m_indicatorID = binary.ReadString(); item.m_userID = binary.ReadInt(); item.m_category = binary.ReadString(); item.m_coordinate = binary.ReadString(); item.m_description = binary.ReadString(); item.m_digit = binary.ReadInt(); item.m_name = binary.ReadString(); item.m_orderNum = binary.ReadInt(); item.m_paintType = binary.ReadInt(); item.m_parameters = binary.ReadString(); item.m_password = binary.ReadString(); item.m_specialCoordinate = binary.ReadString(); item.m_text = binary.ReadString(); item.m_type = binary.ReadInt(); item.m_usePassword = binary.ReadInt(); item.m_version = binary.ReadInt(); indicators.Add(item); } } binary.Close(); return(1); }
/// <summary> /// 回调函数 /// </summary> /// <param name="socketID">连接ID</param> /// <param name="localSID">本地连接ID</param> /// <param name="str">数据</param> /// <param name="len">长度</param> public static void CallBack(int socketID, int localSID, IntPtr str, int len) { m_downFlow += len; try { if (len > 4) { byte[] bytes = GetValueChar(str, len); Binary br = new Binary(); br.Write(bytes, len); int head = br.ReadInt(); int groupID = br.ReadShort(); int serviceID = br.ReadShort(); BaseService service = null; if (m_services.ContainsKey(serviceID)) { m_services[serviceID].OnCallBack(br, socketID, localSID, len); } br.Close(); } } catch (Exception ex) { Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace); } }
public static int GetSecurities(List <Security> securities, int functionID, byte[] body, int bodyLength) { Binary binary = new Binary(); binary.Write(body, bodyLength); int num = binary.ReadInt(); if (num > 0) { for (int i = 0; i < num; i++) { Security item = new Security(); item.m_code = binary.ReadString(); if (functionID == 0) { item.m_name = binary.ReadString(); item.m_pingyin = binary.ReadString(); item.m_type = binary.ReadShort(); item.m_status = binary.ReadChar(); } securities.Add(item); } } binary.Close(); return(1); }
/// <summary> /// 获取弹幕信息 /// </summary> /// <param name="datas">用于返回弹幕信息</param> /// <param name="body">包体</param> /// <param name="bodyLength">包体长度</param> /// <returns></returns> public static int GetChatDatas(List <ChatData> datas, byte[] body, int bodyLength) { Binary br = new Binary(); br.Write(body, bodyLength); int size = br.ReadInt(); for (int i = 0; i < size; i++) { ChatData chat = new ChatData(); chat.m_userID = br.ReadInt(); chat.m_type = br.ReadChar(); chat.m_text = br.ReadString(); datas.Add(chat); } br.Close(); return(1); }
/// <summary> /// 通过流获取用户会话 /// </summary> /// <param name="sessions">用户会话</param> /// <param name="body">包体</param> /// <param name="bodyLength">包体长度</param> public static int GetSessions(List <UserSession> sessions, byte[] body, int bodyLength) { Binary br = new Binary(); br.Write(body, bodyLength); int size = br.ReadInt(); if (size > 0) { for (int i = 0; i < size; i++) { UserSession session = new UserSession(); session.m_userID = br.ReadInt(); session.m_key = br.ReadString(); session.m_value = br.ReadString(); sessions.Add(session); } } br.Close(); return(1); }
public static int GetMacros(List <Macro> macros, byte[] body, int bodyLength) { Binary binary = new Binary(); binary.Write(body, bodyLength); int num = binary.ReadInt(); if (num > 0) { for (int i = 0; i < num; i++) { Macro item = new Macro(); item.m_macroID = binary.ReadString(); item.m_userID = binary.ReadInt(); item.m_name = binary.ReadString(); item.m_description = binary.ReadString(); item.m_icon = binary.ReadString(); item.m_script = binary.ReadString(); item.m_type = binary.ReadInt(); item.m_interval = binary.ReadInt(); item.m_cd = binary.ReadInt(); item.m_orderNum = binary.ReadInt(); macros.Add(item); } } binary.Close(); return(1); }
/// <summary> /// 收到消息 /// </summary> /// <param name="br">流</param> /// <param name="socketID">套接字ID</param> /// <param name="localSID">本地套接字ID</param> /// <param name="len">长度</param> public virtual void OnCallBack(Binary br, int socketID, int localSID, int len) { int headSize = sizeof(int) * 4 + sizeof(short) * 3 + sizeof(byte) * 2; int functionID = br.ReadShort(); int sessionID = br.ReadInt(); int requestID = br.ReadInt(); int state = br.ReadByte(); int compressType = br.ReadByte(); int bodyLength = br.ReadInt(); byte[] body = new byte[len - headSize]; br.ReadBytes(body); if (compressType == COMPRESSTYPE_GZIP) { using (MemoryStream dms = new MemoryStream()) { using (MemoryStream cms = new MemoryStream(body)) { using (GZipStream gzip = new GZipStream(cms, CompressionMode.Decompress)) { byte[] buffer = new byte[1024]; int size = 0; while ((size = gzip.Read(buffer, 0, buffer.Length)) > 0) { dms.Write(buffer, 0, size); } body = dms.ToArray(); } } } } CMessage message = new CMessage(GroupID, ServiceID, functionID, sessionID, requestID, socketID, state, compressType, bodyLength, body); OnReceive(message); OnWaitMessageHandle(message); body = null; }
public static int GetCategories(List <UserSecurityCategory> categories, byte[] body, int bodyLength) { Binary binary = new Binary(); binary.Write(body, bodyLength); int num = binary.ReadInt(); if (num > 0) { for (int i = 0; i < num; i++) { UserSecurityCategory item = new UserSecurityCategory(); item.m_categoryID = binary.ReadString(); item.m_userID = binary.ReadInt(); item.m_name = binary.ReadString(); item.m_codes = binary.ReadString(); item.m_type = binary.ReadInt(); item.m_orderNum = binary.ReadInt(); categories.Add(item); } } binary.Close(); return(1); }
public static int GetLayouts(List <IndicatorLayout> layouts, byte[] body, int bodyLength) { Binary binary = new Binary(); binary.Write(body, bodyLength); int num = binary.ReadInt(); if (num > 0) { for (int i = 0; i < num; i++) { IndicatorLayout item = new IndicatorLayout(); item.m_layoutID = binary.ReadString(); item.m_userID = binary.ReadInt(); item.m_name = binary.ReadString(); item.m_text = binary.ReadString(); item.m_type = binary.ReadInt(); item.m_orderNum = binary.ReadInt(); layouts.Add(item); } } binary.Close(); return(1); }
/// <summary> /// 获取预测的成交量 /// </summary> /// <param name="datas"></param> /// <param name="body"></param> /// <param name="bodyLength"></param> /// <returns></returns> public static int GetVolumeForecastData(List <VolumeForecastData> datas, byte[] body, int bodyLength) { Binary binary = new Binary(); binary.Write(body, bodyLength); int num = binary.ReadInt(); for (int i = 0; i < num; i++) { VolumeForecastData item = new VolumeForecastData(); item.m_securityCode = binary.ReadString(); item.m_rate = binary.ReadDouble(); datas.Add(item); } binary.Close(); return(1); }
/// <summary> /// 获取交易数据 /// </summary> /// <param name="securityCode"></param> /// <param name="transactionDatas"></param> /// <param name="body"></param> /// <param name="bodyLength"></param> /// <returns></returns> public static int GetTransactionDatas(ref string securityCode, List <TransactionData> transactionDatas, byte[] body, int bodyLength) { Binary binary = new Binary(); binary.Write(body, bodyLength); securityCode = binary.ReadString(); int num = binary.ReadInt(); for (int i = 0; i < num; i++) { TransactionData item = new TransactionData(); item.m_date = binary.ReadDouble(); item.m_price = binary.ReadFloat(); item.m_volume = binary.ReadDouble(); item.m_type = binary.ReadChar(); transactionDatas.Add(item); } binary.Close(); return(1); }
/// <summary> /// 获取表格 /// </summary> /// <param name="bytes">流</param> /// <param name="native">方法库</param> /// <returns>表格</returns> public GridA GetGrid(byte[] bytes, INativeBase native) { Binary br = new Binary(); br.Write(bytes, bytes.Length); GridA grid = new GridA(); grid.Native = native; grid.Name = br.ReadString(); int columnsSize = br.ReadInt(); for (int i = 0; i < columnsSize; i++) { GridColumn column = new GridColumn(); column.Name = br.ReadString(); column.ColumnType = br.ReadString(); grid.AddColumn(column); } grid.Update(); List <GridColumn> columns = grid.GetColumns(); int rowsCount = br.ReadInt(); for (int i = 0; i < rowsCount; i++) { GridRow row = new GridRow(); grid.AddRow(row); for (int j = 0; j < columnsSize; j++) { GridColumn column = columns[j]; string columnType = column.ColumnType.ToLower(); GridCell cell = null; if (columnType == "bool") { cell = new GridBoolCell(); row.AddCell(j, cell); cell.SetBool(br.ReadBool()); } else if (columnType == "double") { cell = new GridDoubleCell(); row.AddCell(j, cell); cell.SetDouble(br.ReadDouble()); } else if (columnType == "float") { cell = new GridFloatCell(); row.AddCell(j, cell); cell.SetFloat(br.ReadFloat()); } else if (columnType == "int") { cell = new GridIntCell(); row.AddCell(j, cell); cell.SetInt(br.ReadInt()); } else if (columnType == "long") { cell = new GridLongCell(); row.AddCell(j, cell); cell.SetLong((long)br.ReadDouble()); } else if (columnType == "string") { cell = new GridStringCell(); row.AddCell(j, cell); cell.SetString(br.ReadString()); } else { cell = new GridStringCell(); row.AddCell(j, cell); cell.SetString(br.ReadString()); } } } br.Close(); return(grid); }
/// <summary> /// 获取实时数据L2 /// </summary> /// <param name="dataInfo"></param> /// <param name="datas"></param> /// <param name="body"></param> /// <param name="bodyLength"></param> /// <returns></returns> public static int GetLatestDatasLV2(ref LatestDataInfoLV2 dataInfo, List <SecurityLatestDataLV2> datas, byte[] body, int bodyLength) { Binary binary = new Binary(); binary.Write(body, bodyLength); dataInfo.m_size = binary.ReadInt(); for (int i = 0; i < dataInfo.m_size; i++) { SecurityLatestDataLV2 item = new SecurityLatestDataLV2(); item.m_securityCode = binary.ReadString(); item.m_allBuyVol = binary.ReadDouble(); item.m_avgBuyPrice = binary.ReadFloat(); item.m_allSellVol = binary.ReadDouble(); item.m_avgSellPrice = binary.ReadFloat(); item.m_buyVolume6 = binary.ReadInt(); item.m_buyPrice6 = binary.ReadFloat(); item.m_buyVolume7 = binary.ReadInt(); item.m_buyPrice7 = binary.ReadFloat(); item.m_buyVolume8 = binary.ReadInt(); item.m_buyPrice8 = binary.ReadFloat(); item.m_buyVolume9 = binary.ReadInt(); item.m_buyPrice9 = binary.ReadFloat(); item.m_buyVolume10 = binary.ReadInt(); item.m_buyPrice10 = binary.ReadFloat(); item.m_sellVolume6 = binary.ReadInt(); item.m_sellPrice6 = binary.ReadFloat(); item.m_sellVolume7 = binary.ReadInt(); item.m_sellPrice7 = binary.ReadFloat(); item.m_sellVolume8 = binary.ReadInt(); item.m_sellPrice8 = binary.ReadFloat(); item.m_sellVolume9 = binary.ReadInt(); item.m_sellPrice9 = binary.ReadFloat(); item.m_sellVolume10 = binary.ReadInt(); item.m_sellPrice10 = binary.ReadFloat(); datas.Add(item); } binary.Close(); return(1); }
/// <summary> /// 获取实时数据 /// </summary> /// <param name="dataInfo"></param> /// <param name="datas"></param> /// <param name="body"></param> /// <param name="bodyLength"></param> /// <returns></returns> public static int GetLatestDatas(ref LatestDataInfo dataInfo, List <SecurityLatestData> datas, byte[] body, int bodyLength) { Binary binary = new Binary(); binary.Write(body, bodyLength); dataInfo.m_formatType = binary.ReadChar(); dataInfo.m_lv2 = binary.ReadChar(); dataInfo.m_size = binary.ReadInt(); for (int i = 0; i < dataInfo.m_size; i++) { SecurityLatestData item = new SecurityLatestData(); item.m_securityCode = binary.ReadString(); item.m_open = binary.ReadFloat(); item.m_lastClose = binary.ReadFloat(); item.m_close = binary.ReadFloat(); item.m_high = binary.ReadFloat(); item.m_low = binary.ReadFloat(); item.m_volume = binary.ReadDouble(); item.m_amount = binary.ReadDouble(); if (dataInfo.m_formatType == 0) { item.m_buyVolume1 = binary.ReadInt(); item.m_buyPrice1 = binary.ReadFloat(); item.m_buyVolume2 = binary.ReadInt(); item.m_buyPrice2 = binary.ReadFloat(); item.m_buyVolume3 = binary.ReadInt(); item.m_buyPrice3 = binary.ReadFloat(); item.m_buyVolume4 = binary.ReadInt(); item.m_buyPrice4 = binary.ReadFloat(); item.m_buyVolume5 = binary.ReadInt(); item.m_buyPrice5 = binary.ReadFloat(); item.m_sellVolume1 = binary.ReadInt(); item.m_sellPrice1 = binary.ReadFloat(); item.m_sellVolume2 = binary.ReadInt(); item.m_sellPrice2 = binary.ReadFloat(); item.m_sellVolume3 = binary.ReadInt(); item.m_sellPrice3 = binary.ReadFloat(); item.m_sellVolume4 = binary.ReadInt(); item.m_sellPrice4 = binary.ReadFloat(); item.m_sellVolume5 = binary.ReadInt(); item.m_sellPrice5 = binary.ReadFloat(); item.m_innerVol = binary.ReadInt(); item.m_outerVol = binary.ReadInt(); item.m_turnoverRate = binary.ReadFloat(); item.m_openInterest = binary.ReadDouble(); item.m_settlePrice = binary.ReadFloat(); } item.m_date = binary.ReadDouble(); datas.Add(item); } binary.Close(); return(1); }
/// <summary> /// 接收消息方法 /// </summary> /// <param name="message">消息</param> public override void OnReceive(CMessage message) { if (message.m_functionID == FUNCTIONID_USERSECURITY_GETVISITSCOUNT) { UserSecurityVisitsCount visitsCount = new UserSecurityVisitsCount(); Binary br = new Binary(); br.Write(message.m_body, message.m_bodyLength); visitsCount.m_userID = br.ReadInt(); visitsCount.CodesFromString(br.ReadString()); m_visitsCount = visitsCount.m_codes; br.Close(); } else { List <UserSecurityCategory> categories = new List <UserSecurityCategory>(); UserSecurityService.GetCategories(categories, message.m_body, message.m_bodyLength); int categoriesSize = categories.Count; if (message.m_functionID != FUNCTIONID_USERSECURITY_GETCATEGORIES) { message.m_requestID = m_operatorRequestID; } switch (message.m_functionID) { case FUNCTIONID_USERSECURITY_GETCATEGORIES: { m_categories = categories; m_loaded = true; break; } case FUNCTIONID_USERSECURITY_ADDCATEGORIES: { bool add = false; for (int i = 0; i < categoriesSize; i++) { UserSecurityCategory category = null; if (!GetCategory(categories[i].m_categoryID, ref category)) { m_categories.Add(categories[i]); add = true; } } if (!add) { return; } break; } case FUNCTIONID_USERSECURITY_DELETECATEGORIES: { for (int i = 0; i < categoriesSize; i++) { UserSecurityCategory category = null; if (GetCategory(categories[i].m_categoryID, ref category)) { m_categories.Remove(category); } } break; } case FUNCTIONID_USERSECURITY_UPDATECATEGORIES: { for (int i = 0; i < categoriesSize; i++) { UserSecurityCategory updateCategory = categories[i]; int curCategoriesSize = m_categories.Count; for (int j = 0; j < curCategoriesSize; j++) { UserSecurityCategory category = m_categories[j]; if (category.m_categoryID == updateCategory.m_categoryID) { m_categories[j] = updateCategory; break; } } } break; } case FUNCTIONID_USERSECURITY_ADDSECURITIES: { for (int i = 0; i < categoriesSize; i++) { UserSecurityCategory updateCategory = categories[i]; int curCategoriesSize = m_categories.Count; for (int j = 0; j < curCategoriesSize; j++) { UserSecurityCategory category = m_categories[j]; if (category.m_categoryID == updateCategory.m_categoryID) { if (category.m_codes != null && category.m_codes.Length > 0) { updateCategory.m_codes = m_categories[j].m_codes + "," + updateCategory.m_codes; } m_categories[j] = updateCategory; break; } } } break; } case FUNCTIONID_USERSECURITY_DELETESECURITIES: { for (int i = 0; i < categoriesSize; i++) { UserSecurityCategory updateCategory = categories[i]; int curCategoriesSize = m_categories.Count; for (int j = 0; j < curCategoriesSize; j++) { UserSecurityCategory category = m_categories[j]; if (category.m_categoryID == updateCategory.m_categoryID) { if (updateCategory.m_codes != null && updateCategory.m_codes.Length > 0 && category.m_codes != null && category.m_codes.Length > 0) { String[] deleteCodes = updateCategory.m_codes.Split(','); int deleteCodesSize = deleteCodes.Length; Dictionary <String, String> deleteCodesMap = new Dictionary <String, String>(); for (int m = 0; m < deleteCodesSize; m++) { deleteCodesMap[deleteCodes[m]] = ""; } String[] codes = category.m_codes.Split(','); int codesSize = codes.Length; String newCodes = ""; for (int m = 0; m < codesSize; m++) { if (!deleteCodesMap.ContainsKey(codes[m])) { newCodes += codes[m] + ","; } } if (newCodes != null && newCodes.Length > 0) { if (newCodes.Substring(newCodes.Length - 1) == ",") { newCodes = newCodes.Substring(0, newCodes.Length - 1); } } updateCategory.m_codes = newCodes; } m_categories[j] = updateCategory; break; } } } break; } } } base.OnReceive(message); }