Skip to content

Instantly share code, notes, and snippets.

@andybrackley
Created February 23, 2014 19:38
Show Gist options
  • Save andybrackley/9176191 to your computer and use it in GitHub Desktop.
Save andybrackley/9176191 to your computer and use it in GitHub Desktop.
namespace TibcoMessagePoster.Model
type FixField<'a>(fieldName, fieldId, validator : ('a -> bool)) =
member self.FieldName = fieldName
member self.FieldId = fieldId
member self.Validator = validator
new(fieldName, fieldId) = FixField(fieldName, fieldId, fun _ -> true )
type FixHeaderFields =
static member ApplVerId = FixField("ApplVerId", "1128", fun str -> str = "9")
static member MsgType = FixField("MsgType", "35", fun str -> str = "X")
static member SenderCompId = FixField("SenderCompId", "49", fun (str : string) -> str.Length <= 7)
static member MsgSeqNum = FixField("MsgSeqNum", "34")
static member SendingTime = FixField("SendingTime", "52")
type FixFieldsBlockTrade =
static member TradeDate = FixField("TradeDate", "75")
static member NoMDEntries = FixField("NoMDEntries", "268")
static member MDUpdateAction = FixField("MDUpdateAction", "279", fun ch -> ch = '0' || ch = '2')
static member MDEntryType = FixField("MDEntryType", "269", fun ch -> ch = 'T')
static member RptSeq = FixField<int>("RptSeq", "83")
static member Symbol = FixField<string>("Symbol", "55", fun (str : string) -> str.Length <= 50)
static member SecurityGroup = FixField<string>("SecurityGroup", "1151", fun (str : string) -> str.Length <= 12)
static member SecurityType = FixField<string>("SecurityType", "167", fun str -> str = "FUT" || str = "OPT")
static member MaturityMonthYear = FixField<string>("MaturityMonthYear", "200")
static member SecurityExchange = FixField<string>("SecurityExchange", "207", fun (str : string) -> str.Length = 4)
static member MaturityDate = FixField<string>("MaturityDate", "541")
static member PutOrCall = FixField<int>("PutOrCall", "201", fun i -> i = 0 || i = 1)
static member StrikePrice = FixField<decimal>("StrikePrice", "202")
static member UnitOfMeasure = FixField<string>("UnitOfMeasure", "996", fun (str : string) -> str.Length <= 30)
static member UnitOfMeasureCurrency = FixField<string>("1UnitOfMe1asureCurrency", "1716", fun (str : string) -> str.Length <= 3)
static member UnitOfMeasureQty = FixField<decimal>("UnitOfMeasureQty", "1147")
static member NoUnderlyings = FixField<int>("NoUnderlyings", "711")
static member UnderlyingSymbol = FixField<string>("UnderlyingSymbol", "311", fun (str : string) -> str.Length <= 6)
static member UnderlyingMaturityMonthYear = FixField<string>("UnderlyingMaturityMonthYear", "313")
static member UnderlyingSecurityType = FixField<string>("UnderlyingSecurityType", "310", fun(str : string) -> str.Length <= 9)
static member UnderlyingSecurityExchange = FixField<string>("UnderlyingSecurityExchange", "308", fun(str : string) -> str.Length <= 4)
static member MDEntryPx = FixField<decimal>("MDEntryPx", "270")
static member MDEntrySize = FixField<decimal>("MDEntryPx", "271")
static member MDEntryDate = FixField<string>("MDEntryDate", "272")
static member MDEntryTime = FixField<string>("MDEntryTime", "273")
static member PriceType = FixField<int>("PriceType", "423", fun i -> i = 2)
static member TrdType = FixField<int>("TrdType", "828", fun i -> i = 1 || i = 2 || i = 11 || i = 12)
//public static FixField<int> NoPartyIDs = new FixField<int>("NoPartyIDs", "453")
static member PartyID = FixField<string>("PartyID", "448", fun (str : string) -> str.Length <= 3)
type IFixFieldValue =
abstract FieldName : string
abstract FieldId : string
abstract Value : string
type FixFieldValue<'a>(field : FixField<'a>, value : 'a) =
interface IFixFieldValue with
member self.FieldName = field.FieldName
member self.FieldId = field.FieldId
member self.Value = value.ToString()
member self.Field = field
member self.Value = value
type FixField<'a> with
member self.CreateValue (value : 'a) = FixFieldValue(self, value) :> IFixFieldValue
namespace TibcoMessagePoster.Model
open System
type FixMessagesDefaultValues =
static member CreateMessage productCode maturityMonthYear price quantity =
[|
FixHeaderFields.ApplVerId.CreateValue("9")
FixField<string>("", "9").CreateValue("234")
FixHeaderFields.MsgType.CreateValue("X")
FixHeaderFields.SenderCompId.CreateValue("CME")
FixHeaderFields.MsgSeqNum.CreateValue("0")
FixHeaderFields.SendingTime.CreateValue(DateTime.Now.ToString("yyyyMMddhhmmssfff"))
FixHeaderFields.SenderCompId.CreateValue("-")
FixField<string>("", "107").CreateValue(productCode)
FixFieldsBlockTrade.NoMDEntries.CreateValue("1")
FixFieldsBlockTrade.MDEntryType.CreateValue('T')
FixFieldsBlockTrade.Symbol.CreateValue(productCode)
FixFieldsBlockTrade.TradeDate.CreateValue(DateTime.Now.ToString("yyyyMMdd"))
FixFieldsBlockTrade.RptSeq.CreateValue(57)
FixFieldsBlockTrade.SecurityType.CreateValue("FUT")
FixFieldsBlockTrade.MaturityMonthYear.CreateValue(maturityMonthYear)
FixFieldsBlockTrade.SecurityExchange.CreateValue("XNYM")
FixFieldsBlockTrade.MDEntryPx.CreateValue(price)
FixFieldsBlockTrade.MDEntrySize.CreateValue(quantity)
FixFieldsBlockTrade.MDEntryDate.CreateValue(DateTime.Now.ToString("yyyyMMdd"))
FixFieldsBlockTrade.MDEntryTime.CreateValue(DateTime.Now.ToString("102200000"))
FixFieldsBlockTrade.MDUpdateAction.CreateValue('0')
FixFieldsBlockTrade.PriceType.CreateValue(2)
FixFieldsBlockTrade.PartyID.CreateValue("CME")
FixField<string>("", "452").CreateValue("21")
FixFieldsBlockTrade.MaturityDate.CreateValue(maturityMonthYear + "01")
FixFieldsBlockTrade.TrdType.CreateValue(1)
FixFieldsBlockTrade.UnitOfMeasure.CreateValue("BBL")
FixFieldsBlockTrade.UnitOfMeasureQty.CreateValue(1000m)
FixFieldsBlockTrade.SecurityGroup.CreateValue(productCode.Substring(0, 2))
FixField<string>("", "10").CreateValue("076")
|]
@andybrackley
Copy link
Author

Looking at this now I think that the types FixHeaderFields and FixFieldsBlockTrade should be a module and all the static members should be individual types that inherit from FixField, although it should be possible to do that without inheritance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment