using System; using System.Collections.Generic; using System.Linq; using System.Text; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2016/1/19 19:33:11 //Author //Description Create //---------------------------------------------------------------- using Muchinfo.MTPClient.Adapter.Abstract; using Muchinfo.MTPClient.Adapter.Utilities; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Model.Account; using tas; namespace Muchinfo.MTPClient.Adapter.ProtoBuf { public class OrderProtoBufAdapter : OrderAdapter { #region 即期委托请求参数 //ClientSerialNo string optional 客户端流水号 //ClientOrderTime string optional 客户端委托时间 //ClientFlag string optional 终端标识 //AccountID uint32 optional 交易账号 //GoodsID uint32 optional 商品ID //MarketID uint32 optional 市场ID //ValidType int32 optional 校验类型 //OperateType uint32 optional 操作类型: //OrderSrc uint32 optional 单据来源 //OperatorID uint32 optional 操作员账号ID //OrderPrice double optional 委托价格 //OrderQty double optional 委托数量 //BuyOrSell uint32 optional 买卖方向 //BuildType uint32 optional 下单类型 //CurtQuotePrice double optional 保留,计算冻结金额使用 //SpPrice double optional 止盈价格 //SlPrice double optional 止损价格 //PriceMode uint32 optional 取价方式 //TimevalidType uint32 optional 时间有效类型 //VolumeType uint32 optional 成交量类型 #endregion /// /// 即期委托请求转换 /// /// 下单内容对象 /// public override byte[] ToMakeMarketEntrustOrder(Data.Model.NewEntrustOrder entrustOrder, uint userID) { var marketOrder = new OrderReq() { ClientSerialNo = Guid.NewGuid().ToString(), ClientOrderTime = entrustOrder.EntrurstTime.ToString("yyyy-MM-dd HH:mm:ss"), ClientType = (uint)eClientType.CLIENTTYPE_PC_TRADE_CLIENT, //NEW uint32 optional 终端类型 LoginID = entrustOrder.LoginID, //NEW uint32 optional 登陆账号 AccountID = entrustOrder.AccountId, //交易账号==? 资金账号吗 GoodsID = entrustOrder.GoodsId, MarketID = entrustOrder.MarketId,//市场ID NEW ValidType = (int)entrustOrder.ValidType, OperateType = (uint)eOrderOperateType.ORDEROPERATETYPE_NORMAL, OrderSrc = (uint)eOrderSrc.ORDERSRC_CLIENT, OperatorID = entrustOrder.OperaterId, OrderPrice = Convert.ToDouble(entrustOrder.EntrustPrice), MarketMaxSub = (double)entrustOrder.AllowTradeSub, //NEW double optional 市价允许最大偏差(做市)?==允许成交偏差范围 OrderQty = Convert.ToUInt64(entrustOrder.EntrustQuantity), BuyOrSell = (uint)entrustOrder.BuyOrSell, BuildType = (uint)entrustOrder.BuildType, CurtQuotePrice = Convert.ToDouble(entrustOrder.CurtQuotePrice), SlPrice = Convert.ToDouble(entrustOrder.SLPrice), SpPrice = Convert.ToDouble(entrustOrder.SPPrice), PriceMode = (uint)entrustOrder.PriceMode, TimevalidType = (int)eValidType.VALIDTYPE_DR, //NEW uint32 optional 时间有效类型 默认当日有效 TriggerType = entrustOrder.TriggerType, //NEW uint32 optional 预埋单触发类型 TriggerPrice = (double)entrustOrder.TriggerPrice, //NEW double optional 预埋单触发价格 }; if (entrustOrder.OrderFormType == eOrderFormType.Listting) { marketOrder.ListingSelectType = (uint)entrustOrder.ListingSelectType; //NEW uint32 optional 挂牌点选类型 marketOrder.DelistingType = (uint)entrustOrder.DelistingType; ; //NEW uint32 optional 摘牌类型 if (entrustOrder.ListingSelectType == eListingSelectType.LISTINGSELECTTYPE_DELISTING && entrustOrder.DelistingType == eDelistingType.DELISTINGTYPE_SELECTED) { marketOrder.RelatedID = (ulong)entrustOrder.RelationTicket; //NEW uint64 optional 关联单号?==关联委托单号 } } marketOrder.Header = new MessageHead() { AccountID = entrustOrder.AccountId, MarketID = entrustOrder.MarketId, UserID = userID, GoodsID = entrustOrder.GoodsId, UUID = Guid.NewGuid().ToString() }; return ProtoBufHelper.EntitySerialize(marketOrder, false); } public override byte[] ToCancelOrder(NewEntrustOrder entrustOrder, uint userID) { var cancelOrder = new CancelOrderReq() { ClientSerialNo = Guid.NewGuid().ToString(), ClientOrderTime = entrustOrder.EntrurstTime.ToString("yyyy-MM-dd HH:mm:ss"), ClientType = 2, //NEW uint32 optional 终端类型 OperateType = 1, OldOrderId = entrustOrder.RelationTicket, AccountID = entrustOrder.AccountId, OrderSrc = 1, OperatorID = entrustOrder.AccountId }; cancelOrder.Header = new MessageHead() { AccountID = entrustOrder.AccountId, MarketID = entrustOrder.MarketId, UserID = userID, GoodsID = entrustOrder.GoodsId, UUID = Guid.NewGuid().ToString() }; return ProtoBufHelper.EntitySerialize(cancelOrder, false); } public override ResponeEntity ToResponseCancelOrder(object responseData) { var buffer = responseData as byte[]; if (buffer == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } var mmOrderRsp = ProtoBufHelper.EntityDeSerialize(buffer); return new ResponeEntity() { RetCode = mmOrderRsp.RetCode, RetMessage = mmOrderRsp.RetDesc, }; } ///// ///// 竞价交易委托转换 ///// ///// ///// //public override byte[] ToBidMarketEntrustOrder(NewEntrustOrder entrustOrder) //{ // var marketOrder = new BMOrderReq() // { // OrderPrice = Convert.ToDouble(entrustOrder.EntrustPrice), //// 委托价格 // OrderQty = Convert.ToDouble(entrustOrder.EntrustQuantity), //// 委托数量 // BuyOrSell = (uint) entrustOrder.BuyOrSell, //// 买卖方向 // CurrentPrice = Convert.ToDouble(entrustOrder.CurtQuotePrice), // MarketID = uint.MaxValue, //不使用 // //// OpenType ////下单类型:建仓,平仓, // BuildType = (uint)entrustOrder.BuildType, // ////CurrentPrice ////当前成交价格 // OpenMode = (uint) entrustOrder.OrderMode, //// 建仓模式(FAK,FOK) // //CloseMode = (uint) entrustOrder.TradeCloseMode, //// 平仓模式(平今,平历史) // PriceMode =(uint) entrustOrder.PriceMode, // RelateOrderID = entrustOrder.RelationTicket, // TriggerPrice =Convert.ToDouble(entrustOrder.TriggerPrice), // TriggerType = entrustOrder.TriggerType, // OrderFlag = entrustOrder.OrderFlag // }; // marketOrder.OrderHead = ToOrderHead(entrustOrder); // marketOrder.Header = new MessageHead() { AccountId = entrustOrder.AccountId, GoodsId = entrustOrder.GoodsId, UUID = Guid.NewGuid().ToByteArray() }; // return ProtoBufHelper.EntitySerialize(marketOrder, false); //} #region OrderRsp委托单请求应答 //OrderID int64 optional 一级生成的订单号 //ExchOrderID int64 optional 交易所订单号 //OrderTime string optional 接收委托交易的时间 //OrderReq OrderReq optional 委托请求带回 #endregion /// /// 反序列化OTC委托返回 /// /// 数据 /// 单据类型 public override ResponeEntity ToMakeLimitOrder(object responeData) { var buffer = responeData as byte[]; if (buffer == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } var mmOrderRsp = ProtoBufHelper.EntityDeSerialize(buffer); return new ResponeEntity() { RetCode = mmOrderRsp.RetCode, RetMessage = mmOrderRsp.RetDesc, Entity = new OrderDetail() { OrderID = long.Parse(mmOrderRsp.OrderID.ToString()), //EntrustOrderType = (eOrderType)mmOrderRsp, ////todo:生成委托 } }; } public override ResponeEntity ToMixModifyRsp(object responeData) { return null; //var buffer = responeData as byte[]; //if (buffer == null) //{ // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); //} //var mmodifyRsp = ProtoBufHelper.EntityDeSerialize(buffer); //return new ResponeEntity() //{ // RetCode = mmodifyRsp.RetCode, // RetMessage = mmodifyRsp.RetDesc, // Entity = new OrderDetail() // { // //OrderID = mmodifyRsp.OrderID, // ////todo:生成委托 // } //}; } /// /// /// 反序列化竞价委托返回 /// /// /// //public override ResponeEntity ToBidMarketLimitOrder(object responeData) //{ // var buffer = responeData as byte[]; // if (buffer == null) // { // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); // } // var bidOrderRsp = ProtoBufHelper.EntityDeSerialize(buffer); // return new ResponeEntity() // { // RetCode = bidOrderRsp.RetCode, // RetMessage = bidOrderRsp.RetDesc, // Entity = new OrderDetail() // { // OrderID = bidOrderRsp.OrderID, // EntrustOrderType = (eOrderType) bidOrderRsp.OrderType, // ////todo:生成委托 // }, // }; //} //public override byte[] ToMixMarketEntrustOrder(NewEntrustOrder entrustOrder) //{ // var marketOrder = new XMOrderReq() // { // SlPrice = Convert.ToDouble(entrustOrder.SLPrice), // SpPrice = Convert.ToDouble(entrustOrder.SPPrice), // OrderPrice = Convert.ToDouble(entrustOrder.EntrustPrice), //// 委托价格 // OrderQty = Convert.ToDouble(entrustOrder.EntrustQuantity), //// 委托数量 // BuyOrSell = (uint)entrustOrder.BuyOrSell, //// 买卖方向 // CurrentPrice = Convert.ToDouble(entrustOrder.CurtQuotePrice), // MarketID = uint.MaxValue, //不使用 // //// OpenType ////下单类型:建仓,平仓, // BuildType = (uint)entrustOrder.BuildType, // ////CurrentPrice ////当前成交价格 // OpenMode = (uint)entrustOrder.OrderMode, //// 建仓模式(FAK,FOK) // //CloseMode = (uint) entrustOrder.TradeCloseMode, //// 平仓模式(平今,平历史) // PriceMode = (uint)entrustOrder.PriceMode, // RelateOrderID = entrustOrder.RelationTicket, // TriggerPrice = Convert.ToDouble(entrustOrder.TriggerPrice), // TriggerType=entrustOrder.TriggerType, // OrderFlag=entrustOrder.OrderFlag // }; // marketOrder.OrderHead = ToOrderHead(entrustOrder); // marketOrder.Header = new MessageHead() { AccountId = entrustOrder.AccountId, GoodsId = entrustOrder.GoodsId, UUID = Guid.NewGuid().ToByteArray() }; // return ProtoBufHelper.EntitySerialize(marketOrder, false); //} public override byte[] ToMixModifyEntrustOrder(NewEntrustOrder entrustOrder) { return null; // var marketOrder = new XMModifyOrderReq() // { // SLPrice = Convert.ToDouble(entrustOrder.SLPrice), // TPPrice = Convert.ToDouble(entrustOrder.SPPrice), // //OrderID = entrustOrder.RelationTicket, // AccountID = (long)entrustOrder.AccountId, //// 委托数量 // BuyOrSell = (uint)entrustOrder.BuyOrSell, //// 买卖方向 // }; //// marketOrder.Header = ToOrderHead(entrustOrder); // marketOrder.Header = new MessageHead() { AccountID = entrustOrder.AccountId, GoodsID = entrustOrder.GoodsId, UUID = Guid.NewGuid().ToString() }; // return ProtoBufHelper.EntitySerialize(marketOrder, false); } //public override ResponeEntity ToMixMarketLimitOrder(object responeData) //{ // var buffer = responeData as byte[]; // if (buffer == null) // { // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); // } // var bidOrderRsp = ProtoBufHelper.EntityDeSerialize(buffer); // return new ResponeEntity() // { // RetCode = bidOrderRsp.RetCode, // RetMessage = bidOrderRsp.RetDesc, // Entity = new OrderDetail() // { // OrderID = bidOrderRsp.OrderID, // EntrustOrderType = (eOrderType)bidOrderRsp.OrderType, // ////todo:生成委托 // }, // }; //} public override byte[] ToRequestTaRiskRate(uint accountId) { return null; //var taRiskRate = new QueryMemberMonitorReq() //{ // AccountId=accountId //}; //return ProtoBufHelper.EntitySerialize(taRiskRate); } public override ResponeEntity> ToLocalTaRiskRateInfo(object obj) { return null; //var buffer = obj as byte[]; //if (buffer == null) //{ // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); //} //var rspData = ProtoBufHelper.EntityDeSerialize(buffer); //var resultEntity = new ResponeEntity>() //{ // RetCode = rspData.RetCode, // Entity = new List(), //}; //if (rspData.TaRiskRateInfo == null || !rspData.TaRiskRateInfo.Any()) //{ // //todo:查询内容空 // return resultEntity; //} //foreach (var taRiskRate in rspData.TaRiskRateInfo) //{ // var memberAccountEntity= new MemberAccountInfo(); // memberAccountEntity.UsedMargin = taRiskRate.UsedMargin == int.MinValue ? 0 : Convert.ToDecimal(taRiskRate.UsedMargin); // memberAccountEntity.FloatPL = taRiskRate.FloatPL == int.MinValue ? 0 : Convert.ToDecimal(taRiskRate.FloatPL); // memberAccountEntity.NetWorth = taRiskRate.NetWorth == int.MinValue ? 0 : Convert.ToDecimal(taRiskRate.NetWorth); // memberAccountEntity.Rate = taRiskRate.Rate == int.MinValue ? 0 : Convert.ToDecimal(taRiskRate.Rate); // memberAccountEntity.CustomerPosFloatPL = taRiskRate.CustomerPosFloatPL == int.MinValue ? 0 : Convert.ToDecimal(taRiskRate.CustomerPosFloatPL); // memberAccountEntity.SelfPosFloatPL = taRiskRate.SelfPosFloatPL == int.MinValue ? 0 : taRiskRate.SelfPosFloatPL; // memberAccountEntity.CutPosFloatPL = taRiskRate.CutPosFloatPL == int.MinValue ? 0 : taRiskRate.CutPosFloatPL; // memberAccountEntity.AvailMargin = taRiskRate.AvailMargin == int.MinValue ? 0 : Convert.ToDecimal(taRiskRate.AvailMargin); // memberAccountEntity.MemberPositions = GetMemberPositions(rspData); // memberAccountEntity.Balance = taRiskRate.Balance == int.MinValue ? 0 : Convert.ToDecimal(taRiskRate.Balance); // memberAccountEntity.AccountStatus = (eAccountStatus) taRiskRate.MemberStatus;//账户状态 // resultEntity.Entity.Add(memberAccountEntity); //} //return resultEntity; } /// /// 自营盘 被动接收 转单头寸 /// /// /// //private List GetMemberPositions(TaRiskRateInfoReport rspData) //{ // var memberPositions = new List(); // //以商品的GoodsID作为键 // Dictionary memberPositionDic = new Dictionary(); // if (rspData.TaRiskRateInfo == null || !rspData.TaRiskRateInfo.Any()) // { // return memberPositions; // } // else // { // foreach (var taRiskRate in rspData.TaRiskRateInfo) // { // //自营盘 会员 // if (taRiskRate.ProprietaryGoodsRisk != null && taRiskRate.ProprietaryGoodsRisk.Any()) // { // foreach (var proprietaryGoodsRisk in taRiskRate.ProprietaryGoodsRisk) // { // if (!memberPositionDic.ContainsKey(proprietaryGoodsRisk.GoodsID)) // { // memberPositionDic[proprietaryGoodsRisk.GoodsID] = new MemberPosition(); // memberPositionDic[proprietaryGoodsRisk.GoodsID].GoodsCode =proprietaryGoodsRisk.GoodsCode; // memberPositionDic[proprietaryGoodsRisk.GoodsID].GoodsId = (uint)proprietaryGoodsRisk.GoodsID; // } // if ((Direction) proprietaryGoodsRisk.BuyOrSell == Direction.Bid) // { // memberPositionDic[proprietaryGoodsRisk.GoodsID].MemberBuyHolderQty += proprietaryGoodsRisk.QTY == int.MinValue ? 0 : Convert.ToDecimal(proprietaryGoodsRisk.QTY); // memberPositionDic[proprietaryGoodsRisk.GoodsID].MemberBuyFloatPL += proprietaryGoodsRisk.FloatPL == int.MinValue ? 0 : Convert.ToDecimal(proprietaryGoodsRisk.FloatPL); // } // else // { // memberPositionDic[proprietaryGoodsRisk.GoodsID].MemberSellHolderQty += proprietaryGoodsRisk.QTY == int.MinValue ? 0 : Convert.ToDecimal(proprietaryGoodsRisk.QTY); // memberPositionDic[proprietaryGoodsRisk.GoodsID].MemberSellFloatPL += proprietaryGoodsRisk.FloatPL == int.MinValue ? 0 : Convert.ToDecimal(proprietaryGoodsRisk.FloatPL); // } // } // } // //被动接收 投资者转的单 // if (taRiskRate.PassiveGoodsRisk != null && taRiskRate.PassiveGoodsRisk.Any()) // { // foreach (var passiveGoodsRisk in taRiskRate.PassiveGoodsRisk) // { // if (!memberPositionDic.ContainsKey(passiveGoodsRisk.GoodsID)) // { // memberPositionDic[passiveGoodsRisk.GoodsID] = new MemberPosition(); // memberPositionDic[passiveGoodsRisk.GoodsID].GoodsCode = passiveGoodsRisk.GoodsCode; // memberPositionDic[passiveGoodsRisk.GoodsID].GoodsId = (uint)passiveGoodsRisk.GoodsID; // } // if ((Direction)passiveGoodsRisk.BuyOrSell == Direction.Bid) ////风控已把方向转在会员 // { // memberPositionDic[passiveGoodsRisk.GoodsID].SellHolderQty = passiveGoodsRisk.QTY == int.MinValue ? 0 : Convert.ToDecimal(passiveGoodsRisk.QTY); // memberPositionDic[passiveGoodsRisk.GoodsID].SellFloatPL = passiveGoodsRisk.FloatPL == int.MinValue ? 0 : Convert.ToDecimal(passiveGoodsRisk.FloatPL); // } // else // { // memberPositionDic[passiveGoodsRisk.GoodsID].BuyHolderQty = passiveGoodsRisk.QTY == int.MinValue ? 0 : Convert.ToDecimal(passiveGoodsRisk.QTY); // memberPositionDic[passiveGoodsRisk.GoodsID].BuyFloatPL = passiveGoodsRisk.FloatPL == int.MinValue ? 0 : Convert.ToDecimal(passiveGoodsRisk.FloatPL); // } // } // } // //转单头寸 // if (taRiskRate.CutGoodsRisk != null && taRiskRate.CutGoodsRisk.Any()) // { // foreach (var cutGoodsRisk in taRiskRate.CutGoodsRisk) // { // if (!memberPositionDic.ContainsKey(cutGoodsRisk.GoodsID)) // { // memberPositionDic[cutGoodsRisk.GoodsID] = new MemberPosition(); // memberPositionDic[cutGoodsRisk.GoodsID].GoodsCode = cutGoodsRisk.GoodsCode; // memberPositionDic[cutGoodsRisk.GoodsID].GoodsId = (uint) cutGoodsRisk.GoodsID; // } // if ((Direction) cutGoodsRisk.BuyOrSell == Direction.Bid) // { // memberPositionDic[cutGoodsRisk.GoodsID].MemberBuyHolderQty += cutGoodsRisk.QTY == // int.MinValue // ? 0 // : Convert.ToDecimal(cutGoodsRisk.QTY); // memberPositionDic[cutGoodsRisk.GoodsID].MemberBuyFloatPL += cutGoodsRisk.FloatPL == // int.MinValue // ? 0 // : Convert.ToDecimal(cutGoodsRisk.FloatPL); // } // else // { // memberPositionDic[cutGoodsRisk.GoodsID].MemberSellHolderQty += cutGoodsRisk.QTY == // int.MinValue // ? 0 // : Convert.ToDecimal(cutGoodsRisk.QTY); // memberPositionDic[cutGoodsRisk.GoodsID].MemberSellFloatPL += cutGoodsRisk.FloatPL == // int.MinValue // ? 0 // : Convert.ToDecimal(cutGoodsRisk.FloatPL); // } // } // } // } // } // return memberPositionDic.Values.ToList(); //} public override byte[] ToRequestDealClose(DealCloseOrder closeOrder) { return null; //var taRiskRate = new DealCloseSettingReq() //{ // AccountId = (uint)closeOrder.AccountId, // autoId = closeOrder.autoId, // BuyOrSell = (uint)closeOrder.Direction, // status = (uint)closeOrder.Status //}; //return ProtoBufHelper.EntitySerialize(taRiskRate); } public override ResponeEntity ToLocalDealCloseInfo(object obj) { return null; //var buffer = obj as byte[]; //if (buffer == null) //{ // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); //} //var rspData = ProtoBufHelper.EntityDeSerialize(buffer); //return new ResponeEntity() //{ // RetCode = rspData.RetCode, // RetMessage = rspData.RetDesc, // Entity = new DealCloseOrder() // { // autoId = rspData.AccountId, // }, //}; } /// /// 通道交易下单转换 /// /// /// /// public override byte[] ToChannnelEntrustOrder(NewEntrustOrder entrustOrder, uint userID, ulong clientId) { var marketOrder = new ChannelOrderReq() { ClientOrderTime = entrustOrder.EntrurstTime.ToString("yyyy-MM-dd HH:mm:ss"), // 客户端委托时间string ClientType = (uint)eClientType.CLIENTTYPE_PC_TRADE_CLIENT, // 终端类型uint32 AccountID = entrustOrder.AccountId, // 交易账号uint64 GoodsID = entrustOrder.GoodsId, // 商品ID uint32 MarketID = entrustOrder.MarketId, // 市场IDuint32 ValidType = (int)entrustOrder.ValidType, // 有效类型-1当日有效int32 ChannelOperateType = (uint)eChannelOperateType.CHANNELOPERATETYPE_ORDER, // 操作类型:uint32 ChannelOrderSrc = 1, // 单据来源委托来源-1:客户端uint32 HedgeFlag = 0, // 投机套保标志-0:无uint32 OrderPrice = Convert.ToDouble(entrustOrder.EntrustPrice), // 委托价格double BuyOrSell = (uint)entrustOrder.BuyOrSell, // 买卖方向(买卖-0:买uint32 CloseType = 0, // 平仓方式(平仓方式-0:无uint32 PriceMode = (uint)entrustOrder.PriceMode, // 取价方式-1:市价uint32 TimeValidType = (uint)entrustOrder.ValidType, // 时间有效类型uint32 RelatedID = 0, // 关联单号uint64 ChannelBuildType = (uint)entrustOrder.BuildType, ClientSerialNo = Guid.NewGuid().ToString(), LoginID = entrustOrder.LoginID, //NEW uint32 optional 登陆账号 OperatorID = entrustOrder.OperaterId, OrderQty = Convert.ToUInt64(entrustOrder.EntrustQuantity), Header = new MessageHead() { AccountID = entrustOrder.AccountId, MarketID = entrustOrder.MarketId, UserID = userID, GoodsID = entrustOrder.GoodsId, UUID = Guid.NewGuid().ToString(), AccountID2 = clientId, }, IP = entrustOrder.Ip, }; // 资管添加 if (entrustOrder.SLPoint != 0) { marketOrder.SLPoint = (uint) entrustOrder.SLPoint; } if (entrustOrder.SPPoint != 0) { marketOrder.SPPoint = (uint) entrustOrder.SPPoint; } return ProtoBufHelper.EntitySerialize(marketOrder, false); } /// /// 通道SPSL下单转换 /// /// The entrust order. /// The user identifier. /// System.Byte[][]. /// public override byte[] ToChannnelSPSLOrderReq(NewEntrustOrder entrustOrder, uint userID) { var req = new ChannelSPSLOrderReq() { Header = new MessageHead() { AccountID = entrustOrder.AccountId, MarketID = entrustOrder.MarketId, UserID = userID, GoodsID = entrustOrder.GoodsId, UUID = Guid.NewGuid().ToString() }, ClientType = (uint)eClientType.CLIENTTYPE_PC_TRADE_CLIENT, // 终端类型uint32 LoginID = entrustOrder.LoginID, //NEW uint32 optional 登陆账号 AccountID = entrustOrder.AccountId, // 交易账号uint64 GoodsID = entrustOrder.GoodsId, // 商品ID uint32 MarketID = entrustOrder.MarketId, // 市场IDuint32 ValidType = (int)entrustOrder.ValidType, // 有效类型-1当日有效int32 OperateType = (uint)entrustOrder.SPSLOrderType, //1 - 止盈 2 - 止损 3 - 撤单 OrderSrc = 1, //1:客户端 OrderQty = Convert.ToUInt64(entrustOrder.EntrustQuantity), BuyOrSell = (uint)entrustOrder.BuyOrSell, // 买卖方向(买卖-0:买uint32 RelatedID = entrustOrder.SPSLOrderType == SPSLOrderType.Cancel? entrustOrder.RelationTicket:0, // 关联单号uint64 SpPrice = entrustOrder.SPSLOrderType == SPSLOrderType.SPOrder || entrustOrder.SPSLOrderType == SPSLOrderType.SPSL ? (double)entrustOrder.SPPrice : 0.0, SlPrice = entrustOrder.SPSLOrderType == SPSLOrderType.SLOrder || entrustOrder.SPSLOrderType == SPSLOrderType.SPSL ? (double)entrustOrder.SLPrice : 0.0, PriceType = entrustOrder.ChannelPriceMode == ChannelPriceMode.LimitPrice ? 0 : (uint)entrustOrder.ChannelPriceMode, //1 - 最新价 2 - 对手价 3 - 市价 TriggerType = 1, //1 - 触发价 2 - 追踪价差 }; return ProtoBufHelper.EntitySerialize(req, false); } /// /// 通道SPSL下单响应转换 /// /// The data. /// System.Int64. /// /// public override ResponeEntity ToLocalChannnelSPSLRsp(object data) { var byteArr = data as byte[]; if (data == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } var itemResponeList = ProtoBufHelper.EntityDeSerialize(byteArr); var resultEntity = new ResponeEntity() { RetCode = itemResponeList.RetCode, RetMessage = itemResponeList.RetDesc, Entity = new OrderDetail() { OrderID = (long)itemResponeList.OrderID} }; return resultEntity; } } }