preloader
blog-post

Start Order FIX Session

author image

This part of the FIX API Starter application takes the responsibility to start a FIX API Order Session.

devEnv is configured to specify the running environment.

If devEnv is set to true, that stands for an environment in development. If devEnv is set to false, that stands for an environment in production.

public static boolean startOrderFix() {
  if (!devEnv) {
    if (startOrderFixProd(resetSeqOrder)) {
      return true;
    } else {
      logger.error("Failed to start order service.");
      return false;
    }
  } else {
    if (startOrderFixDev(resetSeqOrder)) {
      return true;
    } else {
      logger.error("Failed to start order service.");
      return false;
    }
  }
}

private static boolean startOrderFixProd(boolean resetReq) {
  if (orderInitiator != null) {
    orderInitiator.stop(true);
    try {
      orderInitiator.start();
      return true;
    } catch (Exception e) {
      orderInitiator = null;
      e.printStackTrace();
      logger.error(e.getMessage());
      return false;
    }
  }

  boolean result = false;

  FileInputStream fileInputStream = null;

  try {
    fileInputStream = new FileInputStream(orderCfgFileName);
    SessionSettings settings = new SessionSettings(fileInputStream);
    fileInputStream.close();
    fileInputStream = null;

    orderFIX = new Order(settings, resetReq);
    MessageStoreFactory storeFactory = new FileStoreFactory(settings);
    LogFactory logFactory = new FileLogFactory(settings);
    MessageFactory messageFactory = new DefaultMessageFactory();
    orderInitiator = new SocketInitiator(orderFIX, storeFactory, settings, logFactory,
        messageFactory);

    orderInitiator.start();

    result = true;
  } catch (Exception e) {
    orderInitiator = null;
    e.printStackTrace();
    logger.error(e.getMessage());
  } finally {
    if (fileInputStream != null) {
      try {
        fileInputStream.close();
      } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.getMessage());
      }
    }
  }

  return result;
}

private static boolean startOrderFixDev(boolean resetReq) {
  if (orderInitiator != null) {
    orderInitiator.stop(true);
    try {
      orderInitiator.start();
      return true;
    } catch (Exception e) {
      orderInitiator = null;
      e.printStackTrace();
      logger.error(e.getMessage());
      return false;
    }
  }

  boolean result = false;

  InputStream fileInputStream = null;

  try {
    fileInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(orderCfgFileName);
    SessionSettings settings = new SessionSettings(fileInputStream);
    fileInputStream.close();
    fileInputStream = null;

    orderFIX = new Order(settings, resetReq);
    MessageStoreFactory storeFactory = new FileStoreFactory(settings);
    LogFactory logFactory = new FileLogFactory(settings);
    MessageFactory messageFactory = new DefaultMessageFactory();
    orderInitiator = new SocketInitiator(orderFIX, storeFactory, settings, logFactory,
        messageFactory);

    orderInitiator.start();

    result = true;
  } catch (Exception e) {
    orderInitiator = null;
    e.printStackTrace();
    logger.error(e.getMessage());
  } finally {
    if (fileInputStream != null) {
      try {
        fileInputStream.close();
      } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.getMessage());
      }
    }
  }

  return result;
}

Relevant Articles

Fintechee Online FIX API Parser

The received messages will output to the “orderlog” folder.

If you want to parse them, please use Fintechee Online FIX Parser.

Fintechee FIX API Trading Platform Individual Version

If you want to trade via FIX API, please use Fintechee FIX API Trading Platform Individual Version(Paid Version).

If you have a Github / Youtube account, you can get a free license for the paid version(No Charge)!

If you have no Github / Youtube account, you can still use Fintechee FIX API Trading Platform Bridge Version(Free Forever)!

If you are working for financial institutions, you can choose Fintechee FIX API Trading Platform Institution Version(White Label License).

Github Repository

Please access our Github repository to get the latest source codes.

Recent Articles

blog-post

FIX API Starter Application Class

This is the FIX API Starter Application Class. It includes: A method to be called to start FIX API Data session A method …

Paid Consulting Service

We offer professional FIX API consulting services, including self-service options for establishing a broker business. There are no additional fees, and all resources can be utilized without any associated costs.

Book One
*