preloader
blog-post

Start Data FIX Session

author image

This part of the FIX API Starter application takes the responsibility to start a FIX API Data 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 startDataFix() {
 if (!devEnv) {
   if (startDataFixProd(resetSeqData)) {
     return true;
   } else {
     logger.error("Failed to start data service.");
     return false;
   }
 } else {
   if (startDataFixDev(resetSeqData)) {
     return true;
   } else {
     logger.error("Failed to start data service.");
     return false;
   }
 }
}

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

  boolean result = false;

  FileInputStream fileInputStream = null;

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

    dataFIX = new Data(settings, resetReq);
    MessageStoreFactory storeFactory = new FileStoreFactory(settings);
    LogFactory logFactory = null;
    logFactory = new FileLogFactory(settings);
    MessageFactory messageFactory = new DefaultMessageFactory();
    dataInitiator = new SocketInitiator(dataFIX, storeFactory, settings, logFactory,
        messageFactory);

    dataInitiator.start();

    result = true;
  } catch (Exception e) {
    dataInitiator = 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 startDataFixDev(boolean resetReq) {
  if (dataInitiator != null) {
    dataInitiator.stop(true);
    try {
      dataInitiator.start();
      return true;
    } catch (Exception e) {
      dataInitiator = null;
      e.printStackTrace();
      logger.error(e.getMessage());
      return false;
    }
  }

  boolean result = false;

  InputStream fileInputStream = null;

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

    dataFIX = new Data(settings, resetReq);
    MessageStoreFactory storeFactory = new FileStoreFactory(settings);
    LogFactory logFactory = null;
    logFactory = new FileLogFactory(settings);
    MessageFactory messageFactory = new DefaultMessageFactory();
    dataInitiator = new SocketInitiator(dataFIX, storeFactory, settings, logFactory,
        messageFactory);

    dataInitiator.start();

    result = true;
  } catch (Exception e) {
    dataInitiator = 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 …

Get Free Demo FIX API Account

We provide free demo FIX API accounts.

Book One
*