我试图从QuickFix44.MarketDataSnapshotFullRefresh消息(类型W)修改价格值。
我已成功将原始FIX消息转换为字符串类型。但有什么办法可以在修改值后将其恢复为字符串的FIX消息?
这是我到目前为止所做的代码:
public void alterMarkup(QuickFix44.MarketDataSnapshotFullRefresh snapshot)
{
// convert FIXMessage to string type
String message = System.Convert.ToString(snapshot);
// retrieve the value to modify
String a = message.Substring(message.LastIndexOf("269=0") + 10);
String bid_value = a.Substring(0, a.IndexOf("\u0001"));
String b = message.Substring(message.LastIndexOf("269=1") + 10);
String ask_value = b.Substring(0, b.IndexOf("\u0001"));
// alter the price
Decimal deci_bid = System.Convert.ToDecimal(bid_value) + 0.1m;
// NoMDEntries Group
QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries group = new QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries();
group.setField(new QuickFix.MDEntryType(System.Convert.ToChar(QuickFix.MDEntryType.BID)));
group.setField(new QuickFix.MDEntryPx(System.Convert.ToDouble(deci_bid)));
group.setField(new QuickFix.MDEntrySize(0));
group.setField(new QuickFix.MDEntryDate());
group.setField(new QuickFix.MDEntryTime(DateTime.UtcNow));
group.setField(new QuickFix.TradingSessionID());
group.setField(new QuickFix.TradingSessionSubID());
group.setField(new QuickFix.QuoteCondition(System.Convert.ToString(QuickFix.QuoteCondition.OPEN_ACTIVE)));
group.setField(new QuickFix.MDEntryOriginator());
group.setField(new QuickFix.QuoteEntryID());
group.setField(new QuickFix.QuoteType(QuickFix.QuoteType.TRADEABLE));
Console.WriteLine(snapshot);
snapshot.replaceGroup(System.Convert.ToUInt32(deci_bid), group.field(), group);
// print out from second time to compare
Console.WriteLine(snapshot);
}
我打印出消息并在https://fixparser.targetcompid.com/翻译。
从图像中,我们可以注意到必须逐个插入字段的值。如果没有,它只会在那里显示null。
附:有没有办法只更改MDEntryPx(对于BID和OFFER)而不是更改整个组。
我是QuickFIX的新手。任何帮助将不胜感激。
为什么要尝试将其转换为字符串并返回?
这些都是设置字段值的正确方法:
snapshot.MDEntryType = new MDEntryType('0');
snapshot.MDEntryType = new MDEntryType(MDEntryType.BID); //enum instead of char
snapshot.Set(new MDEntryType('0')) //can also use enum
这都是在the documentation。