fix协议介绍8-Reject消息

本文介绍 FIX 协议中 Reject 消息的格式及处理方法。当接收到违反会话级规则的消息时,发送方将发出 Reject 消息。文章详细解释了各个字段的作用,并提供了一个 Java 实现示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

FIX.5.0SP2 Message

Reject [type '3']

The reject message should be issued when a message is received but cannot be properly processed due to a session-level rule violation. An example of when a reject may be appropriate would be the receipt of a message with invalid basic data which successfully passes de-encryption, CheckSum and BodyLength checks.


Added  FIX.2.7

Expand Components | Collapse Components

  Field or Component Field Name FIXML name Req'd Comments Depr.
Component StandardHeader BaseHeader

MsgType = 3

 
45 RefSeqNum @RefSeqNum

MsgSeqNum of rejected message

 
371 RefTagID @RefTagID  

The tag number of the FIX field being referenced.

 
372 RefMsgType @RefMsgTyp  

The MsgType of the FIX message being referenced.

 
1130 RefApplVerID @RefApplVerID  

Recommended when rejecting an application message that does not explicitly provide ApplVerID ( 1128) on the message being rejected. In this case the value from the DefaultApplVerID(1137) or the default value specified in the NoMsgTypes repeating group on the logon message should be provided.

 
1406 RefApplExtID @RefApplExtID  

Recommended when rejecting an application message that does not explicitly provide ApplExtID(1156) on the rejected message. In this case the value from the DefaultApplExtID(1407) or the default value specified in the NoMsgTypes repeating group on the logon message should be provided.

 
1131 RefCstmApplVerID @RefCstmApplVerID  

Recommended when rejecting an application message that does not explicitly provide CstmApplVerID(1129) on the message being rejected. In this case the value from the DefaultCstmApplVerID(1408) or the default value specified in the NoMsgTypes repeating group on the logon message should be provided.

 
373 SessionRejectReason    

Code to identify reason for a session-level Reject message.

 
58 Text @Txt  

Where possible, message to explain reason for rejection

 
354 EncodedTextLen @EncTxtLen  

Must be set if EncodedText field is specified and must immediately precede it.

 
355 EncodedText @EncTxt  

Encoded (non-ASCII characters) representation of the Text field in the encoded format specified via the MessageEncoding field.

 
Component StandardTrailer      


消息实现:

package cs.mina.codec.msg;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import cs.mina.exception.InValidDataException;

/*
 *@author(huangxiaoping)
 *@date 2013-11-25
 */
public class RejectMsg extends BaseMsg {
	private Tag refSeqNum=new Tag("45","SeqNum",true);
	private Tag refTagID=new Tag("371","int",false);
	private Tag refMsgType=new Tag("372","String",false);
	private Tag sessionRejectReason=new Tag("373","int",false);
	private Tag text=new Tag("58","String",false);
	private Tag encodedTextLen=new Tag("354","Length",false);
	private Tag encodedText=new Tag("355","data",false);
	private Set<String> tagIdsSet=new HashSet<String>();
	public RejectMsg(){
		this.getHeadEntity().getMsgType().setTagValue("3");
		tagIdsSet.add("45");
		tagIdsSet.add("371");
		tagIdsSet.add("372");
		tagIdsSet.add("373");
		tagIdsSet.add("58");
		tagIdsSet.add("354");
		tagIdsSet.add("355");
		this.getBodyEntity().getBodyTagList().add(refSeqNum);
		this.getBodyEntity().getBodyTagList().add(refTagID);
		this.getBodyEntity().getBodyTagList().add(refMsgType);
		this.getBodyEntity().getBodyTagList().add(sessionRejectReason);
		this.getBodyEntity().getBodyTagList().add(text);
		this.getBodyEntity().getBodyTagList().add(encodedTextLen);
		this.getBodyEntity().getBodyTagList().add(encodedText);
	}
	@Override
	public void decodeBody() {
		Set<String> already=new HashSet<String>();
		String[] bodyItems=this.body.split(BaseMsg.SOH);
		for(int i=0;i<bodyItems.length;i++){
			String[]tagItems=bodyItems[i].split("=");
			if(tagItems.length!=2){
				throw new InValidDataException("消息格式错误");
			}
			String tagId=tagItems[0];
			if(already.contains(tagId)){
				throw new InValidDataException("消息格式错误");
			}
			already.add(tagId);
			if(this.tagIdsSet.contains(tagId)){
				List<Tag> tagList=this.bodyEntity.getBodyTagList();
				for(int j=0;j<tagList.size();j++){
					Tag tag=tagList.get(j);
					if(tag.getTagId().equals(tagId)){
						tag.setTagValue(tagItems[1]);
						break;
					}
				}
			}else{
				throw new InValidDataException("消息格式错误");
			}
		}

	}

	@Override
	public void validate() {
		if(refMsgType.getTagValue()!=null){
			if(MsgUtil.msgTypeMap.get(refMsgType.getTagValue())==null){
				throw new InValidDataException("refMsgType错误");
			}
		}
		if(sessionRejectReason.getTagValue()!=null){
			if(!MsgUtil.sessionRejectReason.contains(sessionRejectReason.getTagValue())){
				throw new InValidDataException("sessionRejectReason错误");
			}
		}
		if(encodedText.getTagValue()!=null){
			encodedTextLen.setMust(true);
		}
		this.headEntity.validate();
		List<Tag> bodyTagList=this.bodyEntity.getBodyTagList();
		for(int i=0;i<bodyTagList.size();i++){
			bodyTagList.get(i).validate();
		}
		this.tailerEntity.validate();

	}

	public Tag getRefSeqNum() {
		return refSeqNum;
	}

	public void setRefSeqNum(Tag refSeqNum) {
		this.refSeqNum = refSeqNum;
	}

	public Tag getRefTagID() {
		return refTagID;
	}

	public void setRefTagID(Tag refTagID) {
		this.refTagID = refTagID;
	}

	public Tag getRefMsgType() {
		return refMsgType;
	}

	public void setRefMsgType(Tag refMsgType) {
		this.refMsgType = refMsgType;
	}

	public Tag getSessionRejectReason() {
		return sessionRejectReason;
	}

	public void setSessionRejectReason(Tag sessionRejectReason) {
		this.sessionRejectReason = sessionRejectReason;
	}

	public Tag getText() {
		return text;
	}

	public void setText(Tag text) {
		this.text = text;
	}

	public Tag getEncodedTextLen() {
		return encodedTextLen;
	}

	public void setEncodedTextLen(Tag encodedTextLen) {
		this.encodedTextLen = encodedTextLen;
	}

	public Tag getEncodedText() {
		return encodedText;
	}

	public void setEncodedText(Tag encodedText) {
		this.encodedText = encodedText;
	}

}

消息处理:略


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hxpjava1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值