Basic Model

In this first complete example, we create a simple model that accepts incoming NewOrderSingle messages (FIX 4.4) and acknowledges them with an ExecutionReport.

Setting the stage

import FIX_4_4

Declaring incoming messages

message NewOrderSingle {
  req ClOrdID
  req Side
  req TransactTime
  req OrdType valid when it in [ OrdType.Limit, OrdType.Market ]
  req OrderQtyData.OrderQty
  opt Price
  ign Account
}

You can add general validation constraints too:

validate {
  this.OrdType == OrdType.Market ==> !present(this.Price)
}

Declaring outgoing messages

outbound message ExecutionReport {
  req OrderID
  req ExecID
  req ExecType
  req OrdStatus
  req Side
  req OrderQtyData.OrderQty
  req LeavesQty
  req CumQty
  opt Text
}

Receiving valid messages

receive ( msg : NewOrderSingle ) {
  send ExecutionReport {
    OrderID = msg.ClOrdID;
    ExecID = "";
    ExecType = ExecType.New;
    OrdStatus = OrdStatus.New;
    Side = msg.Side;
    LeavesQty = 0.0;
    OrderQtyData.OrderQty = msg.OrderQtyData.OrderQty;
  }
}

Rejecting invalid messages

reject (msg:NewOrderSingle, text:string){
  missingfield:{
    send ExecutionReport {
      OrderID = "";
      ExecID = "";
      ExecType = ExecType.New;
      OrdStatus = OrdStatus.New;
      Side = Side.Buy;
      OrderQtyData.OrderQty = 0.0;
      LeavesQty = 0.0;
      CumQty = 0.0;
      Text = Some text;
    }
  }
  invalidfield:{
    send ExecutionReport {
      OrderID = msg.ClOrdID;
      ExecID = "";
      ExecType = ExecType.New;
      OrdStatus = OrdStatus.New;
      Side = Side.Buy;
      OrderQtyData.OrderQty = 0.0;
      LeavesQty = 0.0;
      CumQty = 0.0;
      Text = Some text;
    }
  }
  invalid:{}
}

See also: Messages and Actions and Functions.