//----------------------------------------------------------------
//Module Name: Muchinfo.MTPClient.Adapter
//Purpose:
//CopyRight: Muchinfo
//History:
//----------------------------------------------------------------
//DateTime 2016/1/13 13:45:06
//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.Helper;
using Muchinfo.MTPClient.Data.Model;
using Muchinfo.MTPClient.Data.Model.Account;
using Muchinfo.MTPClient.Data.Model.GoodRules;
using Muchinfo.MTPClient.Data.Model.Message;
using System;
using System.Collections.Generic;
using System.Linq;
using tas;
namespace Muchinfo.MTPClient.Adapter.ProtoBuf
{
///
/// Class AccountProtobufAdapter.
///
public class AccountProtobufAdapter : AccountAdapter
{
///
/// 通知查询转换
///
/// The login identifier.
/// The last notice identifier.
/// System.Byte[][].
public override byte[] ToReqeustNoticeQuery(ulong loginId, long lastNoticeId)
{
var baseQueryReq = new NoticeQueryReq()
{
Header = new MessageHead() { },
LoginID = loginId,
LastNoticeId = (uint)lastNoticeId,
//MsgType = 0,
};
return ProtoBufHelper.EntitySerialize(baseQueryReq);
}
///
/// 通知查询转换-应答
///
/// 数据内容
///
public override ResponeEntity> ResponeNoticeQuery(object data)
{
var byteArr = data as byte[];
if (data == null)
{
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
}
var itemRespone = ProtoBufHelper.EntityDeSerialize(byteArr);
var resultEntity = new ResponeEntity>()
{
RetCode = itemRespone.RetCode,
RetMessage = itemRespone.RetDesc,
Entity = new List()
};
foreach (var item in itemRespone.NoticeInfoList)
{
var itemNoticeInfo = BufToNoticeInfo(item);
resultEntity.Entity.Add(itemNoticeInfo);
}
return resultEntity;
}
///
/// 通知item转换
///
///
///
private NoticeMsg BufToNoticeInfo(NoticeInfo tasModel)
{
var localModel = new NoticeMsg()
{
MSG_ID = tasModel.NoticeId, //NoticeId id uint32
TITLE = tasModel.NoticeTitle, //NoticeTitle 标题 string
CONTENT = tasModel.NoticeContent, //NoticeContent 内容 string
Sending_Time = TimeHelper.ConvertStringToDateTime(tasModel.NoticeTime.ToString()),
NoticeType = tasModel.NoticeType, //NoticeType 类型 uint32
};
return localModel;
}
///
/// 风险协议书转换
///
/// 上次更新配置时间
///
public override byte[] ToReqeustRiskTipQueryReq(ulong RiskMsgUTime)
{
var baseQueryReq = new RiskTipQueryReq()
{
Header = new MessageHead() { },
RiskMsgUTime = RiskMsgUTime,
};
return ProtoBufHelper.EntitySerialize(baseQueryReq);
}
///
/// 风险协议书转换-应答
///
/// 数据内容
///
public override ResponeEntity ResponeRiskTipQueryReq(object data)
{
var byteArr = data as byte[];
if (data == null)
{
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
}
var itemRespone = ProtoBufHelper.EntityDeSerialize(byteArr);
var resultEntity = new ResponeEntity()
{
RetCode = itemRespone.RetCode,
RetMessage = itemRespone.RetDesc,
Entity = new RiskTipQueryRspModel()
{
TipTitle = itemRespone.TipTitle,
TipMsg = itemRespone.TipMsg
}
};
return resultEntity;
}
///
/// 市场转换
///
/// 上次更新配置时间
///
public override byte[] ToReqeustMarketsQueryReq(ulong MarketsUTime)
{
var baseQueryReq = new MarketsQueryReq()
{
Header = new MessageHead() { },
MarketsUTime = MarketsUTime,
};
return ProtoBufHelper.EntitySerialize(baseQueryReq);
}
///
/// 市场转换-应答
///
/// 数据内容
///
public override ResponeEntity> ResponeMarketsQueryReq(object data)
{
var byteArr = data as byte[];
if (data == null)
{
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
}
var itemRespone = ProtoBufHelper.EntityDeSerialize(byteArr);
var resultEntity = new ResponeEntity>()
{
RetCode = itemRespone.RetCode,
RetMessage = itemRespone.RetDesc,
Entity = new List()
{
}
};
foreach (var item in itemRespone.MarketsList)
{
var itemMarketsInfo = BufToMarketsInfo(item);
resultEntity.Entity.Add(itemMarketsInfo);
}
return resultEntity;
}
///
/// 市场item转换
///
///
///
private MarketsInfoModel BufToMarketsInfo(MarketsInfo tasModel)
{
var localModel = new MarketsInfoModel()
{
MarketID = tasModel.MarketID,// 市场id uint32
MarketName = tasModel.MarketName,// 市场名称 string
TradeMode = (eTradeMode)tasModel.TradeMode,// 交易模式 uint32
TradeProperty = (eTradeProperty)tasModel.TradeProperty,//交易属性
};
return localModel;
}
///
/// 枚举常量字典转换
///
/// 上次更新配置时间
///
public override byte[] ToReqeustDictionaryQueryReq(ulong DirctionaryUTime)
{
var baseQueryReq = new DictionaryQueryReq()
{
Header = new MessageHead() { },
DirctionaryUTime = DirctionaryUTime,
};
return ProtoBufHelper.EntitySerialize(baseQueryReq);
}
///
/// 枚举常量字典转换-应答
///
/// 数据内容
///
public override ResponeEntity> ResponeDictionaryQueryReq(object data)
{
var byteArr = data as byte[];
if (data == null)
{
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
}
var itemRespone = ProtoBufHelper.EntityDeSerialize(byteArr);
var resultEntity = new ResponeEntity>()
{
RetCode = itemRespone.RetCode,
RetMessage = itemRespone.RetDesc,
Entity = new List()
{
}
};
foreach (var item in itemRespone.DictionaryList)
{
var itemDictionaryList = BufToDictionaryList(item);
resultEntity.Entity.Add(itemDictionaryList);
}
return resultEntity;
}
///
/// 枚举常量字典item转换
///
///
///
private DictionaryInfoModel BufToDictionaryList(DictionaryInfo tasModel)
{
var localModel = new DictionaryInfoModel()
{
FieldCode = tasModel.FieldCode, // 枚举类型代码 string
FieldName = tasModel.FieldName,// 枚举类型名称 string
Key = tasModel.Key,// 枚举值 string
Value = tasModel.Value,// 枚举名称 string
};
return localModel;
}
///
/// 错误码字典转换
///
/// 上次更新配置时间
///
public override byte[] ToReqeustErrorCodeQueryReq(ulong ErrorcodeUTime)
{
var baseQueryReq = new ErrorCodeQueryReq()
{
Header = new MessageHead() { },
ErrorcodeUTime = ErrorcodeUTime,
};
return ProtoBufHelper.EntitySerialize(baseQueryReq);
}
///
/// 错误码字典转换-应答
///
/// 数据内容
///
public override ResponeEntity> ResponeErrorCodeQueryReq(object data)
{
var byteArr = data as byte[];
if (data == null)
{
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
}
var itemRespone = ProtoBufHelper.EntityDeSerialize(byteArr);
var resultEntity = new ResponeEntity>()
{
RetCode = itemRespone.RetCode,
RetMessage = itemRespone.RetDesc,
Entity = new List()
{
}
};
foreach (var item in itemRespone.ErrorCodeList)
{
var itemErrorCodeList = BufToErrorCodeList(item);
resultEntity.Entity.Add(itemErrorCodeList);
}
return resultEntity;
}
///
/// 错误码字典转换item转换
///
///
///
private ErrorCodeInfoModel BufToErrorCodeList(ErrorCodeInfo tasModel)
{
var localModel = new ErrorCodeInfoModel()
{
ErrorCode = tasModel.ErrorCode, // 错误码 string
ErrorMsg = tasModel.ErrorMsg,// 提示信息 string
};
return localModel;
}
///
/// 市场运行计划转换
///
/// 交易日
///
public override byte[] ToReqeustMarketRunQueryReq(string TradeDate)
{
var baseQueryReq = new MarketRunQueryReq()
{
Header = new MessageHead() { },
TradeDate = TradeDate,
};
return ProtoBufHelper.EntitySerialize(baseQueryReq);
}
///
/// 市场运行计划转换-应答
///
/// 数据内容
///
public override ResponeEntity ResponeMarketRunQueryReq(object data)
{
var byteArr = data as byte[];
if (data == null)
{
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
}
var itemRespone = ProtoBufHelper.EntityDeSerialize(byteArr);
var resultEntity = new ResponeEntity()
{
RetCode = itemRespone.RetCode,
RetMessage = itemRespone.RetDesc,
Entity = new MarketRunQueryRspModel()
{
TradeDate = itemRespone.TradeDate, //交易日 string
//MarketRunList 市场及其日计划列表 MarketRun
}
};
foreach (var item in itemRespone.MarketRunList)
{
var itemMarketRun = BufToMarketRun(item);
resultEntity.Entity.MarketRunList.Add(itemMarketRun);
}
return resultEntity;
}
///
/// 市场运行计划item转换
///
///
///
private MarketRunModel BufToMarketRun(MarketRun tasModel)
{
var localModel = new MarketRunModel()
{
MarketId = tasModel.MarketId, // 市场id uint32
//DayRunList 市场日运行计划表 DayRun
};
foreach (var item in tasModel.DayRunList)
{
var itemDayRun = BufToDayRun(item);
localModel.DayRunList.Add(itemDayRun);
}
return localModel;
}
///
/// 市场日运行计划表item转换
///
///
///
private DayRunModel BufToDayRun(DayRun tasModel)
{
var localModel = new DayRunModel()
{
TradeWeekDay = tasModel.TradeWeekDay,// 交易归属日 uint32
RunStep = tasModel.RunStep,// 运行阶段 uint32
StartWeekDay = tasModel.StartWeekDay,// 起始周几 uint32
StartTime = tasModel.StartTime,// 起始时间 string
EndWeekDay = tasModel.EndWeekDay,// 结束周几 uint32
EndTime = tasModel.EndTime,// 结束时间 string
};
return localModel;
}
///
/// 终端系统参数查询转换
///
/// 配置时间
///
public override byte[] ToReqeustConfigQueryReq(ulong ConfigUTime)
{
var baseQueryReq = new ConfigQueryReq()
{
Header = new MessageHead() { },
// ConfigUTime = ConfigUTime,
};
return ProtoBufHelper.EntitySerialize(baseQueryReq);
}
///
/// 终端系统参数查询应答转换
///
/// 数据内容
///
public override ResponeEntity> ResponeConfigQueryReq(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 List() { }
};
foreach (var item in itemResponeList.ConfigInfoList)
{
var good = BufToConfigInfo(item);
resultEntity.Entity.Add(good);
}
return resultEntity;
}
///
/// 终端系统参数item转换
///
///
///
private ConfigInfoModel BufToConfigInfo(ConfigInfo tasModel)
{
var localModel = new ConfigInfoModel()
{
ParamCode = tasModel.ParamCode,//参数代码 string
ParamName = tasModel.ParamName,// 参数名称 string
ParamValue = tasModel.ParamValue,// 参数值 string
ParamRemark = tasModel.ParamRemark,//说明 string
};
return localModel;
}
///
/// 商品查询请求转换-管理端查询
///
/// 账号信息
///
public override byte[] ToReqeustGoodsQueryReq(ulong GoodsUTime)
{
var baseGoodsQueryReq = new GoodsQueryReq()
{
Header = new MessageHead() { },
GoodsUTime = GoodsUTime,
};
return ProtoBufHelper.EntitySerialize(baseGoodsQueryReq);
}
///
/// 商品查询回应转换-管理端返回
///
/// 数据内容
///
public override ResponeEntity> ResponeGoodsQueryReq(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 List() { }
};
foreach (var item in itemResponeList.GoodsList)
{
var good = BufToQuoteGoods(item);
resultEntity.Entity.Add(good);
}
return resultEntity;
}
///
/// 商品转换
///
///
///
private QuoteGoods BufToQuoteGoods(GoodsInfo good)
{
var category = QuoteCategoryType.PreciousMetal; //暂时随意定义
var entityPara = new GoodsParameters()
{
AgreeUnit = Convert.ToDecimal(good.AgreeUnit),
GoodsCode = good.GoodsCode,
GoodsId = good.GoodsId,
GoodsName = good.GoodsName,
ExchAreaID = 250,
MoneyMode = eMoneyMode.MONEYMODE_MARGIN,
HqExchFigures = (int)good.DecimalPlace,
// TradeMode = eTradeMode., // 交易模式
////todo:服务未返回,设置调试值
ReckonRate = 1,
};
if (good.MarketID == 9)//全额转让市场,其他都是保证金市场
{
entityPara.MoneyMode = eMoneyMode.MONEYMODE_PAY;
}
var localGoods = new QuoteGoods("", good.GoodsCode, good.GoodsCode, category)
{
EndDate = good.EndDate, //EndDate 交割结束日期
BeginDate = good.BeginDate,//BeginDate 交割起始日期
PGoodsID1 = good.PGoodsID1,
PGoodsID2 = good.PGoodsID2,
MinDeliveryQty = good.MinDeliveryQty,//LimitSum 最小交割手数
DeliveryGoodsName = good.DeliveryGoodsName, //DeliveryGoodsName 交割品种名称
DeliveryGoodsCode = good.DeliveryGoodsCode,//DeliveryGoodsCode 交割品种代码
DeliveryGoodsId = good.DeliveryGoodsId,//DeliveryGoodsId 交割品种代码
GoodsUnit = good.GoodsUnit, //GoodsUnit 商品单位 uint32
AgreeUnit = (uint)good.AgreeUnit, //AgreeUnit 合约单位 uint32
Currency = good.Currency,//Currency 报价货币 uint32
DecimalPlaces = (int)good.DecimalPlace,//DecimalPlace 价格小数位 uint32
ListingDate = good.ListingDate, //ListingDate 上市时间 int32
MarketID = good.MarketID, //MarketID 商品所属市场ID uint32
Name = good.GoodsName,//GoodsName 商品名称 String
GoodsCode = good.GoodsCode,//GoodsCode 商品代码 String
GoodsId = good.GoodsId, //商品id uint32
GoodsParameters = entityPara,
DeliveryFlag = good.DeliveryFlag, //DeliveryFlag 是否交割 uint32 0:不交割1:要交割
DeliveryGoodsUnit = good.DeliveryGoodsUnit, //DeliveryGoodsUnit 交割商品单位 string
XDeliveryRatio = good.XDeliveryRatio,//XDeliveryRatio 主辅商品比的主手数 uint32 如3手主+2手辅=1份基准头寸
PDeliveryRatio1 = good.PDeliveryRatio1, //PDeliveryRatio1 主辅商品比的辅手数 uint32
PDeliveryRatio2 = good.PDeliveryRatio2,
P1Type = good.P1Type,
P2Type = good.P2Type,
P1value = (uint)good.P1value,
P2value = (uint)good.P2value,
GoodsPMList = ToLocalPriceMove(good.GoodsPMList),
ClosePriceMode = good.ClosePriceMode,
ClosePriceParam = good.ClosePriceParam,
Currencyid = good.Currencyid,
DelistingMode = good.DelistingMode,
GoodsStatus = good.GoodsStatus,
GoodsType = good.GoodsType,
GroupID = good.GroupID,
InnerDealMode = good.InnerDealMode,
IsBuyLimited = good.IsBuyLimited,
Lotsize = good.Lotsize,
QtyDecimalPlace = good.QtyDecimalPlace,
QuoteMinUnit = good.QuoteMinUnit
};
return localGoods;
}
private List ToLocalPriceMove(List priceMoveLst)
{
List retLst = new List();
if (priceMoveLst != null)
{
foreach (var item in priceMoveLst)
{
PriceMoveModel pricemove = new PriceMoveModel()
{
PriceMoveID = item.PriceMoveID,
PriceMoveType = item.PriceMoveType,
PriceMoveDesc = item.PriceMoveDesc
};
retLst.Add(pricemove);
}
}
return retLst;
}
///
/// 获取最后更新时间转换
///
///
public override byte[] ToReqeustLastUpdateTimeReq()
{
var baseReq = new LastUpdateTimeReq()
{
Header = new MessageHead() { },
};
return ProtoBufHelper.EntitySerialize(baseReq);
}
///
/// 获取最后更新时间回应转换
///
/// 数据内容
///
public override ResponeEntity ResponeLastUpdateTimeReq(object data)
{
var byteArr = data as byte[];
if (data == null)
{
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
}
var itemRespone = ProtoBufHelper.EntityDeSerialize(byteArr);
var result = new ResponeEntity()
{
RetCode = itemRespone.RetCode,
RetMessage = itemRespone.RetDesc,
Entity = new LastUpdateTimeModel()
{
TradeDate = itemRespone.TradeDate,
RiskMsgUTime = itemRespone.RiskMsgUTime,
ConfigUTime = itemRespone.ConfigUTime,
GoodsUTime = itemRespone.GoodsUTime,
MarketsUTime = itemRespone.MarketsUTime,
ErrorcodeUTime = itemRespone.ErrorcodeUTime,
DirctionaryUTime = itemRespone.DirctionaryUTime,
}
};
return result;
}
///
/// 登录查询请求转换
///
/// 账号信息
///
public override byte[] ToReqeustLoginQueryReq(ulong LoginID, string QueryItem)
{
QueryItem = QueryItem == "0" ? "" : QueryItem;
var baseReq = new LoginQueryReq()
{
Header = new MessageHead() { },
LoginID = LoginID,
QueryItem = QueryItem
};
baseReq.Header.UserID = ProtoBufHelper.Head.UserID;
return ProtoBufHelper.EntitySerialize(baseReq, false);
}
///
/// 登录查询回应转换
///
/// 数据内容
///
public override ResponeEntity ResponeLoginQueryReq(object data)
{
var byteArr = data as byte[];
if (byteArr == null)
{
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
}
var itemRespone = ProtoBufHelper.EntityDeSerialize(byteArr);
var resultEntity = new ResponeEntity()
{
RetCode = itemRespone.RetCode,
RetMessage = itemRespone.RetDesc,
Entity = new AccountBaseInfoModel()
{
ServerLastNoticeId = itemRespone.ServerLastNoticeId
},
};
var accountInfo = resultEntity.Entity;
accountInfo.TAAccountList = ToLocalTAAccountList(itemRespone.TAAccountList); // 账户列表
accountInfo.TradeAccount = ToLocalTradeAccount(itemRespone.AccountInfo); ////账号信息
accountInfo.GoodsRuleAndFeeList = ToLocalGoodsRuleAndFeeList(itemRespone.GoodsRuleAndFeeList); ////商品交易规则和费用规则列表
accountInfo.LastUpdateTimeList = ToLocalLastUpdateTimeList(itemRespone.ParamValues); ////最后更新时间列表
return resultEntity;
}
///
/// 菜单转换
///
///
///
public override byte[] ToReqeustFuncMenuQueryReq(ulong MenuUTime)
{
var baseQueryReq = new FuncMenuReq()
{
Header = new MessageHead() { },
MenuUTime = MenuUTime,
};
return ProtoBufHelper.EntitySerialize(baseQueryReq);
}
///
/// 菜单权限列表转换
///
///
///
private List ToLocalSysMenuItems(List FuncMenu)
{
var SysMenuList = new List();
if (FuncMenu == null || FuncMenu.Count <= 0)
{
return SysMenuList;
}
foreach (var item in FuncMenu)
{
var menu = BuildFuncMenu(item);
SysMenuList.Add(menu);
}
return SysMenuList;
}
///
/// 账户列表转换
///
///
///
private List ToLocalTAAccountList(List tAAccountAll)
{
var itemResultList = new List();
if (tAAccountAll == null)
{
return itemResultList;
}
foreach (var item in tAAccountAll)
{
var type = ConverTAAccountAllModel(item);
itemResultList.Add(type);
}
return itemResultList;
}
private TAAccountAllModel ConverTAAccountAllModel(tas.TAAccountAll tasModel)
{
var model = new TAAccountAllModel();
var goodsPositionList = new List();
var marketsIdList = new List();
#region 资金信息/资金账户信息
var fundsAccounts = new FundsAccount()
{
AccountId = tasModel.TaAccountInfo.AccountId,// 账户id
TradeStatus = tasModel.TaAccountInfo.TradeStatus,
Currency = tasModel.TaAccountInfo.Currency,
IsMain = tasModel.TaAccountInfo.IsMain,
ParentAccountID = tasModel.TaAccountInfo.ParentAccountID,
TAAccountType = tasModel.TaAccountInfo.TAAccountType,
RelatedMainAccountID = tasModel.TaAccountInfo.RelatedMainAccountID,
Balance = (decimal)tasModel.TaAccountInfo.Balance,// 期初余额
CurrentBalance = (decimal)tasModel.TaAccountInfo.CurrentBalance,// 期末余额
UsedMargin = (decimal)tasModel.TaAccountInfo.UsedMargin,// 占用保证金
FreezeMargin = (decimal)tasModel.TaAccountInfo.FreezeMargin,// 冻结保证金
OtherFreezeMargin = (decimal)tasModel.TaAccountInfo.OtherFreezeMargin,
FreezeCharge = (decimal)tasModel.TaAccountInfo.FreezeCharge,
MortgageCredit = (decimal)tasModel.TaAccountInfo.MortgageCredit,
OtherCredit = (decimal)tasModel.TaAccountInfo.OtherCredit,
OutAmountFreeze = (decimal)tasModel.TaAccountInfo.OutAmountFreeze,
OutAmount = (decimal)tasModel.TaAccountInfo.OutAmount,// 今日出金
InAmount = (decimal)tasModel.TaAccountInfo.InAmount,// 今日入金
PayCharge = (decimal)tasModel.TaAccountInfo.PayCharge,
CreditIncrease = (decimal)tasModel.TaAccountInfo.CreditIncrease,
CreditDecrease = (decimal)tasModel.TaAccountInfo.CreditDecrease,
OtherCreditIncrease = (decimal)tasModel.TaAccountInfo.OtherCreditIncrease,
OtherCreditDecrease = (decimal)tasModel.TaAccountInfo.OtherCreditDecrease,
TransferAmount = (decimal)tasModel.TaAccountInfo.TransferAmount,
OtherPay = (decimal)tasModel.TaAccountInfo.OtherPay,
OtherIncome = (decimal)tasModel.TaAccountInfo.OtherIncome,
ClosePL = (decimal)tasModel.TaAccountInfo.ClosePL,// 今日平仓盈亏
OutThreshold = (decimal)tasModel.TaAccountInfo.OutThreshold, // 出金阀值
CurrencyID = tasModel.TaAccountInfo.Currencyid, //todo:服务端需返回此字段
};
model.FundsAccounts = fundsAccounts;
#endregion
#region 持仓头寸列表
foreach (var item in tasModel.TradePositionList)
{
var goodsPM = new TradePositionModel()
{
GoodsId = item.GoodsId, // 商品id
BuyFrozenQty = item.BuyFrozenQty, // 买持仓冻结
BuyOtherFrozenQty = item.BuyOtherFrozenQty, // 买持仓其他冻结
SellFrozenQty = item.SellFrozenQty, // 卖持仓冻结
SellOtherFrozenQty = item.SellOtherFrozenQty, // 卖持仓其他冻结
BuyCurPositionQty = item.BuyCurPositionQty, //买当前持仓数量 uint32
BuyCurHolderAmount = item.BuyCurHolderAmount, //买当前持仓金额 double
SellCurPositionQty = item.SellCurPositionQty, //卖当前持仓数量 uint32
SellCurHolderAmount = item.SellCurHolderAmount, //卖当前持仓金额 double
};
goodsPositionList.Add(goodsPM);
}
model.GoodsPositionList = goodsPositionList;
#endregion
#region 市场权限列表
foreach (var item in tasModel.MarketsIdList)
{
marketsIdList.Add(item);
}
model.MarketsIdList = marketsIdList;
#endregion
return model;
}
///
/// 商品交易规则和费用规则列表转换
///
///
///
private List ToLocalGoodsRuleAndFeeList(List goodsRuleAndFee)
{
var ruleAndFeeList = new List();
if (goodsRuleAndFee == null || goodsRuleAndFee.Count <= 0)
{
return ruleAndFeeList;
}
foreach (var item in goodsRuleAndFee)
{
var feeRule = ConverFeeRuleType(item);
ruleAndFeeList.Add(feeRule);
}
return ruleAndFeeList;
}
///
/// 最后更新时间列表
///
///
///
private List ToLocalLastUpdateTimeList(List lastUpdateTimeKeyValue)
{
var lastUpdateTimeList = new List();
if (lastUpdateTimeKeyValue == null || lastUpdateTimeKeyValue.Count <= 0)
{
return lastUpdateTimeList;
}
foreach (var item in lastUpdateTimeKeyValue)
{
if (string.IsNullOrEmpty(item.Key))
{
continue;
}
var itemKeyValue = ConverLastUpdateTime(item);
lastUpdateTimeList.Add(itemKeyValue);
}
return lastUpdateTimeList;
}
///
/// 最后更新时间列表ITEM 转换
///
///
///
private LastUpdateTimeKeyValueModel ConverLastUpdateTime(tas.ParamValue tasModel)
{
var model = new LastUpdateTimeKeyValueModel()
{
TimeKey = (LastUpdateTimeType)Convert.ToInt16(tasModel.Key),
TimeValue = tasModel.Value
};
return model;
}
//============================MTP2.0 above==================================================
public override ResponeEntity ToLocalAccountEntity(object obj)
{
return new ResponeEntity();
//var protoObject = obj as ProtobufAccount;
//if (null == protoObject) return null;
//return new TradeAccount()
//{
// //初始化值
//};
}
public override ResponeEntity ToLocalLoginEntity(object obj)
{
var byteArr = obj as byte[];
if (byteArr == null)
{
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
}
var loginRsq = ProtoBufHelper.EntityDeSerialize(byteArr);
var result = new ResponeEntity()
{
RetCode = loginRsq.RetCode,
RetMessage = loginRsq.RetDesc,
Entity = new TradeAccount()
{
AccountStatus = (eAccountStatus)loginRsq.AccountStatus,
AccountType = (eUserType)loginRsq.LoginUserType,
LoginID = loginRsq.LoginID,
MemberAreaId = (uint)loginRsq.MemberUserID,
SystemTime = loginRsq.SystemTime,
Token = loginRsq.Token,
FundsAccountIds = loginRsq.AccountIDs,
CustomerId = loginRsq.UserID,
HasUpdatedPwd = loginRsq.HasUpdatedPwd,
PwdWrongCnt = loginRsq.PwdWrongCnt,
PwdWrongLockCnt = loginRsq.PwdWrongLockCnt,
LoginLockHourNum = loginRsq.LoginLockHourNum,
ClientSystemInfo = loginRsq.ClientSystemInfo,
ClientId = loginRsq.ClientID
}
};
if (loginRsq.Header != null && loginRsq.RetCode == 0)
{
loginRsq.Header.UserID = loginRsq.UserID;
result.Entity.FundsAccountId = loginRsq.Header.AccountID;
ProtoBufHelper.Head = loginRsq.Header; ////保存头内容
}
return result;
}
///
/// To the reqeust login.
///
/// Type of the login.
/// The pass word.
/// The login code.
/// The unique identifier.
/// login IP Address.
/// The system desc.
/// System.Byte[][].
public override byte[] ToReqeustLogin(int loginType, string passWord, ulong loginID, string guid, string loginIP, string systemDesc, string version, byte[] clientSystemInfo, string clientAppID)
{
var loginReq = new LoginReq()
{
LoginPWD = passWord,
ClientType = (int)eClientType.CLIENTTYPE_PC_TRADE_CLIENT,
LoginType = (uint)loginType,
LoginID = loginID,
LoginIp = loginIP,
GUID = guid,
DeviceID = string.Empty,
Version = version,
EnvironmentInfo = systemDesc,
ClientSystemInfo = clientSystemInfo,
ClientAppID = clientAppID,
};
var uuid = Guid.NewGuid();
loginReq.Header = new MessageHead() { UUID = uuid.ToString() };
return ProtoBufHelper.EntitySerialize(loginReq, false);
}
///
/// 交易端登出
///
///
public override byte[] ToReqeustLogOut(ulong loginID)
{
var logOutReq = new LogoutReq() { LoginID = loginID };
return ProtoBufHelper.EntitySerialize(logOutReq);
}
///
/// 商品组信息转换=>市场信息转换
///
/// 商品组信息=>市场信息
/// The exchanges.
/// System.Collections.Generic.List{Muchinfo.TASClient.Data.Model.Market}.
private List ToLocalGoodsGroupsInfo(List goodsGroupInfos)
{
var goodsGroups = new List();
if (goodsGroupInfos == null || goodsGroupInfos.Count <= 0)
{
return goodsGroups;
}
foreach (var item in goodsGroupInfos)
{
var goodsGroup = new Muchinfo.MTPClient.Data.Model.GoodsGroup()
{
MarketTypeID = (int)item.MarketID,
GoodsGroupName = item.MarketName,
TradeMode = (eTradeMode)item.TradeMode,
//GoodsGroupCode = item.GoodsGroupCode,
//GoodsGroupName = item.GoodsGroupName,
//GoodsGroupLevelTypeID = item.GoodsGroupLevelTypeID,
//GoodsGroupid = item.GoodsGroupid,
//MarketTypeID = item.MarketTypeID,
//ReckonMode = (ReckonModeType)item.ReckonMode,
//TradeMode = (eTradeMode)item.TradeMode,
//ExchAreaId = item.ExchAreaId,
//ParentGoodsGroupId = item.ParentGoodsGroupId,
};
goodsGroups.Add(goodsGroup);
}
return goodsGroups;
}
///
/// 资金账户转换
///
///
///
private FundsAccount ToLocalFundsAccounts(TaAccountInfo taAccountInfos)
{
return new FundsAccount();
}
///
/// 交易账号信息转换
///
///
///
private TradeAccount ToLocalTradeAccount(AccountInfo accountInfos)
{
if (null == accountInfos)
{
//todo:异常信息提示
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "查询账号信息异常!");
}
return new TradeAccount()
{
CustomerId = accountInfos.UserID,
MemberAreaId = accountInfos.ParentUserID,
CustomerName = accountInfos.AccountName
};
}
///
/// 商品信息参数配置
///
/// The goods infos.
/// The goods groups.
/// List{LocalEntity.Exchange}.
public List ToLocalGoodsList(List goodsInfos, List goodsGroups)
{
var goodsList = new List();
if (null == goodsInfos || goodsInfos.Count <= 0)
{
return goodsList;
}
foreach (var serviceEntity in goodsInfos)
{
if (serviceEntity == null)
{
continue;
}
var goodsGroup = goodsGroups.FirstOrDefault(z => z.GoodsGroupid == serviceEntity.MarketID);
if (goodsGroup == null) continue;
var entity = new GoodsParameters()
{
AgreeUnit = Convert.ToDecimal(serviceEntity.AgreeUnit),
GoodsCode = serviceEntity.GoodsCode,
GoodsId = serviceEntity.GoodsId,
GoodsName = serviceEntity.GoodsName,
ExchAreaID = goodsGroup.ExchAreaId,
TradeMode = goodsGroup.TradeMode, // 交易模式
////todo:服务未返回,设置调试值
ReckonRate = 1,
};
//DateTime listedtime;
//if (DateTime.TryParse(serviceEntity.ListedTime, out listedtime))
//{
// entity.ListedTime = listedtime;
//}
var quoteGoods = ToQuoteGoods(entity);
goodsList.Add(quoteGoods);
}
return goodsList;
}
private QuoteGoods ToQuoteGoods(GoodsParameters parameter)
{
if (parameter == null) return null;
//todo:商品类别
//var sort = dataModel.Sort.ToString();
var category = QuoteCategoryType.PreciousMetal; //GoodsSortHelper.GetQuoteCategoryBySorts(sort);
return new QuoteGoods(parameter.ExchHqCode, parameter.GoodsCode, parameter.GoodsHqCode, category)
{
ListingStatus = parameter.GoodsStatus.ToString(), // ListStatus.ToString(),
//LotUnit = dataModel.LotSize,
Name = parameter.GoodsName,
GoodsId = (uint)parameter.GoodsId,
// QuoteCurrency = parameter.QuoteCurrency, //PriceCurrency,
// QuoteUnit = parameter.PriceUnit.ToString(),
// Sort = QuoteCategoryType.PreciousMetal.ToString(), //sort,
GoodsParameters = parameter,
TradeMode = parameter.TradeMode,
DecimalPlaces = parameter.HqExchFigures,
//RelevanceCode = dataModel.RelevanceCode,
//SectorCode = dataModel.Sector2,推荐
};
}
///
///
///
/// ToLocalLoginEntity
///
public override ResponeEntity TolocalAccountInfoEntity(object obj)
{
return null;
//var byteArr = obj as byte[];
//if (byteArr == null)
//{
// throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
//}
//var accountRespone = ProtoBufHelper.EntityDeSerialize(byteArr);
//var resultEntity = new ResponeEntity()
//{
// RetCode = accountRespone.RetCode,
// RetMessage = accountRespone.RetDesc,
// Entity = new AccountInfoEntity(),
//};
//if (accountRespone.Rsps == null || !accountRespone.Rsps.Any())
//{
// //todo:查询内容空
// return resultEntity;
//}
//var account = resultEntity.Entity;
//account.GoodsGroups = ToLocalGoodsGroupsInfo(accountRespone.Rsps[0].GoodsGroupInfoRsps); //市场
//account.QuoteGoodses = ToLocalGoodsList(accountRespone.Rsps[0].GoodsInfoRsps, account.GoodsGroups); ////商品信息
// account.FundsAccounts = ToLocalFundsAccounts(accountRespone.Rsps[0].TaAccountInfoRsps); //资金账号 单独查询资金信息
//account.TradeAccount = ToLocalTradeAccount(accountRespone.Rsps[0].AccountInfoRsps); ////交易账号
//if (account.FundsAccounts != null && account.FundsAccounts.Any() && account.TradeAccount!=null) ////设置会员证件
//{
// account.TradeAccount.MemberCardType = account.FundsAccounts[0].CardType;
// account.TradeAccount.MemberCardNum = account.FundsAccounts[0].CardNum;
//}
//return resultEntity;
}
///
/// 账号基本信息查询与交易所市场商品信息
///
/// The account identifier.
/// System.Byte[][].
public override byte[] ToReqeustAccountInfo(ulong accountId)
{
return null;
//var accountGoodsReq = new QueryAccountAndGoodsReq()
//{
// Header = new MessageHead() { },
// AccountId = accountId,
//};
//return ProtoBufHelper.EntitySerialize(accountGoodsReq);
}
///
/// 请求校验Token的Protobuf对象装箱方法
///
///
///
public override byte[] ToTokenCheck(ulong loginID, string token, ulong octTime)
{
var tokenCheckReq = new TokenCheckReq()
{
LoginID = loginID,
Token = token,
SystemTime = octTime
};
return ProtoBufHelper.EntitySerialize(tokenCheckReq);
}
///
/// 从检验Token返回信息中获取Token状态的方法
///
/// 检验Token返回信息
/// Token状态值
public override ResponeEntity GetTokenStatus(object obj)
{
var byteArr = obj as byte[];
if (byteArr == null)
{
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
}
var tokenCheckRsp = ProtoBufHelper.EntityDeSerialize(byteArr);
var resultEntity = new ResponeEntity
{
RetCode = tokenCheckRsp.RetCode,
RetMessage = tokenCheckRsp.RetDesc,
Entity = tokenCheckRsp.SystemTime //服务器时间
};
return resultEntity;
}
///
/// 转换修改密码
///
///
///
public override byte[] ToReqeustModifyPwds(AccountPwds accountPwds)
{
var modifyPwdReq = new ModifyPwdReq()
{
ModifyPwdType = accountPwds.ModifyPwdType,
ModifyPwdID = accountPwds.ModifyPwdID,
NewPwd = accountPwds.NewPwd,
OldPwd = accountPwds.OldPwd
};
return ProtoBufHelper.EntitySerialize(modifyPwdReq);
}
///
/// 解释修改密码返回对象
///
///
///
public override ResponeEntity ResponeModifyPWDEntity(object obj)
{
var byteArr = obj as byte[];
if (byteArr == null)
{
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
}
var modifyPwd = ProtoBufHelper.EntityDeSerialize(byteArr);
var responeEntity = new ResponeEntity()
{
RetCode = modifyPwd.RetCode,
RetMessage = modifyPwd.RetDesc,
};
return responeEntity;
}
public override byte[] ToReqeustFuncMenu(string loginCode)
{
return null;
//var modifyPwdReq = new QueryAccountFuncMenuReq()
//{
// LoginCode = loginCode,
// RoleType = 0, ////客户端类型
//};
//return ProtoBufHelper.EntitySerialize(modifyPwdReq);
}
public override ResponeEntity> ResponeLocalFuncMenu(object data)
{
var byteArr = data as byte[];
if (data == null)
{
throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
}
var menusRespone = ProtoBufHelper.EntityDeSerialize(byteArr);
var resultEntity = new ResponeEntity>()
{
RetCode = menusRespone.RetCode,
RetMessage = menusRespone.RetDesc,
Entity = new List(),
};
if (menusRespone.FuncMenuList == null || !menusRespone.FuncMenuList.Any())
{
//todo:查询内容空
return resultEntity;
}
foreach (var queryAccount in menusRespone.FuncMenuList)
{
var menu = BuildFuncMenu(queryAccount);
resultEntity.Entity.Add(menu);
}
if (resultEntity.Entity != null) ////对子菜单进行排序
{
resultEntity.Entity = resultEntity.Entity.OrderBy((item) => item.SortId).ToList();
}
return resultEntity;
}
///
/// 生成树菜单
///
///
private SysMenuItem BuildFuncMenu(tas.FuncMenu menus)
{
var localMenu = new SysMenuItem(menus.FuncMenuName)
{
FuncMenuCode = menus.FuncMenuCode,
ParentFuncMenuCode = menus.Parentfuncmenucode,
Children = new List(),
};
foreach (var funcMenuList in menus.SonMenus)
{
var childMenu = BuildFuncMenu(funcMenuList);
if (childMenu.Children != null) ////对子菜单进行排序
{
childMenu.Children = childMenu.Children.OrderBy((item) => item.SortId).ToList();
}
localMenu.Children.Add(childMenu);
}
if (localMenu.Children != null) ////对子菜单进行排序
{
localMenu.Children = localMenu.Children.OrderBy((item) => item.SortId).ToList();
}
return localMenu;
}
///
/// 转换请求
///
///
///
public override byte[] ToReqeustTradeFeeRules(uint accountid)
{
//var tradeRulesReq = new QueryAccountAndGoodsReq()
//{
// AccountId = accountid,
//};
//return ProtoBufHelper.EntitySerialize(tradeRulesReq);
return null;
}
public override ResponeEntity> ResoneLocalGoodsFeeRules(object data)
{
return null;
//var byteArr = data as byte[];
//if (data == null)
//{
// throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
//}
//var goodsResult=ProtoBufHelper.EntityDeSerialize(byteArr);
//var resultEntity = new ResponeEntity>()
//{
// RetCode = goodsResult.RetCode,
// RetMessage = goodsResult.RetDesc,
// Entity = new List(),
//};
//if (goodsResult.Rsps == null || !goodsResult.Rsps.Any())
//{
// //todo:查询内容空
// return resultEntity;
//}
//foreach (var rspItem in goodsResult.Rsps)
//{
// var goodsFeeRules = new Dictionary();
// foreach (var goodsRules in rspItem.GoodsRuleAndFee)
// {
// var feeRule = ConverFeeRuleType(goodsRules);
// resultEntity.Entity.Add(feeRule);
// //goodsFeeRules[feeRule.GoodsID].GoodsFees[feeRule.] = goodsFeeType;
// }
//}
//return resultEntity;
}
///
///
///
///
///
private Data.Model.GoodRules.TradeGoodsFeeRule ConverFeeRuleType(tas.GoodsRuleAndFee goodsInce)
{
var feeRule = new Data.Model.GoodRules.TradeGoodsFeeRule();
feeRule.GoodsID = goodsInce.GoodsID;
////商品交易规则
foreach (var goodsFeeType in goodsInce.GoodsRuleList)
{
var rule = new Data.Model.GoodRules.GoodsRuleModel()
{
Ruleid = goodsFeeType.Ruleid,
RuleName = goodsFeeType.RuleName,
ParamValue = goodsFeeType.ParamValue
};
feeRule.GoodsRuleList.Add(rule);
}
return feeRule;
}
public override byte[] ToReqeustRiskChecked(ulong accountid, uint isChecked)
{
return null;
//var riskReq = new RiskCheckNotifyReq()
//{
// AccountId = (uint)accountid,
// IsChecked = isChecked,
//};
//return ProtoBufHelper.EntitySerialize(riskReq);
}
public override ResponeEntity ResponeRiskChecked(object data)
{
return null;
//var byteArr = data as byte[];
//if (byteArr == null)
//{
// throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
//}
//var riskChecked = ProtoBufHelper.EntityDeSerialize(byteArr);
//var responeEntity = new ResponeEntity()
//{
// RetCode = riskChecked.RetCode,
// RetMessage = riskChecked.RetDesc,
// Entity = riskChecked.AccountId,
//};
//return responeEntity;
}
public override byte[] ToReqeustDeliveryGoodsReq(ulong DeliveryGoodsUTime)
{
var baseQueryReq = new DeliveryGoodsQueryReq()
{
Header = new MessageHead() { },
DeliveryGoodsUTime = DeliveryGoodsUTime
};
return ProtoBufHelper.EntitySerialize(baseQueryReq);
}
public override ResponeEntity> ResponeDeliveryGoodsReq(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 List() { }
};
foreach (var item in itemResponeList.DeliveryGoodsList)
{
var good = ToLocalDeliveryGoodsInfo(item);
resultEntity.Entity.Add(good);
}
return resultEntity;
}
private DeliveryGoodsInfoModel ToLocalDeliveryGoodsInfo(DeliveryGoodsInfo goods)
{
var item = new DeliveryGoodsInfoModel()
{
DeliveryGoodsID = goods.DeliveryGoodsID,
DeliveryGoodsCode = goods.DeliveryGoodsCode,
DeliveryGoodsName = goods.DeliveryGoodsName,
AuditFlag = goods.AuditFlag,
GoodsUnit = goods.GoodsUnit,
StandardQty = goods.StandardQty,
StandardQtyRange = goods.StandardQtyRange,
DeliveryGoodsPMList = ToLocalPriceMove(goods.DeliveryGoodsPMList)
};
return item;
}
///
/// 查询外部交易所请求
///
///
public override byte[] ToExternalExchangeReq()
{
var externalExchangeReq = new ExternalExchangeReq()
{
Header = new MessageHead() { },
};
return ProtoBufHelper.EntitySerialize(externalExchangeReq);
}
///
/// 查询外部交易所响应
///
///
///
public override ResponeEntity> ResponseExternalExchange(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 List() { }
};
foreach (var item in itemResponeList.ExternalExchangeList)
{
var externalExchange = BufToMarketsInfo(item);
resultEntity.Entity.Add(externalExchange);
}
return resultEntity;
}
///
/// 外部对象转内部对象
///
///
///
private ExternalExchangeModel BufToMarketsInfo(ExternalExchange tasModel)
{
var localModel = new ExternalExchangeModel()
{
AutoID = tasModel.AutoID,
ExExchangeCode = tasModel.ExExchangeCode,
ExExchangeName = tasModel.ExExchangeName,
IsMarketPrice = tasModel.IsMarketPrice
};
return localModel;
}
///
/// 查询商品组请求
///
///
public override byte[] ToGoodsGroupReq()
{
var externalExchangeReq = new GoodsGroupReq()
{
Header = new MessageHead() { },
};
return ProtoBufHelper.EntitySerialize(externalExchangeReq);
}
///
/// 查询商品组响应
///
///
///
public override ResponeEntity> ResponseGoodsGroup(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 List() { }
};
foreach (var item in itemResponeList.GoodsGroupList)
{
var goodsGroup = new Data.Model.GoodsGroup()
{
GoodsGroupid = item.GoodsGroupID,
GoodsGroupName = item.GoodsGroupName,
MarketTypeID = (int)item.MarketID,
ExChangeId = item.ExExchangeID,
CanShort = item.CanShort
};
resultEntity.Entity.Add(goodsGroup);
}
return resultEntity;
}
}
}