コード例 #1
0
ファイル: fixclient.go プロジェクト: cyanly/gotrade
// Common Order FIX client routines serving requests from order router
//   if a market connector has special case it will need to implement its own start routine like below
func (app FIXClient) Start() error {
	err := app.Initiator.Start()

	// Subscribe to order flow topics
	// NEW
	app.MessageBus.Subscribe("order.NewOrderRequest.MC."+app.marketConnectorName, func(m *messagebus.Msg) {
		request := new(proto.NewOrderRequest)
		if err := request.Unmarshal(m.Data); err == nil {
			order := request.Order

			//TODO: this is only prototype, migrate common tasks: instruments / limits processing

			fixmsg := fix44nos.Message{
				ClOrdID:      strconv.Itoa(int(order.OrderKey)) + "." + strconv.Itoa(int(order.Version)),
				Side:         util.ProtoEnumToFIXEnum(int(order.Side)),
				TransactTime: time.Now(),
				OrdType:      util.ProtoEnumToFIXEnum(int(order.OrderType)),
			}

			// Instrument specific
			fixmsg.Instrument.Symbol = &order.Symbol

			fixmsg.OrderQty = &order.Quantity
			if order.OrderType == proto.OrderType_LIMIT || order.OrderType == proto.OrderType_LIMIT_ON_CLOSE {
				fixmsg.Price = &order.LimitPrice
			}

			// Broker specific
			fixmsg.Account = &order.BrokerAccount
			fixmsg.HandlInst = stringPtr(util.ProtoEnumToFIXEnum(int(order.HandleInst)))

			// 142 SenderLocationID
			//     Mandatory for CME exchanges. It contains a 2-character country. For the US and Canada, the state/province is included.
			fixmsg.SenderLocationID = stringPtr("UK")

			log.Info("MC->FIX FIX44NewOrderSingle")
			if err := quickfix.SendToTarget(fixmsg, app.Session); err != nil {
				log.WithError(err).Fatal("FIX quickfix.SendToTarget Error")
			}

		}
	})

	// TODO: CANCEL

	// TODO: REPLACE

	return err
}
コード例 #2
0
ファイル: service.go プロジェクト: cyanly/gotrade
func NewService(c Config) *Service {

	// Hardware Info
	uuid = fmt.Sprint(hostname, ":", pid)
	log.Infof("Service [%v] starting @ %v", c.ServiceName, uuid)

	// Service handle
	svc := &Service{
		Config:          c,
		Status:          proto.STARTING,
		shutdownChannel: make(chan bool),
	}

	// Messaging bus
	messageBus, err := messagebus.Connect(svc.Config.MessageBusURL)
	svc.messageBus = messageBus
	if err != nil {
		log.WithField("MessageBusURL", svc.Config.MessageBusURL).Fatal("error: Cannot connect to message bus")
	}

	//Heartbeating
	currDateTime := time.Now().UTC().Format(time.RFC3339)
	hbMsg := &proto.Heartbeat{
		Name:             svc.Config.ServiceName,
		Id:               uuid,
		Status:           proto.STARTING,
		Machine:          hostname,
		CreationDatetime: currDateTime,
		CurrentDatetime:  currDateTime,
	}
	svc.lastHBMsg = hbMsg
	hbTicker := time.NewTicker(time.Second * time.Duration(svc.Config.HeartbeatFreq))
	go func(shutdownChannel chan bool) {
		publish_address := "service.Heartbeat." + svc.Config.ServiceName

		for range hbTicker.C {
			hbMsg.CurrentDatetime = time.Now().UTC().Format(time.RFC3339)
			hbMsg.Status = svc.Status

			if data, _ := hbMsg.Marshal(); data != nil {
				messageBus.Publish(publish_address, data)
			}

			select {
			case <-shutdownChannel:
				hbTicker.Stop()

				//Publish Stop heartbeat
				if svc.Status != proto.ERROR {
					svc.Status = proto.STOPPED
				}
				hbMsg.CurrentDatetime = time.Now().UTC().Format(time.RFC3339)
				hbMsg.Status = svc.Status
				if data, _ := hbMsg.Marshal(); data != nil {
					messageBus.Publish(publish_address, data)
				}

				messageBus.Close()

				log.Info("Server Terminated")
				return
			}
		}
	}(svc.shutdownChannel)

	return svc
}
コード例 #3
0
ファイル: logger_test.go プロジェクト: cyanly/gotrade
func BenchmarkLogger_small(b *testing.B) {
	for i := 0; i < b.N; i++ {
		l.Info("login")
	}
}
コード例 #4
0
ファイル: logger_test.go プロジェクト: cyanly/gotrade
func TestLogger_levels(t *testing.T) {
	l.Debug("uploading")
	l.Info("upload complete")
}