根据交易所接口文档 对重复组取值赋值,返回成交回报

来源:互联网 发布:实对称矩阵必可对角化 编辑:程序博客网 时间:2024/05/08 03:06

如上海交易所的综合业务中,股票期权组合拆分业务,柜台发到交易所的委托oiw..reqresp表中reqtext字段值为

9=19635=D11=0300000001522=148=CNSJC54=B38=1198= 555=2602=10000071624=L203= 685=1602=10000072624=S203= 685=1453=4448=A431800010452=5448=888452=500448=20403452=1448=0000 452=4001

按照市场参与者接口规格说明书,对这类委托的处理交易所需要返回成交回报也要有‘555字段值’个重复组,重复组内容为

602LegSecurityID合约编码、624LegSide合约方向、203CoveredOrUncovered备兑标签、685LegOrderQty申报数量;


先说结果,返回到oiw..execreport成交表的execreporttext字段内容为

9=27335=811=030000001048=CNSJC   17=20403154=B32=1198=2016110200000001555=2602=10000071624=L203=685=1602=10000072624=S203=685=18541=20160518-16:38:27.00042=20160518-16:38:27.000522=1453=4448=A431800010452=5448=888452=500448=20403452=1448=0000452=4001


这其中对重复组的判断和赋值处理如下:

function GetGroupLegesValue2(Hash: THashedStringList):string;                   //902var  i:Integer;  // bufferList下标  j,n : Integer; //重复组内组数  ipos : Integer;  tmp:string;begin  Result := '';  tmp := Hash.Values['555'];     //2  if tmp='' then     Exit;  n := StrToInt(tmp);  if n = 0 then Exit;  Result := '555='+ IntToStr(n) + SOH;  i := Hash.IndexOfName('555');  for j := 1 to n*4 do  begin    tmp := Hash.Strings[i + j];    if Pos(LeftStr(tmp,4),'602=624=203=685=') > 0 then               Result := Result + tmp + SOH;  end;end;

成交回报写到回报表oiw..execreport的方法如下:

function PostCJHB_OML(wt : PTReqResp;cjsl : Integer):Boolean; //期权组合、分拆、转备兑var  FPTExecReport : PTExecReport;  FPTExecReportText : PTExecReportText;  sql, sExecReportText: string;  i : Integer;  tmp : string;begin  if not Simulator.cjconn.Connected then  begin       Simulator.cjconn.ConnectionString := gconfig.DestConnnectString;       Simulator.cjconn.Open;  end;  New(FPTExecReport);  New(FPTExecReportText);  Inc(wt.FEntrustXW.d_maxCJBH);  FPTExecReport.ExecNum := wt.FEntrustXW.d_maxCJBH;  FPTExecReport.BcastType := '7M';  FPTExecReport.SetID := '300';  FPTExecReport.SeqNum := FPTExecReport.ExecNum;  FPTExecReport.RecordTimeStamp := LeftStr(wt.recordtimestamp,8) +'-'+TimeToStr(Time())+ '.000';  //拼接FPTResptext  FPTExecReportText.clordid := wt.reff;  FPTExecReportText.securityid := wt.securityid;  FPTExecReportText.execid := wt.FPTReqtext.reportseat + IntToStr(FPTExecReport.ExecNum);  FPTExecReportText.side := wt.FPTReqtext.side;  FPTExecReportText.lastqty := IntToStr(cjsl);  //FPTExecReportText.orderid := wt.FPTResptext.orderid;  没有orderid字段,但有SecondaryOrderID字段  if wt.FPTReqtext.SecondaryOrderID = '' then      //组合指令时为空  begin      tmp := IntToStr(wt.localrespnum);      tmp := rightstr('0000000' + tmp, 8); //前补0凑8位      FPTExecReportText.SecondaryOrderID := FormatDateTime('yyyymmdd', now)+ tmp;  end  else  begin     FPTExecReportText.SecondaryOrderID := wt.FPTReqtext.SecondaryOrderID;// 拆分指令时为组合编号  end;        FPTExecReportText.GroupLeges := wt.FPTReqtext.GroupLeges;  FPTExecReportText.transacttime := FPTExecReport.RecordTimeStamp;   FPTExecReportText.origtime := wt.FPTResptext.transacttime;  FPTExecReportText.OwnerType :=   wt.FPTReqtext.OwnerType;  FPTExecReportText.stockholder := wt.FPTReqtext.stockholder;    FPTExecReportText.reportseat := wt.FPTReqtext.reportseat;  FPTExecReportText.branchCode := wt.FPTReqtext.branchCode;  MakeCJText_OML(FPTExecReportText,sExecReportText);  FPTExecReport.ExecReportText := sExecReportText;      sql := 'insert into  ' + wt.FEntrustXW.vc_HBLJ + ' (execnum,bcasttype,setid,seqnum,recordtimestamp,execreporttext) ';  sql := sql + 'select ' + IntToStr(FPTExecReport.ExecNum) +                  ', ' + QuotedStr(FPTExecReport.BcastType) +                  ', ' + QuotedStr(FPTExecReport.SetID) +                  ', ' + IntToStr(FPTExecReport.SeqNum) +                  ', ' + QuotedStr(FPTExecReport.RecordTimeStamp) +                  ', ' + QuotedStr(FPTExecReport.ExecReportText);  Simulator.WTQuery.InsertCommitSQL(sql);  //ExecQuery2(Simulator.cjconn,sql);  StatInfo.IncStat(wt.pbu, 'cj', 1);  Simulator.AddLog(2,wt.pbu + ':' + wt.reff +'成交'+inttostr(cjsl)); //加日志  result := true;end;

其中报文打包函数MakeCJText_OML(FPTExecReportText,sExecReportText)为:

function MakeCJText_OML(ExecReportText:PTExecReportText;var sExecReportText:string):Boolean;var  fixPkg : TFixPackage;begin  fixPkg := TFixPackage.Create();  fixPkg.BeginPkg;  fixPkg.MsgType := '8';  fixPkg.ClOrdID :=  ExecReportText.clordid;  fixPkg.SecurityID :=  ExecReportText.SecurityID;  fixPkg.ExecID :=  ExecReportText.ExecID;  fixPkg.Side :=  ExecReportText.Side;   //B,C,D  fixPkg.LastQty :=  ExecReportText.LastQty;  fixPkg.SecondaryOrderID :=  ExecReportText.SecondaryOrderID; //这个字段在调用前要特别处理 pitodo  fixPkg.setGroupLegesValue(ExecReportText.GroupLeges);  //合约重复组   602LegSecurityID合约编码C8  //624LegSide合约方向,L为权利仓,S为义务仓C1  //685LegOrderQty申报数量(张)N10  fixPkg.AddValue(Const_TransactTimeOnly,ExecReportText.transacttime,TC,21);  fixPkg.OrigTime := ExecReportText.origtime;  fixPkg.OwnerType :=  ExecReportText.OwnerType;  fixPkg.NoPartyIDs := 4;  fixPkg.stockholderid:= ExecReportText.stockholder;  fixPkg.stockholderidSubCode := '888';  fixPkg.SetReportSeat(ExecReportText.reportseat);  fixPkg.SetBranchCode(ExecReportText.branchCode);      fixPkg.EndPkg;  sExecReportText := fixPkg.Buffer;  fixPkg.Free;      Result := True;end;


0 0