Custom Message Fields and Cases

This tutorial shows how to add custom enum cases and custom message fields for venue-specific behavior.

Custom enum cases

extend enum OrdType {
  StopSpread "s"
}

Custom message fields

extend message NewOrderSingle {
  SpreadProportion "10001" :? float
}
message NewOrderSingle {
  req OrdType valid when it in [ OrdType.Limit, OrdType.Market, StopSpread ]
  opt SpreadProportion valid when case(it){None:true}{Some x: x>0.0 && x<1.0}
  opt Price
  validate {
    this.OrdType == OrdType.StopSpread ==> present(this.Price)
  }
}

Update state and receive logic

internal state {
  assignable{
    SpreadProportion :? float
    OrdType          :  OrdType
    OrdStatus        :  OrdStatus = OrdStatus.PendingNew;
  }
  bestBid: Price
  bestAsk: Price
}
receive (msg:NewOrderSingle) {
  assignFrom(msg,state)
  if msg.OrdType == StopSpread then
    case(msg.SpreadProportion)
    {Some x:
      if state.bestAsk != 0.0 &&
         x >= (state.bestAsk - state.bestBid)/state.bestAsk then
      {
        state.OrdStatus = OrdStatus.New
        state.ExecType = ExecType.New
      }
    }
}

Continue with Repeating Groups.