FIXTradingCommunity / fix-orchestra

Machine readable rules of engagement
Apache License 2.0
71 stars 34 forks source link

Questions about rules #160

Open bronnikova18 opened 2 years ago

bronnikova18 commented 2 years ago

Please provide sample code to define the following basic rules in Orchestra:

  1. field is required and it's value != some string value
  2. field is optional, but if field exists, it's value <= some float value
  3. if field1 == 'some value' field2 and field3 are forbidden Thanks!
donmendelson commented 2 years ago

I'm not sure of the business use case, so my examples may not be realistic, but I'll try to show the format.

  1. You could encode this as presence is required except that a certain value is forbidden.

    <fixr:fieldRef id="145" presence="required">
    <fixr:rule name="exception" presence="forbidden">
        <fixr:when>DeliverToLocationID == "BadLocation"</fixr:when>
    </fixr:rule>
    </fixr:fieldRef>
  2. Again, use a rule that sets it to forbidden in a certain exception case. Uses existence operator of Score DSL. Note that "le" operator avoids having to use an escape sequence for < in XML.

    <fixr:fieldRef id="2646">
    <fixr:rule name="exception" presence="forbidden">
        <fixr:when>exists CommissionRate and CommissionRage le 0.10 </fixr:when>
    </fixr:rule>
    </fixr:fieldRef>
  3. Write the rules for field2 and field3.

    <fixr:fieldRef id="9999">
    <fixr:rule name="Field2Exception" presence="forbidden">
        <fixr:when>field1 == "some value"</fixr:when>
    </fixr:rule>
    </fixr:fieldRef>
JoanPuig commented 2 years ago

How would you create a rule that enforces a given number of occurrences in a repeating group? Example, in a swap trade I want to make sure that there is exactly one party of type clearing house. I think I can filter them like this: Parties[PartyRole==4] but is there a count or length operator/function?

donmendelson commented 2 years ago

The overall size of a repeating group may be limited with group attributes; see Repeating group

Limits on the size of a repeating group may optionally be specified with implMinOccurs and implMaxOccurs attributes. If those attributes are not present, then the repeating has unbound size.

There currently is no count operator. However, we are gathering proposed enhancements for Orchestra v1.1, so feel free to propose a syntax for it.

bronnikova18 commented 2 years ago

Thank you! Examples are very helpful.

Could you please provide one more example:

donmendelson commented 2 years ago

I propose to add these examples to v1.1 documentation.