Code Monkey home page Code Monkey logo

quickfixj-spring-boot-starter's Introduction

Build Status codecov Maven Central Apache 2 QuickFixJ 2.1.0 Codacy code quality

Spring Boot Starter for QuickFixJ (Spring Boot 2)

This project is a Spring Boot Starter for QuickFixJ. It simplifies the configuration required to create and start an Initiator or Acceptor, and handles the lifecycle of the Connector.

Getting started

To use the QuickFixJ Server or QuickFixJ Client you have to add the QuickFixJ Spring Boot Starter dependency in your project.

<dependency>
    <groupId>io.allune</groupId>
    <artifactId>quickfixj-spring-boot-starter</artifactId>
    <version>2.5.0</version>
</dependency>

To enable the actuator endpoints you will also have to add the QuickFixJ Spring Boot Actuator dependency.

<dependency>
    <groupId>io.allune</groupId>
    <artifactId>quickfixj-spring-boot-actuator</artifactId>
    <version>2.5.0</version>
</dependency>

QuickFixJ Spring Boot Starter - Server

The @EnableQuickFixJServer will auto configure a QuickFixJ Server:

@EnableQuickFixJServer
@SpringBootApplication
public class AppServer {

    public static void main(String[] args) {
        SpringApplication.run(AppServer.class, args);
    }
}

The configuration can be done in the application.properties / application.yml.

quickfixj:
  server:
    config: classpath:quickfixj-server.cfg

Additionally you need to add a quickfixj-server.cfg file to configure the FIX sessions. The configuration is resolved using the following approach:

  • By the presence of a quickfix.SessionSettings bean named serverSessionSettings

  • By a configuration file defined by the quickfixj.server.config property

  • By the presence of the quickfixj.server.config system property

  • By a quickfixj-server.cfg in the working directory or at the root of the classpath

QuickFixJ Server properties

quickfixj.server.config=classpath:quickfixj-server.cfg # location of the quickfixj acceptor
quickfixj.server.auto-startup=true # whether to auto-connect to the remote endpoint at start up
quickfixj.server.phase=0 # phase in which this connection manager should be started and stopped
quickfixj.server.jmx-enabled=true # whether to register the jmx mbeans for the acceptor
quickfixj.server.concurrent.enabled=true # whether to use a simple SocketAcceptor or a ThreadedSocketAcceptor

QuickFixJ Server Actuator properties

management.endpoint.quickfixjserver.enabled=true # whether the endpoint is enabled or not
management.endpoints.web.exposure.include=quickfixjserver # whether the endpoint will be exposed

Example usage:

http://localhost:8081/actuator/quickfixjserver
{
  "FIX.4.2:EXEC->BANZAI": {
    "SenderCompID": "EXEC",
    "StartTime": "00:00:00",
    "DefaultMarketPrice": "12.30",
    "ValidOrderTypes": "1,2,F",
    "ConnectionType": "acceptor",
    "EndTime": "00:00:00",
    "BeginString": "FIX.4.2",
    "SocketAcceptPort": "9878",
    "TargetCompID": "BANZAI",
    "SenderCompID": "EXEC",
    "HeartBtInt": "30",
    "BeginString": "FIX.4.2",
    "TargetCompID": "BANZAI",
    "FileStorePath": "target/data/executor",
    "UseDataDictionary": "Y"
  },
  "FIX.4.1:EXEC->BANZAI": {
    "SenderCompID": "EXEC",
    "StartTime": "00:00:00",
    "DefaultMarketPrice": "12.30",
    "ValidOrderTypes": "1,2,F",
    "ConnectionType": "acceptor",
    "EndTime": "00:00:00",
    "BeginString": "FIX.4.1",
    "SocketAcceptPort": "9877",
    "TargetCompID": "BANZAI",
    "SenderCompID": "EXEC",
    "HeartBtInt": "30",
    "BeginString": "FIX.4.1",
    "TargetCompID": "BANZAI",
    "FileStorePath": "target/data/executor",
    "UseDataDictionary": "Y"
  }
}

QuickFixJ Spring Boot Starter - Client

The @EnableQuickFixJClient will auto configure a QuickFixJ Client:

@EnableQuickFixJClient
@SpringBootApplication
public class AppClient {

    public static void main(String[] args) {
        SpringApplication.run(AppClient.class, args);
    }
}

The configuration can be done in the application.properties / application.yml.

quickfixj:
  client:
    config: classpath:quickfixj-client.cfg

Additionally you need to add a quickfixj-client.cfg file to configure the FIX sessions. The configuration is resolved using the following approach:

  • By the presence of a quickfix.SessionSettings bean named clientSessionSettings

  • By a configuration file defined by the quickfixj.client.config property

  • By the presence of the quickfixj.client.config system property

  • By a quickfixj-client.cfg in the working directory or at the root of the classpath

QuickFixJ Client properties

quickfixj.client.config=classpath:quickfixj-client.cfg # location of the quickfixj initiator
quickfixj.client.auto-startup=true # whether to auto-connect to the remote endpoint at start up
quickfixj.client.phase=0 # phase in which this connection manager should be started and stopped
quickfixj.client.jmx-enabled=true # whether to register the jmx mbeans for the initiator
quickfixj.client.concurrent.enabled=true # whether to use a simple SocketInitiator or a ThreadedSocketInitiator

QuickFixJ Client Actuator properties

management.endpoint.quickfixjclient.enabled=true # whether the endpoint is enabled or not
management.endpoints.web.exposure.include=quickfixjclient # whether the endpoint will be exposed

Example usage:

http://localhost:8080/actuator/quickfixjclient
{
  "FIXT.1.1:BANZAI->EXEC": {
    "SenderCompID": "BANZAI",
    "StartTime": "00:00:00",
    "ConnectionType": "initiator",
    "EndTime": "00:00:00",
    "BeginString": "FIXT.1.1",
    "ReconnectInterval": "5",
    "TargetCompID": "EXEC",
    "DefaultApplVerID": "FIX.5.0",
    "SocketConnectHost": "localhost",
    "SenderCompID": "BANZAI",
    "HeartBtInt": "30",
    "BeginString": "FIXT.1.1",
    "TargetCompID": "EXEC",
    "FileStorePath": "target/data/banzai",
    "SocketConnectPort": "9881"
  },
  "FIX.4.2:BANZAI->EXEC": {
    "SenderCompID": "BANZAI",
    "StartTime": "00:00:00",
    "ConnectionType": "initiator",
    "EndTime": "00:00:00",
    "BeginString": "FIX.4.2",
    "ReconnectInterval": "5",
    "TargetCompID": "EXEC",
    "SocketConnectHost": "localhost",
    "SenderCompID": "BANZAI",
    "HeartBtInt": "30",
    "BeginString": "FIX.4.2",
    "TargetCompID": "EXEC",
    "FileStorePath": "target/data/banzai",
    "SocketConnectPort": "9878"
  }
}

Listening on quickfixj.Application messages

The QuickFixJ Spring Boot Starter provides a default implementation for the quickfixj.Application interface which publishes the messages received by the Server (Acceptor) and the Client (Initiator) as `ApplicationEvent`s.

If your application is only processing a subset of message types (i.e. toAdmin, toApp, onCreate, etc.) you will need to register an EventListener for these, with the appropriate message type as the only parameter for the listener method:

@EventListener
public void listenFromAdmin(FromAdmin fromAdmin) {
	...
}

@EventListener
public void listenFromApp(FromApp fromApp) {
	...
}

@EventListener
public void listenOnCreate(Create create) {
	...
}

@EventListener
public void listenOnLogon(Logon logon) {
	...
}

@EventListener
public void listenOnLogout(Logout logout) {
	...
}

@EventListener
public void listenToAdmin(ToAdmin toAdmin) {
	...
}

@EventListener
public void listenToApp(ToApp toApp) {
	...
}

In case the EventListener method throws an exception, this exception will be propagated up the quickfix.Session#next() method. Depending on the value of RejectMessageOnUnhandledException in the quickfixj configuration file, the message will be redelivered or dismissed.

QuickFixJTemplate

The QuickFixJTemplate provides a synchronous client to perform requests, exposing a simple, template method API over the QuickFixJ client.

@EnableQuickFixJServer provides a serverQuickFixJTemplate bean and @EnableQuickFixJClient provides a clientQuickFixJTemplate bean than can be Autowired in the application.

@Autowire
private QuickFixJTemplate serverQuickFixJTemplate;

...

SessionID sessionID = serverAcceptor.getSessions().stream()
        .filter(sessId ->
                sessId.getBeginString().equals(fixVersion) &&
                        sessId.getTargetCompID().equals(targetId))
        .findFirst()
        .orElseThrow(RuntimeException::new);

OrderCancelRequest message = new OrderCancelRequest(
        new OrigClOrdID("123"),
        new ClOrdID("321"),
        new Symbol("LNUX"),
        new Side(Side.BUY));

serverQuickFixJTemplate.send(message, sessionID);

License and Acknowledgement

The QuickFixJ Spring Boot Starter is released under version 2.0 of the Apache License.

This code includes software developed by quickfixengine.org.

quickfixj-spring-boot-starter's People

Contributors

esanchezros avatar mballoni avatar bhanuhiteshi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.