Exemplo n.º 1
0
func TestNewMarketConnectorNewOrderRequest(t *testing.T) {
	//config
	sc := common.NewConfig()
	sc.MessageBusURL = "nats://localhost:22222"
	sc.DatabaseDriver = "memstore"

	//start MC
	svc := NewMarketConnector(sc)
	svc.Start()

	time.Sleep(100 * time.Millisecond)

	// mock a NewOrderRequest, really should come from OrderRouter
	request := &proto.NewOrderRequest{
		Order: testOrder.MockOrder(),
	}
	request.Order.OrderStatus = proto.OrderStatus_ORDER_RECEIVED
	request.Order.SubmitDatetime = time.Now().UTC().Format(time.RFC3339Nano)
	request.Order.MessageType = proto.Order_NEW
	request.Order.OrderKey = int32(321)
	svc.app.OrderStore.OrderCreate(request.Order)

	// subscribe to check if we can receive a fill execution report from sim broker
	recvExecutionReport := false
	svc.app.MessageBus.Subscribe("order.Execution", func(m *messagebus.Msg) {
		recvExecutionReport = true
		exec := new(proto.Execution)
		if err := exec.Unmarshal(m.Data); err == nil {
			if exec.ClientOrderId != "321.1" {
				t.Fatalf("unexpected execution report ClOrdId %v, expecting 321.1", exec.ClientOrderId)
			}
			if exec.OrderId != 1 {
				t.Fatalf("unexpected execution report OrderId %v, expecting 1", exec.OrderId)
			}
		} else {
			t.Fatalf("unexpected execution report: %v", err)
		}
	})

	// send above mock NewOrderRequest
	data, _ := request.Marshal()
	svc.app.MessageBus.Publish("order.NewOrderRequest.MC."+MarketConnectorName, data)

	time.Sleep(100 * time.Millisecond)

	//stop and disconnect MC
	svc.Close()

	if recvExecutionReport == false {
		t.Fatal("No execution report received from mock order new request")
	}

}
Exemplo n.º 2
0
func TestMain(m *testing.M) {
	// Start a temporary messaging broker
	ts := test.RunDefaultServer()
	defer ts.Shutdown()

	// Start OrderRouter service
	orSC := orderrouter.NewConfig()
	orSC.MessageBusURL = "nats://localhost:22222"
	orSC.ServiceMessageBusURL = "nats://localhost:22222"
	orSC.DatabaseDriver = "memstore"
	orSvc := orderrouter.NewOrderRouter(orSC)
	orSvc.Start()
	defer orSvc.Close()

	// Start Simulated FIX Sell Side
	sellsvc := sellsidesim.NewSellSideSimulator("")
	sellsvc.Start()
	defer sellsvc.Close()

	// Start a MarketConnector Service for simuilated market
	// 1. MC (implementation)
	mcSC := MCCommon.NewConfig()
	mcSC.MessageBusURL = "nats://localhost:22222"
	mcSC.DatabaseDriver = "memstore"
	mcSvc := MCSimulator.NewMarketConnector(mcSC)
	mcSvc.Start()
	defer mcSvc.Close()
	// 2. Service (heartbeating etc)
	sc := service.NewConfig()
	sc.MessageBusURL = "nats://localhost:22222"
	sc.ServiceName = "MC." + mcSvc.Name()
	svc := service.NewService(sc)
	svc.Start()
	defer svc.Stop()

	// Turn off logging to measure performance
	logger.Discard()

	time.Sleep(100 * time.Millisecond) // async

	// Connect messaging bus for this mock client
	if nc, err := nats.Connect("nats://localhost:22222"); err != nil {
		log.Fatal("error: Cannot connect to message bus")
	} else {
		msgbus = nc
	}

	code := m.Run()
	os.Exit(code)
}
Exemplo n.º 3
0
func TestNewMarketConnectorStartAndStop(t *testing.T) {
	//config
	sc := common.NewConfig()
	sc.MessageBusURL = "nats://localhost:22222"
	sc.DatabaseDriver = "memstore"

	//start MC
	svc := NewMarketConnector(sc)
	svc.Start()

	//stop and disconnect MC
	time.Sleep(100 * time.Millisecond)
	svc.Close()

	//expect no panic
}
Exemplo n.º 4
0
func main() {

	// Load configurations

	// Initialise Service Infrastructure
	sc := service.NewConfig()
	sc.ServiceName = "Simulator"
	svc := service.NewService(sc)

	// Initialise Component
	orc := common.NewConfig()
	orc.MessageBusURL = sc.MessageBusURL

	// Initialise Database Connection
	orc.DatabaseDriver = "memstore"

	orsvc := simulator.NewMarketConnector(orc)
	orsvc.Start()
	defer orsvc.Close()

	// Go
	<-svc.Start()
}