public ProtoBufPackage buildPackage() { Trd_GetPositionList.Request.Builder request = Trd_GetPositionList.Request.CreateBuilder(); Trd_GetPositionList.C2S.Builder c2s = Trd_GetPositionList.C2S.CreateBuilder(); TrdHeader.Builder headerBuilder = TrdHeader.CreateBuilder(); headerBuilder.TrdEnv = (int)trdenv; headerBuilder.AccID = (ulong)accID; headerBuilder.TrdMarket = (int)trdMarket; c2s.SetHeader(headerBuilder.Build()); if (filterConditions != null) { c2s.FilterConditions = filterConditions; } if (filterPLRatioMin != null) { c2s.FilterPLRatioMin = (double)filterPLRatioMin; } if (filterPLRatioMax != null) { c2s.FilterPLRatioMax = (double)filterPLRatioMax; } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Trd_GetMaxTrdQtys.Request.Builder request = Trd_GetMaxTrdQtys.Request.CreateBuilder(); Trd_GetMaxTrdQtys.C2S.Builder c2s = Trd_GetMaxTrdQtys.C2S.CreateBuilder(); TrdHeader.Builder headerBuilder = TrdHeader.CreateBuilder(); headerBuilder.TrdEnv = (int)trdenv; headerBuilder.AccID = (ulong)accID; headerBuilder.TrdMarket = (int)trdMarket; c2s.SetHeader(headerBuilder.Build()); c2s.OrderType = (int)orderType; c2s.Code = code; c2s.Price = price; if (orderID != null) { c2s.OrderID = (ulong)orderID; } if (adjustPrice != null) { c2s.AdjustPrice = (bool)adjustPrice; } if (adjustSideAndLimit != null) { c2s.AdjustSideAndLimit = (double)adjustSideAndLimit; } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public object execute(IExecutor handler) { ProtoBufPackage pack = handler.buildPackage(); addHander(pack.NSerialNo, handler); while (!over) { if (connected) { try { socket.Send(pack.pack()); ms.Flush(); }catch (Exception e) { Console.WriteLine(e.GetBaseException()); } break; } sleepMillis(1); } long startTime = Utils.currentTimeMillis(); while (handler.getValue() == null) { if ((Utils.currentTimeMillis() - startTime) > 30 * 1000)//超时 { break; } sleepMillis(1); } return(handler.getValue()); }
public ProtoBufPackage buildPackage() { Trd_GetOrderList.Request.Builder request = Trd_GetOrderList.Request.CreateBuilder(); Trd_GetOrderList.C2S.Builder c2s = Trd_GetOrderList.C2S.CreateBuilder(); TrdHeader.Builder headerBuilder = TrdHeader.CreateBuilder(); headerBuilder.TrdEnv = (int)trdenv; headerBuilder.AccID = (ulong)accID; headerBuilder.TrdMarket = (int)trdMarket; c2s.SetHeader(headerBuilder.Build()); if (filterConditions != null) { c2s.FilterConditions = filterConditions; } if (filterStatusList != null && filterStatusList.Length > 0) { foreach (int orderID in filterStatusList) { c2s.AddFilterStatusList(orderID); } } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Qot_RequestHistoryKL.Request.Builder request = Qot_RequestHistoryKL.Request.CreateBuilder(); Qot_RequestHistoryKL.C2S.Builder c2s = Qot_RequestHistoryKL.C2S.CreateBuilder(); c2s.SetSecurity(Security.CreateBuilder().SetMarket((int)market).SetCode(symbol)); c2s.RehabType = (int)this.rehabType; c2s.KlType = (int)this.klType; c2s.BeginTime = beginTime; c2s.EndTime = endTime; if (this.maxAckKLNum > 0) { c2s.MaxAckKLNum = maxAckKLNum; } if (this.needKLFieldsFlag > 0) { c2s.NeedKLFieldsFlag = needKLFieldsFlag; } if (nextReqKey == null || nextReqKey.Trim().Equals("")) { c2s.NextReqKey = ByteString.CopyFromUtf8("None"); } else { c2s.NextReqKey = ByteString.CopyFromUtf8(nextReqKey); } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Qot_GetHistoryKL.Request.Builder request = Qot_GetHistoryKL.Request.CreateBuilder(); Qot_GetHistoryKL.C2S.Builder c2s = Qot_GetHistoryKL.C2S.CreateBuilder(); c2s.SetSecurity(Security.CreateBuilder().SetMarket((int)market).SetCode(symbol)); c2s.RehabType = (int)this.rehabType; c2s.KlType = (int)this.klType; c2s.BeginTime = beginTime; c2s.EndTime = endTime; if (this.maxAckKLNum > 0) { c2s.MaxAckKLNum = maxAckKLNum; } if (this.needKLFieldsFlag > 0) { c2s.NeedKLFieldsFlag = needKLFieldsFlag; } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Qot_GetSubInfo.Request.Builder request = Qot_GetSubInfo.Request.CreateBuilder(); Qot_GetSubInfo.C2S.Builder c2s = Qot_GetSubInfo.C2S.CreateBuilder(); c2s.IsReqAllConn = isReqAllConn; request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Trd_GetAccList.Request.Builder request = Trd_GetAccList.Request.CreateBuilder(); Trd_GetAccList.C2S.Builder c2s = Trd_GetAccList.C2S.CreateBuilder(); c2s.UserID = (ulong)futuUserID; request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Qot_GetRT.Request.Builder request = Qot_GetRT.Request.CreateBuilder(); Qot_GetRT.C2S.Builder c2s = Qot_GetRT.C2S.CreateBuilder(); c2s.SetSecurity(Security.CreateBuilder().SetMarket((int)market).SetCode(symbol)); request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { KeepAlive.Request.Builder request = KeepAlive.Request.CreateBuilder(); KeepAlive.C2S.Builder c2s = KeepAlive.C2S.CreateBuilder(); c2s.Time = Utils.currentTimeMillis() / 1000; request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); pack.NBodyLen = pack.Bodys.Length; return(pack); }
public ProtoBufPackage buildPackage() { Qot_GetPlateSet.Request.Builder request = Qot_GetPlateSet.Request.CreateBuilder(); Qot_GetPlateSet.C2S.Builder c2s = Qot_GetPlateSet.C2S.CreateBuilder(); c2s.Market = (int)market; c2s.PlateSetType = (int)plateSetType; request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Qot_GetTradeDate.Request.Builder request = Qot_GetTradeDate.Request.CreateBuilder(); Qot_GetTradeDate.C2S.Builder c2s = Qot_GetTradeDate.C2S.CreateBuilder(); c2s.Market = (int)market; c2s.BeginTime = beginTime; c2s.EndTime = endTime; request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return pack; }
public void SocketThread() { Thread heartbeatThread = new Thread(sendHeartbeat); heartbeatThread.IsBackground = true; heartbeatThread.Start(); long startTime = Utils.currentTimeMillis(); while (!over) { try { int size = socket.Available; if (size <= 0) { if ((Utils.currentTimeMillis() - startTime) > 30 * 1000) { // 超过30秒没有收到服务器信息,关闭 socket.Close(); startTime = Utils.currentTimeMillis(); } sleepMillis(1); continue; } else { startTime = Utils.currentTimeMillis(); byte[] buffer = new byte[socket.Available]; var effective = socket.Receive(buffer); MemoryStream ms = new MemoryStream(); ms.Write(buffer, 0, buffer.Length); ProtoBufPackage pack = ProtoBufPackage.unpack(ms); if (pack.NProtoID == InitConnectExec.nProtoID) { connected = true; } Thread handlerThread = new Thread(handler); handlerThread.IsBackground = true; handlerThread.Start(pack); } } catch (Exception e) { over = true; } } handlers = null; socket.Close(); ms.Close(); }
public ProtoBufPackage buildPackage() { Qot_GetSecuritySnapshot.Request.Builder request = Qot_GetSecuritySnapshot.Request.CreateBuilder(); Qot_GetSecuritySnapshot.C2S.Builder c2s = Qot_GetSecuritySnapshot.C2S.CreateBuilder(); foreach (String symbol in symbols) { c2s.AddSecurityList(Security.CreateBuilder().SetMarket((int)market).SetCode(symbol)); } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { InitConnect.Request.Builder request = InitConnect.Request.CreateBuilder(); InitConnect.C2S.Builder c2s = InitConnect.C2S.CreateBuilder(); c2s.SetClientID("testcshap"); c2s.SetClientVer(307); c2s.SetRecvNotify(true); request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); pack.NBodyLen = pack.Bodys.Length; return(pack); }
/** * 初始化协议 * @throws UnknownHostException * @throws IOException */ public void initConnection() { ms = new MemoryStream(); socket = new Socket(SocketType.Stream, ProtocolType.Tcp); IPAddress ipAdd = IPAddress.Parse(ip);; IPEndPoint point = new IPEndPoint(ipAdd, port); socket.Connect(point); InitConnectExec init = new InitConnectExec(); ProtoBufPackage pack = init.buildPackage(); this.addHander(pack.NSerialNo, init); socket.Send(pack.pack()); ms.Flush(); }
public ProtoBufPackage buildPackage() { Trd_SubAccPush.Request.Builder request = Trd_SubAccPush.Request.CreateBuilder(); Trd_SubAccPush.C2S.Builder c2s = Trd_SubAccPush.C2S.CreateBuilder(); foreach (long accID in accIDList) { c2s.AddAccIDList((ulong)accID); } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Qot_GetTicker.Request.Builder request = Qot_GetTicker.Request.CreateBuilder(); Qot_GetTicker.C2S.Builder c2s = Qot_GetTicker.C2S.CreateBuilder(); Security.Builder security = Security.CreateBuilder(); security.Market = (int)market; security.Code = symbol; c2s.SetSecurity(security); c2s.MaxRetNum = maxRetNum; request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Trd_UnlockTrade.Request.Builder request = Trd_UnlockTrade.Request.CreateBuilder(); Trd_UnlockTrade.C2S.Builder c2s = Trd_UnlockTrade.C2S.CreateBuilder(); c2s.Unlock = unlock; if (unlock) { c2s.PwdMD5 = pwdMD5; } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Trd_ModifyOrder.Request.Builder request = Trd_ModifyOrder.Request.CreateBuilder(); Trd_ModifyOrder.C2S.Builder c2s = Trd_ModifyOrder.C2S.CreateBuilder(); ProtoBufPackage pack = new ProtoBufPackage(); TrdHeader.Builder headerBuilder = TrdHeader.CreateBuilder(); headerBuilder.TrdEnv = (int)trdenv; headerBuilder.AccID = (ulong)accID; headerBuilder.TrdMarket = (int)trdMarket; c2s.SetHeader(headerBuilder.Build()); PacketID.Builder packetID = PacketID.CreateBuilder(); packetID.ConnID = (ulong)connID; packetID.SerialNo = (uint)pack.NSerialNo; c2s.SetPacketID(packetID.Build()); c2s.OrderID = (ulong)orderID; c2s.ModifyOrderOp = (int)modifyOrderOp; if (forAll != null) { c2s.ForAll = (bool)forAll; } if (qty != null) { c2s.Qty = (double)qty; } if (price != null) { c2s.Price = (double)price; } if (adjustPrice != null) { c2s.AdjustPrice = (bool)adjustPrice; } if (adjustSideAndLimit != null) { c2s.AdjustSideAndLimit = (double)adjustSideAndLimit; } request.SetC2S(c2s); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Trd_GetFunds.Request.Builder request = Trd_GetFunds.Request.CreateBuilder(); Trd_GetFunds.C2S.Builder c2s = Trd_GetFunds.C2S.CreateBuilder(); TrdHeader.Builder headerBuilder = TrdHeader.CreateBuilder(); headerBuilder.TrdEnv = (int)trdenv; headerBuilder.AccID = (ulong)accID; headerBuilder.TrdMarket = (int)trdMarket; c2s.Header = headerBuilder.Build(); request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
/** * 发送心跳包 */ public void sendHeartbeat() { while (!over && keepAlive) { try { sleepMillis(10 * 1000);// 10s发送一次心跳 KeepAliveExec keepAlive = new KeepAliveExec(); ProtoBufPackage pack = keepAlive.buildPackage(); addHander(pack.NSerialNo, keepAlive); socket.Send(pack.pack()); ms.Flush(); } catch (Exception e) { } } }
public ProtoBufPackage buildPackage() { Trd_GetHistoryOrderFillList.Request.Builder request = Trd_GetHistoryOrderFillList.Request.CreateBuilder(); Trd_GetHistoryOrderFillList.C2S.Builder c2s = Trd_GetHistoryOrderFillList.C2S.CreateBuilder(); TrdHeader.Builder headerBuilder = TrdHeader.CreateBuilder(); headerBuilder.TrdEnv = (int)trdenv; headerBuilder.AccID = (ulong)accID; headerBuilder.TrdMarket = (int)trdMarket; c2s.SetHeader(headerBuilder.Build()); c2s.FilterConditions = filterConditions; request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Qot_Sub.Request.Builder request = Qot_Sub.Request.CreateBuilder(); Qot_Sub.C2S.Builder c2s = Qot_Sub.C2S.CreateBuilder(); foreach (String symbol in symbols) { c2s.AddSecurityList(Security.CreateBuilder().SetMarket((int)market).SetCode(symbol)); } c2s.IsSubOrUnSub = isSubOrUnSub; foreach (SubType subType in subTypes) { c2s.AddSubTypeList((int)subType); } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Qot_GetHoldingChangeList.Request.Builder request = Qot_GetHoldingChangeList.Request.CreateBuilder(); Qot_GetHoldingChangeList.C2S.Builder c2s = Qot_GetHoldingChangeList.C2S.CreateBuilder(); c2s.SetSecurity(Security.CreateBuilder().SetMarket((int)market).SetCode(symbol)); c2s.HolderCategory = holderCategory; if (beginTime != null) { c2s.BeginTime = beginTime; } if (endTime != null) { c2s.EndTime = endTime; } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Qot_GetStaticInfo.Request.Builder request = Qot_GetStaticInfo.Request.CreateBuilder(); Qot_GetStaticInfo.C2S.Builder c2s = Qot_GetStaticInfo.C2S.CreateBuilder(); c2s.Market = (int)market; c2s.SecType = (int)secType; if (symbols != null && symbols.Length > 0) { foreach (String symbol in symbols) { c2s.AddSecurityList(Security.CreateBuilder().SetMarket((int)market).SetCode(symbol)); } } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Trd_PlaceOrder.Request.Builder request = Trd_PlaceOrder.Request.CreateBuilder(); Trd_PlaceOrder.C2S.Builder c2s = Trd_PlaceOrder.C2S.CreateBuilder(); ProtoBufPackage pack = new ProtoBufPackage(); TrdHeader.Builder headerBuilder = TrdHeader.CreateBuilder(); headerBuilder.TrdEnv = (int)trdenv; headerBuilder.AccID = (ulong)accID; headerBuilder.TrdMarket = (int)trdMarket; c2s.Header = headerBuilder.Build(); PacketID.Builder packetID = PacketID.CreateBuilder(); packetID.ConnID = (ulong)connID; packetID.SerialNo = (uint)pack.NSerialNo; c2s.PacketID = packetID.Build(); c2s.TrdSide = (int)trdSide; c2s.OrderType = (int)orderType; c2s.Code = code; c2s.Qty = qty; c2s.Price = price; if (adjustPrice != null) { c2s.AdjustPrice = (bool)adjustPrice; } if (adjustSideAndLimit != null) { c2s.AdjustSideAndLimit = (double)adjustSideAndLimit; } request.SetC2S(c2s); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Qot_GetOptionChain.Request.Builder request = Qot_GetOptionChain.Request.CreateBuilder(); Qot_GetOptionChain.C2S.Builder c2s = Qot_GetOptionChain.C2S.CreateBuilder(); c2s.SetOwner(Security.CreateBuilder().SetMarket((int)market).SetCode(symbol)); c2s.BeginTime = beginTime; c2s.EndTime = endTime; if (type >= 0) { c2s.Type = type; } if (this.condition >= 0) { c2s.Condition = condition; } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public ProtoBufPackage buildPackage() { Qot_GetHistoryKLPoints.Request.Builder request = Qot_GetHistoryKLPoints.Request.CreateBuilder(); Qot_GetHistoryKLPoints.C2S.Builder c2s = Qot_GetHistoryKLPoints.C2S.CreateBuilder(); foreach (String symbol in symbols) { c2s.AddSecurityList(Security.CreateBuilder().SetMarket((int)market).SetCode(symbol)); } c2s.RehabType = (int)this.rehabType; c2s.KlType = (int)this.klType; c2s.NoDataMode = (int)noDataMode; int count = 0; foreach (String timeList in timeLists) { c2s.AddTimeList(timeList); count++; if (count == 5) { break; } } if (maxReqSecurityNum > 0) { c2s.MaxReqSecurityNum = maxReqSecurityNum; } if (needKLFieldsFlag > 0) { c2s.NeedKLFieldsFlag = needKLFieldsFlag; } request.SetC2S(c2s); ProtoBufPackage pack = new ProtoBufPackage(); pack.NProtoID = nProtoID; pack.Bodys = request.Build().ToByteArray(); return(pack); }
public static ProtoBufPackage unpack(MemoryStream inputStream) { ProtoBufPackage pack = new ProtoBufPackage(); inputStream.Position = 0; byte[] bytes = new byte[2]; inputStream.Read(bytes, 0, 2); bytes = new byte[4]; inputStream.Read(bytes, 0, 4); pack.NProtoID = (int)unintbyte2long(bytes); bytes = new byte[2]; inputStream.Read(bytes, 0, 2); bytes = new byte[4]; inputStream.Read(bytes, 0, 4); pack.NSerialNo = (int)unintbyte2long(bytes); bytes = new byte[4]; inputStream.Read(bytes, 0, 4); pack.NBodyLen = (int)unintbyte2long(bytes); bytes = new byte[20]; inputStream.Read(bytes, 0, 20); pack.ArrBodySHA1 = bytes; bytes = new byte[8]; inputStream.Read(bytes, 0, 8); bytes = new byte[pack.NBodyLen]; inputStream.Read(bytes, 0, bytes.Length); pack.Bodys = bytes; inputStream.Flush(); return(pack); }