Exemplo n.º 1
0
func TestSession_CheckSendingTime(t *testing.T) {
	session := Session{}
	builder := getBuilder()
	msgBytes, _ := builder.Build()
	msg, _ := parseMessage(msgBytes)

	//missing sending time
	err := session.checkSendingTime(*msg)
	if err == nil {
		t.Error("Expected error")
	}
	if err.RejectReason() != rejectReasonRequiredTagMissing {
		t.Error("Reject reason not expected, got ", err.RejectReason)
	}

	//sending time too late
	sendingTime := time.Now().Add(time.Duration(-200) * time.Second)
	builder.Header().Set(fix.NewUTCTimestampField(tag.SendingTime, sendingTime))
	msgBytes, _ = builder.Build()
	msg, _ = parseMessage(msgBytes)

	err = session.checkSendingTime(*msg)
	if err == nil {
		t.Error("Expected error")
	}
	if err.RejectReason() != rejectReasonSendingTimeAccuracyProblem {
		t.Error("Reject reason not expected, got ", err.RejectReason)
	}

	//future sending time
	sendingTime = time.Now().Add(time.Duration(200) * time.Second)
	builder.Header().Set(fix.NewUTCTimestampField(tag.SendingTime, sendingTime))
	msgBytes, _ = builder.Build()
	msg, _ = parseMessage(msgBytes)

	err = session.checkSendingTime(*msg)
	if err == nil {
		t.Error("Expected error")
	}
	if err.RejectReason() != rejectReasonSendingTimeAccuracyProblem {
		t.Error("Reject reason not expected, got ", err.RejectReason)
	}

	//sending time ok
	sendingTime = time.Now()
	builder.Header().Set(fix.NewUTCTimestampField(tag.SendingTime, sendingTime))
	msgBytes, _ = builder.Build()
	msg, _ = parseMessage(msgBytes)

	err = session.checkSendingTime(*msg)
	if err != nil {
		t.Error("Unexpected error ", err)
	}
}
Exemplo n.º 2
0
func (s *Session) insertSendingTime(header MutableFieldMap) {
	sendingTime := time.Now().UTC()

	if s.sessionID.BeginString >= fix.BeginString_FIX42 {
		header.Set(fix.NewUTCTimestampField(tag.SendingTime, sendingTime))
	} else {
		header.Set(fix.NewUTCTimestampFieldNoMillis(tag.SendingTime, sendingTime))
	}
}
Exemplo n.º 3
0
func (s *ValidationTests) TestValidateFieldNotFound(c *C) {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")

	builder := NewMessageBuilder()
	builder.Header().Set(fix.NewStringField(tag.MsgType, "D"))
	builder.Header().Set(fix.NewStringField(tag.BeginString, "FIX.4.0"))
	builder.Header().Set(fix.NewStringField(tag.BodyLength, "0"))
	builder.Header().Set(fix.NewStringField(tag.SenderCompID, "0"))
	builder.Header().Set(fix.NewStringField(tag.TargetCompID, "0"))
	builder.Header().Set(fix.NewStringField(tag.MsgSeqNum, "0"))
	builder.Header().Set(fix.NewUTCTimestampField(tag.SendingTime, time.Now()))
	builder.Trailer().Set(fix.NewStringField(tag.CheckSum, "000"))

	builder.Body().Set(fix.NewStringField(tag.ClOrdID, "A"))
	builder.Body().Set(fix.NewStringField(tag.HandlInst, "A"))
	builder.Body().Set(fix.NewStringField(tag.Symbol, "A"))
	builder.Body().Set(fix.NewStringField(tag.Side, "A"))
	builder.Body().Set(fix.NewStringField(tag.OrderQty, "A"))

	//ord type is required
	//builder.Body().Set(fix.NewStringField(tag.OrdType, "A"))
	msgBytes, _ := builder.Build()
	msg, _ := parseMessage(msgBytes)

	reject := validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonRequiredTagMissing)
	c.Check(*reject.RefTagID(), Equals, tag.OrdType)

	builder = NewMessageBuilder()
	builder.Trailer().Set(fix.NewStringField(tag.CheckSum, "000"))
	builder.Body().Set(fix.NewStringField(tag.ClOrdID, "A"))
	builder.Body().Set(fix.NewStringField(tag.HandlInst, "A"))
	builder.Body().Set(fix.NewStringField(tag.Symbol, "A"))
	builder.Body().Set(fix.NewStringField(tag.Side, "A"))
	builder.Body().Set(fix.NewStringField(tag.OrderQty, "A"))

	builder.Header().Set(fix.NewStringField(tag.MsgType, "D"))
	builder.Header().Set(fix.NewStringField(tag.BeginString, "FIX.4.0"))
	builder.Header().Set(fix.NewStringField(tag.BodyLength, "0"))
	builder.Header().Set(fix.NewStringField(tag.SenderCompID, "0"))
	builder.Header().Set(fix.NewStringField(tag.TargetCompID, "0"))
	builder.Header().Set(fix.NewStringField(tag.MsgSeqNum, "0"))
	//sending time is required
	//msg.Header.FieldMap.Set(fix.NewStringField(tag.SendingTime, "0"))

	msgBytes, _ = builder.Build()
	msg, _ = parseMessage(msgBytes)

	reject = validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonRequiredTagMissing)
	c.Check(*reject.RefTagID(), Equals, tag.SendingTime)
}
Exemplo n.º 4
0
func (s *ValidationTests) createFIX43NewOrderSingle() MessageBuilder {
	msg := NewMessageBuilder()
	msg.Header().Set(fix.NewStringField(tag.MsgType, "D"))
	msg.Header().Set(fix.NewStringField(tag.BeginString, "FIX.4.3"))
	msg.Header().Set(fix.NewStringField(tag.BodyLength, "0"))
	msg.Header().Set(fix.NewStringField(tag.SenderCompID, "0"))
	msg.Header().Set(fix.NewStringField(tag.TargetCompID, "0"))
	msg.Header().Set(fix.NewStringField(tag.MsgSeqNum, "0"))
	msg.Header().Set(fix.NewUTCTimestampField(tag.SendingTime, time.Now()))

	msg.Body().Set(fix.NewStringField(tag.ClOrdID, "A"))
	msg.Body().Set(fix.NewStringField(tag.HandlInst, "1"))
	msg.Body().Set(fix.NewStringField(tag.Symbol, "A"))
	msg.Body().Set(fix.NewStringField(tag.Side, "1"))
	msg.Body().Set(fix.NewIntField(tag.OrderQty, 5))
	msg.Body().Set(fix.NewStringField(tag.OrdType, "1"))
	msg.Body().Set(fix.NewUTCTimestampField(tag.TransactTime, time.Now()))

	msg.Trailer().Set(fix.NewStringField(tag.CheckSum, "000"))

	return msg
}