Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

Introduction

This document is a developer’s guide for the CME STP API library.

Prerequisites

The CME STP API library requires the following software installed on computer:

  • Microsoft .NET Framework 4.0

Deployment

  • Unpack the package and copy CMESTPapi.dll and Log4Net files
  • Add reference to CMESTPapi.dll in your .NET project

Logging Configuration

To replace the default logging settings you should specify the parameters in the %Application%\com.b2bits.CMESTP.Configuration.xml file.

  1. Open %Application%\com.b2bits.CMESTP.Configuration.xml file

Find the following section:

      <Logging>
        <Default>
          <LogLevel>Debug</LogLevel>
          <Path>C:\LogFiles\</Path>
          <NumOfFiles>4</NumOfFiles>
          <FileSizeInMb>5</FileSizeInMb>
          <NameRollingStyle>Date</NameRollingStyle>
        </Default>
      </Logging>
  1. Replace the value of tag <Path> if you need to move the log file location
  2. Replace the value of tag <LogLevel> if you need to change the logging level:

Supported values are:

                Error – log the errors only

                Warning - log the errors and warnings

                Info - log the errors, warnings and information messages

                Debug – log everything

Interfaces

class CMEApiConfiguration

 public class CMEApiConfiguration
{
	public CMEApiConfiguration();
 
	public string ApiURL { get; set; }
	public int ConnectionTimeout { get; set; }
	public string Description { get; }
	public string PartyFirmID { get; set; }
	public string PartyRole { get; set; }
	public string Password { get; set; }
	public int PollingTimeout { get; set; }
	public int ReconnectMaxTries { get; set; }
	public int RecoveryTimeout { get; set; }
	public DateTimeOffset StartTime { get; set; }
	public string TestXML { get; set; }
	public string UserName { get; set; }
}

Property

Default value

Description

ApiURL

 

URI of the FIXML API

ConnectionTimeout

10

Connection timeout of FIXML API connect (in seconds)

Description

 

Returns string representation of current configuration

LastUpdateTime

<No default value, automatically will be set to current time minus 24 hours (in time zone of CME)>

The timestamp of last received trade.

PartyFirmID

 

ID of Party that is the subject of the subscription

PartyRole

 

Indicates the type or role of the Party that is the subject of the subscription

Password

 

FIXML API password

PoolingTimeout

5

The frequency of pooling of the FIXML API (in seconds)

ReconnectMaxTries

-1

Amount of retries if connection was lost.

RecoveryTimeout

60000

The timeout between recovery attempts if any problem occurs during the pooling action (in milliseconds)

UserName

 

FIXML API login

class CMESTPapi

public sealed class CMESTPapi : IDisposable
{
	public CMESTPapi(CMEApiConfiguration config);
 
	public event CMESTPapi.TradeHandler onTrade;
 
	public string LicenseInfo();
	public void Start();
	public void Stop();
 
	public delegate void TradeHandler(object sender, XElement trade);
}

Using the CMESTPapi library

To use the library you should create the instance of CMEApiConfiguration object and fill in the desired configuration values. XML serialization could be used to load configuration settings from file.

Next, create the instance of CMESTPapi object with created above configuration as parameter. Subscribe to onTrade event.

Call Start() method to start polling. Process received Trade messages in onTrade event handler. Call Stop() to stop polling.

Sample Application

class Program
{
       static void Main(string[] args)
       {
              CMEApiConfiguration config = new CMEApiConfiguration();
              config.ApiURL = "https://servicesnr.cmegroup.com/cmestp/query";
              config.UserName = "API_CMESTP_EPAM_SYSTEMS";
              config.Password = "summer1!";
              config.PartyFirmID = "epam";
              config.PartyRole = "7";
              config.ConnectionTimeout = 10;
              config.PollingTimeout = 5;
              config.ReconnectMaxTries = -1;
              config.RecoveryTimeout = 60000;
              config.StartTime = DateTimeOffset.Parse("10/1/2014 12:00:00 PM -05:00");
 
              CMESTPapi api = null;
              try
              {
                     api = new CMESTPapi(config);
                     api.onTrade += OnTrade;
                     api.Start();
 
                     Console.WriteLine(api.LicenseInfo());
                     Console.WriteLine("CMESTP Client is running...");
                     Console.WriteLine("Press Enter to exit");
                     Console.ReadLine();
              }
              catch (ApplicationException e)
              {
                     Console.Error.WriteLine("CMESTPapi error: " + e.Message);
              }
              catch (System.ComponentModel.LicenseException e)
              {
                     Console.Error.WriteLine("Licensing error: " + e.Message);
              }
              catch (Exception e)
              {
                     Console.Error.WriteLine("Runtime error: " + e.Message);
              }
              finally
              {
                     if (api != null)
                           api.Stop();
              }
       }
 
       static void OnTrade(object sender, XElement trade)
       {
              Console.Write(trade.ToString());
              Console.WriteLine();
       }
}
  • No labels