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

Compare with Current View Page History

« Previous Version 6 Next »

Overview

The Order Routing System is responsible for managing sessions with external brokers and exchanges, sending orders, receiving execution reports, and maintaining order history. The Order Routing System has a JMS bus for order and execution report traffic and a web services API for order history and positions.

Running Order Routing System

The Order Routing System is a command-line application with no UI. The Order Routing System acts as the server component in the Marketcetera Automated Trading Platform stack.

Windows

On Windows, the Order Routing System is started from the Start Menu: Marketcetera->Marketcetera-2.4.0->Start Marketcetera Server Components.

03 Jan 2014 06:27:01,218  INFO [main] marketcetera.ors.OrderRoutingSystem (OrderRoutingSystem.java:357) - Copyright (c) 2006-2013 Marketcetera, Inc.
03 Jan 2014 06:27:01,245  INFO [main] marketcetera.ors.OrderRoutingSystem (OrderRoutingSystem.java:358) - ORS version '2.4.0' (build 'cc.build.335')
03 Jan 2014 06:27:01,245  INFO [main] marketcetera.ors.OrderRoutingSystem (OrderRoutingSystem.java:361) - ORS is starting
03 Jan 2014 06:27:10,930  INFO [main] marketcetera.ors.OrderRoutingSystem (OrderRoutingSystem.java:380) - ORS started successfully. Ctrl-C to exit

Linux

$ ./startServerComponents.sh 
nohup: redirecting stderr to stdout
Starting mysqld daemon with databases from /home/colin/marketcetera/marketcetera-2.4.0/mysql/data
06 Jan 2014 10:43:02,401  INFO [main] marketcetera.ors.OrderRoutingSystem (OrderRoutingSystem.java:357) - Copyright (c) 2006-2013 Marketcetera, Inc.
06 Jan 2014 10:43:02,426  INFO [main] marketcetera.ors.OrderRoutingSystem (OrderRoutingSystem.java:358) - ORS version '2.4.0' (build 'cc.build.335')
06 Jan 2014 10:43:02,427  INFO [main] marketcetera.ors.OrderRoutingSystem (OrderRoutingSystem.java:361) - ORS is starting
Jan 6, 2014 10:43:03 AM java.util.prefs.FileSystemPreferences$7 run
06 Jan 2014 10:43:12,850  INFO [main] marketcetera.ors.OrderRoutingSystem (OrderRoutingSystem.java:380) - ORS started successfully. Ctrl-C to exit

Broker and Exchange Connections

The Order Routing System maintains connections to one or more brokers and exchanges via FIX (Financial Information eXchange) sessions. It is possible to connect to non-FIX destinations with some custom configuration. Upon start, the Order Routing System attempts to establish connections to all configured order destinations. If connection is lost, Marketcetera Automated Trading Platform client applications are notified of the loss of connectivity and the Order Routing System attempts to reconnect at regular intervals.

Brokers and exchanges are identified in the Order Routing System configuration. Upon installation, the Order Routing System is already configured to connect to the Marketcetera simulated exchange. The configuration files for a broker define the FIX session settings for that broker, gateway host and port, like start of session, end of session, and FIX version. You can also define optional attributes like message modifiers and response modifiers.

Message Modifiers

A message modifier is used to modify or selectively modify orders before they are released to a broker or exchange. A message modifier is simply a unit of code that receives the order before it is sent and has the opportunity to modify it or throw an exception to prevent it being sent at all. Multiple message modifiers can be applied in the sequence defined in the configuration files. Message modifiers are defined per broker.

In addition to message modifiers, there are also pre-send message modifiers. The distinction between the two are simply when the modifiers are activated. Message modifiers are applied before routing modification. Pre-send message modifiers are applied after routing modification.

To create a message modifier or a pre-send message modifier, write a Java class that extends org.marketcetera.ors.filters.MessageModifier. Build the class into a JAR and deploy the it to the Order Routing System lib directory. After the next restart, the message modifier will be available for use. To activate the message modifier, edit the main.xml file for your broker. Make sure this entry exists:

<property name="modifiers" ref="your_modifiers"/>

or, for pre-send modifiers, this:

<property name="preSendModifiers" ref="your_ps_modifiers"/>

The ref can be any name you want as long as it matches an entry in either modifiers.xml or ps_modifiers.xml, as appropriate. The contents of modifiers.xml might look like this:

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
  <bean id="your_modifiers" class="org.marketcetera.ors.filters.MessageModifierManager">
    <property name="messageModifiers">
      <list>
        <bean id="your_modifier_1" class="com.acme.yourcompany.MyMessageModifier">
          <property name="property1" value="some value here"/>
        </bean>
        <bean id="your_modifier_2" class="com.acme.yourcompany.MyMessageModifier">
          <property name="property1" value="some value here"/>
        </bean>
      </list>
    </property>
  </bean>
</beans>

This would define two message modifiers, to be applied in the order indicated. Each modifier can have its own properties, or none. In addition to the MessageModifier interface, there is also the SessionAwareMessageModifier interface. The operation of the modifier is the same, but the session-aware version has access to the session info of the order sender.

Here is the implementation of FieldDuplicatorMessageModifier:

public class FieldDuplicatorMessageModifier
        implements MessageModifier
{
    /**
     * Create a new FieldDuplicatorMessageModifier instance.
     *
     * @param sourceField an <code>int</code> value
     * @param destField an <code>int</code> value
     */
    public FieldDuplicatorMessageModifier(int sourceField,
                                          int destField)
    {
        this.sourceField = sourceField;
        this.destField = destField;
    }
    /* (non-Javadoc)
     * @see org.marketcetera.ors.filters.MessageModifier#modifyMessage(quickfix.Message, org.marketcetera.ors.history.ReportHistoryServices, org.marketcetera.quickfix.messagefactory.FIXMessageAugmentor)
     */
    @Override
    public boolean modifyMessage(Message inMessage,
                                 ReportHistoryServices inHistoryServices,
                                 FIXMessageAugmentor inAugmentor)
            throws CoreException
    {
        try {
            if(inMessage.isSetField(sourceField)) {
                String value = inMessage.getString(sourceField);
                inMessage.setField(new StringField(destField,value));
                return true;
            }
            return false;
        } catch (FieldNotFound fieldNotFound) {
            throw new CoreException(fieldNotFound);
        }
    }
    /**
     * field to which to duplicate
     */
    private int destField;
    /**
     * field from which to duplicate
     */
    private int sourceField;
}

This message modifier copies the value from one field to another, if the source field is set. This can be useful for brokers that might require the symbol (field 55) to also be in another field, for example. The modifier returns true or false depending on whether the message was modified or not. To prevent the order from being sent, the modifier can throw an exception. Note that you can implement risk management using this technique, if you like.

There are several pre-defined message modifiers you can use as-is or as a model for your own modifiers.

  • ConditionalFieldRemoverMessageModifier - removes a field from a message if a given condition is met
  • ConditionalMessageModifier - modifies a message if a given condition is met
  • DefaultMessageModifier - sets specified fields to specified values in all messages
  • FieldDuplicatorMessageModifier - copies the string value of one field to another
  • FieldOverrideMessageModifier - sets the value of the given fields regardless of the original value
  • OrderTagRecorder - records specified fields from outgoing orders, used with OrderTagRemapper
  • OrderTagRemapper - remaps saved order tags onto execution reports, used with OrderTagRecorder. The use case here is if you want to retain some tags on orders that your broker won't accept (identification tags not present in the canonical FIX spec, for example). You use the OrderTagRecorder and the OrderTagRemapper on outgoing orders and incoming execution reports, respectively. The tags are transparently removed from outgoing orders and added back to incoming execution reports without the broker ever seeing them. You can then sort or filter on that tag.
  • TransactionTimeInsertMessageModifier - inserts the TransactTime field into an order if it's not currently present
  • UserInfoMessageModifier - sets the SenderSubID on outgoing messages according to the Marketcetera user that initiated the order

Response Modifiers

A response modifier is similar to a message modifier and implements the same interface. It is used to modify incoming execution reports. To activate a response modifier, make sure this property is in the broker main.xml file:

<property name="responseModifiers" ref="your_response_modifiers"/>

The ref can be any name you want as long as it matches an entry in  resp_modifiers.xml. The contents of resp_modifiers.xml might look like this:

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
  <bean id="your_response_modifiers" class="org.marketcetera.ors.filters.MessageModifierManager">
    <property name="messageModifiers">
      <list>
        <bean id="your_response_modifier_1" class="com.yourcompany.MyMessageModifier">
          <property name="property1" value="some value here"/>
        </bean>
        <bean id="your_response_modifier_2" class="com.yourcompany.MyMessageModifier">
          <property name="property1" value="some value here"/>
        </bean>
      </list>
    </property>
  </bean>
</beans>

Order Routing

Order routing in the Order Routing System is the process of choosing to which of the available destinations an order should be sent. A given order may be sent to any destination. The order as created in the Marketcetera Automated Trading Platform will be customized as necessary depending on the chosen destination.

When an order is created, you may explicitly choose a destination in your strategy or in the UI, or you may leave it to the Order Routing System to route the order. The Order Routing System is configured with a default destination. You may also establish your own custom rules for order routing.

The precedence for order routing is as follows:

  1. Destination selected when the order is created
  2. Destination selected from configurable routing rules
  3. Default destination

The default destination is defined in ors/conf/brokers/selector.xml in the property defaultBroker:

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
  <bean id="metc_selector" class="org.marketcetera.ors.brokers.SpringSelector">
    <!-- Default broker. -->
    <property name="defaultBroker" ref="metc_broker"/>
  </bean>
</beans>

Set the default broker to the id of a broker in one of the broker main.xml files.

To establish your own routing rules, you need to create one or more classes that extend org.marketcetera.ors.brokers.SpringSelectorEntry. When routing an order, the Order Routing System passes the outgoing order to each class you define/ The selector entry you create returns a boolean value that determines whether the order should go to the broker associated with the selector entry. If all entries return false, the order is routed to the default broker.

The selector.xml file with selectors looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
  <bean id="metc_selector" class="org.marketcetera.ors.brokers.SpringSelector">
    <!-- Routing entries -->
    <property name="entries>
      <list>
        <bean class="com.yourcompany.RoutingSelector1">
          <property name="broker" ref="broker1"/> <!-- matches the id of a broker bean -->
          <property name="skipIfUnavailable" value="true"/>
        </bean>
        <bean class="com.yourcompany.RoutingSelector2">
          <property name="broker" ref="broker2"/> <!-- matches the id of a broker bean -->
          <property name="skipIfUnavailable" value="true"/>
        </bean>
      </list>
    </property>
    <!-- Default broker -->
    <property name="defaultBroker" ref="broker3"/>
  </bean>
</beans>

Here is a sample broker selector that routes by security type:

package org.marketcetera.ors.brokers;


import org.apache.commons.lang.Validate;
import org.marketcetera.trade.Order;
import org.marketcetera.trade.SecurityType;
import org.springframework.beans.factory.InitializingBean;


/**
 * Selects a target broker by {@link SecurityType}.
 *
 * @author <a href="mailto:colin@marketcetera.com">Colin DuPlantis</a>
 * @version $Id$
 * @since $Release$
 */
public class SecurityTypeSelectorEntry
        implements SpringSelectorEntry, InitializingBean
{
    /* (non-Javadoc)
     * @see org.marketcetera.ors.brokers.SpringSelectorEntry#routeToBroker(org.marketcetera.trade.Order)
     */
    @Override
    public boolean routeToBroker(Order inOrder)
    {
        SecurityType orderType = inOrder.getSecurityType();
        if((orderType != null) && orderType != SecurityType.Unknown) {
            if(targetType.equals(orderType)) {
                return true;
            }
        }
        return false;
    }
    /* (non-Javadoc)
     * @see org.marketcetera.ors.brokers.SpringSelectorEntry#setBroker(org.marketcetera.ors.brokers.SpringBroker)
     */
    @Override
    public void setBroker(SpringBroker inBroker)
    {
        broker = inBroker;
    }
    /* (non-Javadoc)
     * @see org.marketcetera.ors.brokers.SpringSelectorEntry#getBroker()
     */
    @Override
    public SpringBroker getBroker()
    {
        return broker;
    }
    /* (non-Javadoc)
     * @see org.marketcetera.ors.brokers.SpringSelectorEntry#setSkipIfUnavailable(boolean)
     */
    @Override
    public void setSkipIfUnavailable(boolean inSkipIfUnavailable)
    {
        skipIfUnavailable = inSkipIfUnavailable;
    }
    /* (non-Javadoc)
     * @see org.marketcetera.ors.brokers.SpringSelectorEntry#getSkipIfUnavailable()
     */
    @Override
    public boolean getSkipIfUnavailable()
    {
        return skipIfUnavailable;
    }
    /* (non-Javadoc)
     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
     */
    @Override
    public void afterPropertiesSet()
            throws Exception
    {
        Validate.notNull(targetType);
        Validate.notNull(broker);
    }
    /**
     * Sets the targetType value.
     *
     * @param inTargetType a <code>String</code> value
     */
    public void setTargetType(String inTargetType)
    {
        targetType = SecurityType.getInstanceForFIXValue(inTargetType);
    }
    /**
     * target broker
     */
    private SpringBroker broker;
    /**
     * indicates if this routing should be skipped if unavailable
     */
    private boolean skipIfUnavailable = true;
    /**
     * target security type
     */
    private SecurityType targetType;
}

You could use this selector to send, for example, all equities to broker1 and all options to broker2. Simply create two instances of this bean in selector.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
  <bean id="metc_selector" class="org.marketcetera.ors.brokers.SpringSelector">
    <!-- Routing entries -->
    <property name="entries>
      <list>
        <bean class="org.marketcetera.ors.brokers.SecurityTypeSelectorEntry">
          <property name="broker" ref="broker1"/> <!-- matches the id of a broker bean -->
          <property name="targetType" value="CS"/> <!-- 'CS' == Equities (Common Stock) -->
          <property name="skipIfUnavailable" value="true"/>
        </bean>
        <bean class="org.marketcetera.ors.brokers.SecurityTypeSelectorEntry">
          <property name="broker" ref="broker2"/> <!-- matches the id of a broker bean -->
          <property name="targetType" value="OPT"/>
          <property name="skipIfUnavailable" value="true"/>
        </bean>
      </list>
    </property>
    <!-- Default broker -->
    <property name="defaultBroker" ref="broker3"/>
  </bean>
</beans>

The skipIfUnavailable property regulates if the entry should be skipped if the broker is offline.

Broker Algorithms

Order History

Positions

Symbol Resolution

Authentication and Authorization

  • No labels