preloader
blog-post

Data FIX API Class Basic Components

author image

These are the basic components for FIX API Data class.

It includes:

  • Member variables
private boolean resetReq;
String mdReqID;

private String userName;
private String userPassword;
private String accountId;

private long requestID;
private SessionID sessionID;

List<String> symbolsList;

resetReq is used to configure whether to reset sequence number once reconnected. mdReqID is used to store the ID of a new subscription to streaming quotes. It will be used when you unsubscribe from the streaming quotes. nextID is used to generate a new unique ID.

  • Construction method
public Data(SessionSettings settings, boolean resetReq) {
  this.resetReq = resetReq;

  try {
    userName = settings.getString("Username");
    userPassword = settings.getString("Password");
    accountId = settings.getString("AccountId");

    symbolsList = new ArrayList<String>();
    symbolsList.add("EUR/USD");
    symbolsList.add("EUR/GBP");
    symbolsList.add("GBP/USD");
  } catch (Exception e) {
    e.printStackTrace();
    logger.error(e.getMessage());
  }
}
  • Method to generate a unique request ID for the subscription to the streaming quotes
private synchronized long nextID() {
  requestID++;
  if (requestID > 0x7FFFFFF0) {
    requestID = 1;
  }
  return requestID;
}
  • Callback to receive administrative message, and then do some extra validations
public void fromAdmin(Message message, SessionID sessionID) {
  try {
    crack(message, sessionID);
  } catch (Exception e) {
    e.printStackTrace();
    logger.error(e.getMessage());
  }
}
  • Callback to receive application-level message, and then do some extra validations
public void fromApp(Message message, SessionID sessionID) {
  try {
    crack(message, sessionID);
  } catch (Exception e) {
    e.printStackTrace();
    logger.error(e.getMessage());
  }
}
  • Callback to add some extra tag fields before sending an administrative message
public void toAdmin(Message message, SessionID sessionID) {
  try {
    if (message instanceof Logon) {
      logger.info("Data via toAdmin login begun for " + this.userName);

      message.setString(Username.FIELD, userName);
      message.setString(Password.FIELD, userPassword);
      if (resetReq) {
        message.setBoolean(ResetSeqNumFlag.FIELD, ResetSeqNumFlag.YES_RESET_SEQUENCE_NUMBERS);
      }
      message.setInt(EncryptMethod.FIELD, EncryptMethod.NONE_OTHER);
    } else if (message instanceof Logout) {
      logger.info("Data logged out via toAdmin " + this.userName);

      sendMarketDataRequestList(SubscriptionRequestType.DISABLE_PREVIOUS_SNAPSHOT_UPDATE_REQUEST);
    }
  } catch (Exception e) {
    e.printStackTrace();
    logger.error(e.getMessage());
  }
}
  • Callback to add some extra tag fields before sending an application-level message
public void toApp(Message message, SessionID sessionID) {
}
  • Callback to notify you when a new session is established
public void onCreate(SessionID sessionID) {
  this.sessionID = sessionID;
}
  • Interface for the client side to logout the current session
public void logout() {
  Logout mdr = new Logout();
  send(mdr);
}
  • Callback to notify you when a new valid logon is established
public void onLogon(SessionID sessionID) {
  logger.warn("Data via onLogon login begun" + (userName == null ? "" : " for " + userName) );

  sendMarketDataRequestList(SubscriptionRequestType.SNAPSHOT_UPDATES);
}
  • Callback to notify you when a new valid logout is established
public void onLogout(SessionID sessionID) {
  logger.warn("Data logged out via onLogout" + (userName == null ? "" : " for " + userName) );

  sendMarketDataRequestList(SubscriptionRequestType.DISABLE_PREVIOUS_SNAPSHOT_UPDATE_REQUEST);
}
  • Method to send request messages via the FIX API data session
private void send(Message message) {
  try {
    Session.sendToTarget(message, sessionID);
  } catch (Exception e) {
    e.printStackTrace();
    logger.error(e.getMessage());
  }
}

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
*