示例#1
0
func tcFieldNotFoundBody() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}
	invalidMsg1 := NewMessage()
	invalidMsg1.Header.SetField(tagMsgType, FIXString("D")).
		SetField(tagBeginString, FIXString("FIX.4.0")).
		SetField(tagBodyLength, FIXString("0")).
		SetField(tagSenderCompID, FIXString("0")).
		SetField(tagTargetCompID, FIXString("0")).
		SetField(tagMsgSeqNum, FIXString("0")).
		SetField(tagSendingTime, FIXUTCTimestamp{Time: time.Now()})
	invalidMsg1.Trailer.SetField(tagCheckSum, FIXString("000"))

	invalidMsg1.Body.SetField(Tag(11), FIXString("A")).
		SetField(Tag(21), FIXString("A")).
		SetField(Tag(55), FIXString("A")).
		SetField(Tag(54), FIXString("A")).
		SetField(Tag(38), FIXString("A"))

	tag := Tag(40)
	//ord type is required
	//invalidMsg1.Body.SetField(Tag(40), "A"))

	msgBytes := invalidMsg1.build()

	return validateTest{
		TestName:             "FieldNotFoundBody",
		Validator:            validator,
		MessageBytes:         msgBytes,
		ExpectedRejectReason: rejectReasonRequiredTagMissing,
		ExpectedRefTagID:     &tag,
	}
}
示例#2
0
func tcFieldNotFoundHeader() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}

	invalidMsg2 := NewMessage()
	invalidMsg2.Trailer.SetField(tagCheckSum, FIXString("000"))
	invalidMsg2.Body.SetField(Tag(11), FIXString("A")).
		SetField(Tag(21), FIXString("A")).
		SetField(Tag(55), FIXString("A")).
		SetField(Tag(54), FIXString("A")).
		SetField(Tag(38), FIXString("A"))

	invalidMsg2.Header.SetField(tagMsgType, FIXString("D")).
		SetField(tagBeginString, FIXString("FIX.4.0")).
		SetField(tagBodyLength, FIXString("0")).
		SetField(tagSenderCompID, FIXString("0")).
		SetField(tagTargetCompID, FIXString("0")).
		SetField(tagMsgSeqNum, FIXString("0"))
	//sending time is required
	//invalidMsg2.Header.FieldMap.SetField(tag.SendingTime, "0"))

	tag := tagSendingTime
	msgBytes, _ := invalidMsg2.Build()

	return validateTest{
		TestName:             "FieldNotFoundHeader",
		Validator:            validator,
		MessageBytes:         msgBytes,
		ExpectedRejectReason: rejectReasonRequiredTagMissing,
		ExpectedRefTagID:     &tag,
	}
}
func (s *ValidationTests) TestValidateInvalidTagNumber(c *C) {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")

	builder := s.createFIX40NewOrderSingle()
	builder.Header().Set(fix.NewStringField(9999, "hello"))
	msgBytes, _ := builder.Build()
	msg, _ := parseMessage(msgBytes)
	reject := validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonInvalidTagNumber)
	c.Check(*reject.RefTagID(), Equals, fix.Tag(9999))

	builder = s.createFIX40NewOrderSingle()
	builder.Trailer().Set(fix.NewStringField(9999, "hello"))
	msgBytes, _ = builder.Build()
	msg, _ = parseMessage(msgBytes)

	reject = validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonInvalidTagNumber)
	c.Check(*reject.RefTagID(), Equals, fix.Tag(9999))

	builder = s.createFIX40NewOrderSingle()
	builder.Body().Set(fix.NewStringField(9999, "hello"))
	msgBytes, _ = builder.Build()
	msg, _ = parseMessage(msgBytes)

	reject = validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonInvalidTagNumber)
	c.Check(*reject.RefTagID(), Equals, fix.Tag(9999))
}
func (s *ValidationTests) TestFloatValidation(c *C) {
	msg, err := parseMessage([]byte("8=FIX.4.29=10635=D34=249=TW52=20140329-22:38:4556=ISLD11=ID21=140=154=138=+200.0055=INTC60=20140329-22:38:4510=178"))
	c.Check(err, IsNil)

	dict, _ := datadictionary.Parse("spec/FIX42.xml")
	reject := validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonIncorrectDataFormatForValue)
}
func (s *ValidationTests) TestValidateTagNotDefinedForMessageComponent(c *C) {
	dict, err := datadictionary.Parse("spec/FIX43.xml")
	c.Check(err, IsNil)
	builder := s.createFIX43NewOrderSingle()
	msgBytes, _ := builder.Build()
	msg, _ := parseMessage(msgBytes)

	reject := validate(dict, *msg)
	c.Check(reject, IsNil)
}
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)
}
func (s *ValidationTests) TestValidateTagAppearsMoreThanOnce(c *C) {

	msg, err := parseMessage([]byte("8=FIX.4.09=10735=D34=249=TW52=20060102-15:04:0556=ISLD11=ID21=140=140=254=138=20055=INTC60=20060102-15:04:0510=234"))
	c.Check(err, IsNil)

	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	reject := validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonTagAppearsMoreThanOnce)
	c.Check(*reject.RefTagID(), Equals, tag.OrdType)
}
func (s *ValidationTests) TestValidateValueIsIncorrect(c *C) {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	builder := s.createFIX40NewOrderSingle()
	builder.Body().Set(fix.NewStringField(tag.HandlInst, "4"))
	msgBytes, _ := builder.Build()
	msg, _ := parseMessage(msgBytes)

	reject := validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonValueIsIncorrect)
	c.Check(*reject.RefTagID(), Equals, tag.HandlInst)
}
func (s *ValidationTests) TestValidateInvalidMsgType(c *C) {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")

	builder := s.createFIX40NewOrderSingle()
	builder.Header().Set(fix.NewStringField(tag.MsgType, "z"))
	msgBytes, _ := builder.Build()
	msg, _ := parseMessage(msgBytes)

	reject := validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonInvalidMsgType)
}
示例#10
0
func (s *ValidationTests) TestValidateTagSpecifiedWithoutAValue(c *C) {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	builder := s.createFIX40NewOrderSingle()
	builder.Body().Set(fix.NewStringField(tag.ClientID, ""))
	msgBytes, _ := builder.Build()
	msg, _ := parseMessage(msgBytes)

	reject := validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonTagSpecifiedWithoutAValue)
	c.Check(*reject.RefTagID(), Equals, tag.ClientID)
}
示例#11
0
func (s *ValidationTests) TestValidateIncorrectDataFormatForValue(c *C) {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	builder := s.createFIX40NewOrderSingle()
	builder.Body().Set(fix.NewStringField(tag.OrderQty, "+200.00"))
	msgBytes, _ := builder.Build()
	msg, _ := parseMessage(msgBytes)

	reject := validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonIncorrectDataFormatForValue)
	c.Check(*reject.RefTagID(), Equals, tag.OrderQty)
}
示例#12
0
func tcFloatValidation() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX42.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}
	tag := Tag(38)
	return validateTest{
		TestName:  "FloatValidation",
		Validator: validator,
		MessageBytes: []byte("8=FIX.4.29=10635=D34=249=TW52=20140329-22:38:4556=ISLD11=ID21=140=154=138=+200.0055=INTC60=20140329-22:38:4510=178"),
		ExpectedRejectReason: rejectReasonIncorrectDataFormatForValue,
		ExpectedRefTagID:     &tag,
	}
}
示例#13
0
func (s *ValidationTests) TestValidateTagNotDefinedForMessage(c *C) {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")

	builder := s.createFIX40NewOrderSingle()
	builder.Body().Set(fix.NewStringField(41, "hello"))
	msgBytes, _ := builder.Build()
	msg, _ := parseMessage(msgBytes)

	reject := validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonTagNotDefinedForThisMessageType)
	c.Check(*reject.RefTagID(), Equals, fix.Tag(41))
}
示例#14
0
func tcTagAppearsMoreThanOnce() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}
	tag := Tag(40)

	return validateTest{
		TestName:  "Tag appears more than once",
		Validator: validator,
		MessageBytes: []byte("8=FIX.4.09=10735=D34=249=TW52=20060102-15:04:0556=ISLD11=ID21=140=140=254=138=20055=INTC60=20060102-15:04:0510=234"),
		ExpectedRejectReason: rejectReasonTagAppearsMoreThanOnce,
		ExpectedRefTagID:     &tag,
	}
}
示例#15
0
func (s *ValidationTests) TestValidateTagSpecifiedOutOfRequiredOrder(c *C) {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	builder := s.createFIX40NewOrderSingle()
	//should be in header
	builder.Body().Set(fix.NewStringField(tag.OnBehalfOfCompID, "CWB"))
	msgBytes, _ := builder.Build()
	msg, _ := parseMessage(msgBytes)

	reject := validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonTagSpecifiedOutOfRequiredOrder)
	c.Check(*reject.RefTagID(), Equals, tag.OnBehalfOfCompID)
}
示例#16
0
func tcInvalidMsgType() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}
	builder := createFIX40NewOrderSingle()
	builder.Header.SetField(tagMsgType, FIXString("z"))
	msgBytes, _ := builder.Build()

	return validateTest{
		TestName:             "Invalid MsgType",
		Validator:            validator,
		MessageBytes:         msgBytes,
		ExpectedRejectReason: rejectReasonInvalidMsgType,
	}
}
示例#17
0
func tcTagIsDefinedForMessage() validateTest {
	//compare to tcTagIsNotDefinedForMessage
	dict, _ := datadictionary.Parse("spec/FIX43.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}
	validMsg := createFIX43NewOrderSingle()
	msgBytes, _ := validMsg.Build()

	return validateTest{
		TestName:          "TagIsDefinedForMessage",
		Validator:         validator,
		MessageBytes:      msgBytes,
		DoNotExpectReject: true,
	}
}
示例#18
0
func tcIncorrectDataFormatForValue() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}
	builder := createFIX40NewOrderSingle()
	tag := Tag(38)
	builder.Body.SetField(tag, FIXString("+200.00"))
	msgBytes, _ := builder.Build()

	return validateTest{
		TestName:             "IncorrectDataFormatForValue",
		Validator:            validator,
		MessageBytes:         msgBytes,
		ExpectedRejectReason: rejectReasonIncorrectDataFormatForValue,
		ExpectedRefTagID:     &tag,
	}
}
示例#19
0
func tcTagNotDefinedForMessage() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}
	invalidMsg := createFIX40NewOrderSingle()
	tag := Tag(41)
	invalidMsg.Body.SetField(tag, FIXString("hello"))
	msgBytes, _ := invalidMsg.Build()

	return validateTest{
		TestName:             "Tag Not Defined For Message",
		Validator:            validator,
		MessageBytes:         msgBytes,
		ExpectedRejectReason: rejectReasonTagNotDefinedForThisMessageType,
		ExpectedRefTagID:     &tag,
	}
}
示例#20
0
func tcInvalidTagNumberTrailer() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}
	invalidTrailerFieldMessage := createFIX40NewOrderSingle()
	tag := Tag(9999)
	invalidTrailerFieldMessage.Trailer.SetField(tag, FIXString("hello"))
	msgBytes, _ := invalidTrailerFieldMessage.Build()

	return validateTest{
		TestName:             "Invalid Tag Number Trailer",
		Validator:            validator,
		MessageBytes:         msgBytes,
		ExpectedRejectReason: rejectReasonInvalidTagNumber,
		ExpectedRefTagID:     &tag,
	}
}
示例#21
0
func tcTagSpecifiedWithoutAValue() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}
	builder := createFIX40NewOrderSingle()

	bogusTag := Tag(109)
	builder.Body.SetField(bogusTag, FIXString(""))
	msgBytes, _ := builder.Build()

	return validateTest{
		TestName:             "Tag SpecifiedWithoutAValue",
		Validator:            validator,
		MessageBytes:         msgBytes,
		ExpectedRejectReason: rejectReasonTagSpecifiedWithoutAValue,
		ExpectedRefTagID:     &bogusTag,
	}
}
示例#22
0
func tcValueIsIncorrect() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}

	tag := Tag(21)
	builder := createFIX40NewOrderSingle()
	builder.Body.SetField(tag, FIXString("4"))
	msgBytes, _ := builder.Build()

	return validateTest{
		TestName:             "ValueIsIncorrect",
		Validator:            validator,
		MessageBytes:         msgBytes,
		ExpectedRejectReason: rejectReasonValueIsIncorrect,
		ExpectedRefTagID:     &tag,
	}
}
示例#23
0
func tcTagSpecifiedOutOfRequiredOrderHeader() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}

	builder := createFIX40NewOrderSingle()
	tag := tagOnBehalfOfCompID
	//should be in header
	builder.Body.SetField(tag, FIXString("CWB"))
	msgBytes, _ := builder.Build()

	return validateTest{
		TestName:             "Tag specified out of required order in Header",
		Validator:            validator,
		MessageBytes:         msgBytes,
		ExpectedRejectReason: rejectReasonTagSpecifiedOutOfRequiredOrder,
		ExpectedRefTagID:     &tag,
	}
}
示例#24
0
func tcTagSpecifiedOutOfRequiredOrderDisabledTrailer() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}
	validator.settings.CheckFieldsOutOfOrder = false

	builder := createFIX40NewOrderSingle()
	tag := tagSignature
	//should be in trailer
	builder.Body.SetField(tag, FIXString("SIG"))
	msgBytes, _ := builder.Build()

	return validateTest{
		TestName:          "Tag specified out of required order in Trailer - Disabled",
		Validator:         validator,
		MessageBytes:      msgBytes,
		DoNotExpectReject: true,
	}
}
示例#25
0
func tcTagSpecifiedOutOfRequiredOrderTrailer() validateTest {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")
	validator := &fixValidator{dict, defaultValidatorSettings}

	builder := createFIX40NewOrderSingle()
	tag := tagSignature
	//should be in trailer
	builder.Body.SetField(tag, FIXString("SIG"))
	msgBytes := builder.build()

	refTag := Tag(100)
	return validateTest{
		TestName:             "Tag specified out of required order in Trailer",
		Validator:            validator,
		MessageBytes:         msgBytes,
		ExpectedRejectReason: rejectReasonTagSpecifiedOutOfRequiredOrder,
		ExpectedRefTagID:     &refTag,
	}
}
示例#26
0
文件: main.go 项目: jfyuen/quickfix
func main() {
	flag.Usage = usage
	flag.Parse()

	if flag.NArg() != 1 {
		usage()
	}

	dataDict := flag.Arg(0)

	if spec, err := datadictionary.Parse(dataDict); err != nil {
		panic(err)
	} else {
		fixSpec = spec
	}

	sortedMsgTypes = make([]string, len(fixSpec.Messages))
	i := 0
	for f := range fixSpec.Messages {
		sortedMsgTypes[i] = f
		i++
	}
	sort.Strings(sortedMsgTypes)

	initPackage()

	if fi, err := os.Stat(pkg); os.IsNotExist(err) {
		if err := os.Mkdir(pkg, os.ModePerm); err != nil {
			panic(err)
		}
	} else if !fi.IsDir() {
		panic(pkg + "/ is not a directory")
	}

	genMessages()
}
示例#27
0
func main() {
	flag.Usage = usage
	flag.Parse()

	if flag.NArg() < 1 {
		usage()
	}

	specs := make([]*datadictionary.DataDictionary, flag.NArg())
	for i, dataDictPath := range flag.Args() {
		var err error
		specs[i], err = datadictionary.Parse(dataDictPath)
		if err != nil {
			log.Fatalf("Error Parsing %v: %v", dataDictPath, err)
		}
	}

	internal.BuildGlobalFieldTypes(specs)

	waitGroup.Add(1)
	go genTags()
	waitGroup.Add(1)
	go genFields()
	waitGroup.Add(1)
	go genEnums()

	for _, spec := range specs {
		pkg := getPackageName(spec)

		if fi, err := os.Stat(pkg); os.IsNotExist(err) {
			if err := os.Mkdir(pkg, os.ModePerm); err != nil {
				log.Fatal(err)
			}
		} else if !fi.IsDir() {
			log.Fatalf("%v/ is not a directory", pkg)
		}

		switch pkg {
		//uses fixt11 header/trailer
		case "fix50", "fix50sp1", "fix50sp2":
		default:
			waitGroup.Add(1)
			go genHeader(pkg, spec)

			waitGroup.Add(1)
			go genTrailer(pkg, spec)
		}

		for _, m := range spec.Messages {
			waitGroup.Add(1)
			go genMessage(pkg, spec, m)
		}
	}

	go func() {
		waitGroup.Wait()
		close(errors)
	}()

	var h internal.ErrorHandler
	for err := range errors {
		h.Handle(err)
	}

	os.Exit(h.ReturnCode)
}
示例#28
0
//Creates Session, associates with internal session registry
func createSession(sessionID SessionID, storeFactory MessageStoreFactory, settings *SessionSettings, logFactory LogFactory, application Application) error {
	session := &Session{sessionID: sessionID}

	if sessionID.BeginString == fix.BeginString_FIXT11 {
		defaultApplVerID, err := settings.Setting(config.DefaultApplVerID)
		if err != nil {
			return requiredConfigurationMissing(config.DefaultApplVerID)
		}
		session.defaultApplVerID = defaultApplVerID
	}

	if dataDictionaryPath, err := settings.Setting(config.DataDictionary); err == nil {
		if session.dataDictionary, err = datadictionary.Parse(dataDictionaryPath); err != nil {
			return err
		}
	}

	if transportDataDictionaryPath, err := settings.Setting(config.TransportDataDictionary); err == nil {
		if session.transportDataDictionary, err = datadictionary.Parse(transportDataDictionaryPath); err != nil {
			return err
		}
	}

	//FIXME: tDictionary w/o appDictionary and vice versa should throw config error
	if appDataDictionaryPath, err := settings.Setting(config.AppDataDictionary); err == nil {
		if session.appDataDictionary, err = datadictionary.Parse(appDataDictionaryPath); err != nil {
			return err
		}
	}

	var err error
	if settings.HasSetting(config.ResetOnLogon) {
		if session.resetOnLogon, err = settings.BoolSetting(config.ResetOnLogon); err != nil {
			return err
		}
	}

	if settings.HasSetting(config.HeartBtInt) {
		if session.heartBtInt, err = settings.IntSetting(config.HeartBtInt); err != nil {
			return err
		}
	}

	if session.log, err = logFactory.CreateSessionLog(session.sessionID); err != nil {
		return err
	}

	if session.store, err = storeFactory.Create(session.sessionID); err != nil {
		return err
	}

	session.toSend = make(chan MessageBuilder)
	session.sessionEvent = make(chan event)
	session.application = application
	session.stateTimer = eventTimer{Task: func() { session.sessionEvent <- needHeartbeat }}
	session.peerTimer = eventTimer{Task: func() { session.sessionEvent <- peerTimeout }}

	application.OnCreate(session.sessionID)
	sessions.newSession <- session

	return nil
}
示例#29
0
func (f sessionFactory) newSession(
	sessionID SessionID, storeFactory MessageStoreFactory, settings *SessionSettings, logFactory LogFactory,
	application Application) (s *session, err error) {
	s = &session{sessionID: sessionID}

	var validatorSettings = defaultValidatorSettings
	if settings.HasSetting(config.ValidateFieldsOutOfOrder) {
		if validatorSettings.CheckFieldsOutOfOrder, err = settings.BoolSetting(config.ValidateFieldsOutOfOrder); err != nil {
			return
		}
	}

	if sessionID.IsFIXT() {
		if s.DefaultApplVerID, err = settings.Setting(config.DefaultApplVerID); err != nil {
			return
		}

		if applVerID, ok := applVerIDLookup[s.DefaultApplVerID]; ok {
			s.DefaultApplVerID = applVerID
		}

		//If the transport or app data dictionary setting is set, the other also needs to be set.
		if settings.HasSetting(config.TransportDataDictionary) || settings.HasSetting(config.AppDataDictionary) {
			var transportDataDictionaryPath, appDataDictionaryPath string
			if transportDataDictionaryPath, err = settings.Setting(config.TransportDataDictionary); err != nil {
				return
			}

			if appDataDictionaryPath, err = settings.Setting(config.AppDataDictionary); err != nil {
				return
			}

			var transportDataDictionary, appDataDictionary *datadictionary.DataDictionary
			if transportDataDictionary, err = datadictionary.Parse(transportDataDictionaryPath); err != nil {
				return
			}

			if appDataDictionary, err = datadictionary.Parse(appDataDictionaryPath); err != nil {
				return
			}

			s.validator = &fixtValidator{transportDataDictionary, appDataDictionary, validatorSettings}
		}
	} else if settings.HasSetting(config.DataDictionary) {
		var dataDictionaryPath string
		if dataDictionaryPath, err = settings.Setting(config.DataDictionary); err != nil {
			return
		}

		var dataDictionary *datadictionary.DataDictionary
		if dataDictionary, err = datadictionary.Parse(dataDictionaryPath); err != nil {
			return
		}

		s.validator = &fixValidator{dataDictionary, validatorSettings}
	}

	if settings.HasSetting(config.ResetOnLogon) {
		if s.ResetOnLogon, err = settings.BoolSetting(config.ResetOnLogon); err != nil {
			return
		}
	}

	if settings.HasSetting(config.RefreshOnLogon) {
		if s.RefreshOnLogon, err = settings.BoolSetting(config.RefreshOnLogon); err != nil {
			return
		}
	}

	if settings.HasSetting(config.ResetOnLogout) {
		if s.ResetOnLogout, err = settings.BoolSetting(config.ResetOnLogout); err != nil {
			return
		}
	}

	if settings.HasSetting(config.EnableLastMsgSeqNumProcessed) {
		if s.EnableLastMsgSeqNumProcessed, err = settings.BoolSetting(config.EnableLastMsgSeqNumProcessed); err != nil {
			return
		}
	}

	if settings.HasSetting(config.ResendRequestChunkSize) {
		if s.ResendRequestChunkSize, err = settings.IntSetting(config.ResendRequestChunkSize); err != nil {
			return
		}
	}

	if settings.HasSetting(config.StartTime) || settings.HasSetting(config.EndTime) {
		var startTimeStr, endTimeStr string
		if startTimeStr, err = settings.Setting(config.StartTime); err != nil {
			return
		}

		if endTimeStr, err = settings.Setting(config.EndTime); err != nil {
			return
		}

		var start, end internal.TimeOfDay
		if start, err = internal.ParseTimeOfDay(startTimeStr); err != nil {
			return
		}

		if end, err = internal.ParseTimeOfDay(endTimeStr); err != nil {
			return
		}

		loc := time.UTC
		if settings.HasSetting(config.TimeZone) {
			var locStr string
			if locStr, err = settings.Setting(config.TimeZone); err != nil {
				return
			}

			loc, err = time.LoadLocation(locStr)
			if err != nil {
				return
			}
		}

		if !settings.HasSetting(config.StartDay) && !settings.HasSetting(config.EndDay) {
			s.SessionTime = internal.NewTimeRangeInLocation(start, end, loc)
		} else {
			var startDayStr, endDayStr string
			if startDayStr, err = settings.Setting(config.StartDay); err != nil {
				return
			}

			if endDayStr, err = settings.Setting(config.EndDay); err != nil {
				return
			}

			parseDay := func(setting, dayStr string) (day time.Weekday, err error) {
				day, ok := dayLookup[dayStr]
				if !ok {
					return day, IncorrectFormatForSetting{Setting: setting, Value: dayStr}
				}
				return
			}

			var startDay, endDay time.Weekday
			if startDay, err = parseDay(config.StartDay, startDayStr); err != nil {
				return
			}

			if endDay, err = parseDay(config.EndDay, endDayStr); err != nil {
				return
			}

			s.SessionTime = internal.NewWeekRangeInLocation(start, end, startDay, endDay, loc)
		}
	}

	if f.BuildInitiators {
		if err = f.buildInitiatorSettings(s, settings); err != nil {
			return
		}
	}

	if s.log, err = logFactory.CreateSessionLog(s.sessionID); err != nil {
		return
	}

	if s.store, err = storeFactory.Create(s.sessionID); err != nil {
		return
	}

	s.sessionEvent = make(chan internal.Event)
	s.messageEvent = make(chan bool, 1)
	s.admin = make(chan interface{})
	s.application = application
	s.stateTimer = internal.EventTimer{Task: func() { s.sessionEvent <- internal.NeedHeartbeat }}
	s.peerTimer = internal.EventTimer{Task: func() { s.sessionEvent <- internal.PeerTimeout }}
	return
}
示例#30
0
文件: main.go 项目: jfyuen/quickfix
func main() {
	flag.Usage = usage
	flag.Parse()

	if flag.NArg() == 0 {
		usage()
	}

	fieldMap = make(map[string]int)
	fieldTypeMap = make(map[string]*datadictionary.FieldType)

	for _, dataDict := range flag.Args() {
		spec, err := datadictionary.Parse(dataDict)

		if err != nil {
			panic(err)
		}

		for _, field := range spec.FieldTypeByTag {
			fieldMap[field.Name] = int(field.Tag)

			if oldField, ok := fieldTypeMap[field.Name]; ok {
				//merge old enums with new
				if len(oldField.Enums) > 0 && field.Enums == nil {
					field.Enums = make(map[string]datadictionary.Enum)
				}

				for enumVal, enum := range oldField.Enums {
					if _, ok := field.Enums[enumVal]; !ok {
						//Verify an existing enum doesn't have the same description. Keep newer enum
						okToKeepEnum := true
						for _, newEnum := range field.Enums {
							if newEnum.Description == enum.Description {
								okToKeepEnum = false
								break
							}
						}

						if okToKeepEnum {
							field.Enums[enumVal] = enum
						}
					}
				}
			}

			fieldTypeMap[field.Name] = field
		}
	}

	sortedTags = make([]string, len(fieldMap))
	i := 0
	for f := range fieldMap {
		sortedTags[i] = f
		i++
	}
	sort.Strings(sortedTags)

	genTags()
	genFields()
	genEnums()
}