gpt4 book ai didi

c# - QuickFix/N 如何最好地处理多个 FIX 版本

转载 作者:行者123 更新时间:2023-11-30 16:08:00 25 4
gpt4 key购买 nike

我连接到几个都使用 FXI4.2 的 API,但现在我想连接到另一个使用自己的 FIX4.4 版本的 API。

我有一个向各种 API 发送订单的路由器应用程序,看来我需要复制我的所有方法(例如 OnMessage()、NewSingleOrder 等)以应对 2 个 FIX 协议(protocol)。

是否有更聪明的方法来避免这种重复?

主持人:我知道这现在有点开放,但一旦我得到一些初步反馈,我会添加一些代码片段。

public void OnMessage(QuickFix.FIX42.MarketDataIncrementalRefresh message, SessionID sessionID)
{
int count = message.NoMDEntries.getValue();
QuickFix.FIX42.MarketDataSnapshotFullRefresh.NoMDEntriesGroup repeatingMDItem = new QuickFix.FIX42.MarketDataSnapshotFullRefresh.NoMDEntriesGroup();

DateTime sourceDT = DateTime.ParseExact(message.Header.GetField(52), "yyyyMMdd-HH:mm:ss.fff", ci);
DateTime dt = TimeZoneInfo.ConvertTimeToUtc(sourceDT, utcZone);
DateTime nowUTC = TimeZoneInfo.ConvertTime(DateTime.UtcNow, utcZone, utcZone);
TimeSpan diffToUK = nowUTC - dt;

for (int i = 1; i <= count; i++)
{

message.GetGroup(i, repeatingMDItem);

String symbol = repeatingMDItem.GetField(55);

int tickBandNoDecPlaces = int.Parse(repeatingMDItem.GetField(5071));
masterForm.MDATA.AddData(symbol, tickBandNoDecPlaces, sourceDT);
}
}

问题:FIX44 会接受所有以前的 FIX 吗?

我怎样才能使它与哪个 FIX 版本无关?

        public void OnMessage(QuickFix.FIX42.MarketDataSnapshotFullRefresh message, SessionID sessionID)
{
OnMessageAgnostic(message, sessionID);
}

public void OnMessage(QuickFix.FIX44.MarketDataSnapshotFullRefresh message, SessionID sessionID)
{
OnMessageAgnostic(message, sessionID);
}

public int FixVersion(QuickFix.Message message)
{
switch (message.GetString(8)) // BeginString
{
case Values.BeginString_FIX42:
return 42;
case Values.BeginString_FIX44:
return 44;
default:
throw new NotSupportedException("This version of FIX is unsupported");
}
}

public void OnMessageAgnostic(QuickFix.Message message, SessionID sessionID)
{

int count;
if (FixVersion(message)==44)
{
count = ((QuickFix.FIX44.MarketDataSnapshotFullRefresh)message).NoMDEntries.getValue();
}
}

最佳答案

问题在于,来自不同版本的 FIX 消息类型除了它们的基类之外没有任何关系 - 在最低级别,所有 FIX 消息都派生自 Message。您需要从消息中获取所需的信息,以与版本无关的方式(尽可能)对其进行打包,然后针对这些与版本无关的数据结构编写代码。

我建议你让 message cracker 为你做初始过滤,如果你可以让它处理的话,然后将消息提供给可以处理特定类型消息的处理程序:

public void OnMessage(QuickFix.FIX42.MarketDataIncrementalRefresh message, SessionID sessionID)
{
this.marketDataIncrementalRefreshHandler.Handle(message);
}

public void OnMessage(QuickFix.FIX44.MarketDataIncrementalRefresh message, SessionID sessionID)
{
this.marketDataIncrementalRefreshHandler.Handle(message);
}

... elsewhere ...

public interface FixMessageHandler
{
void Handle(Message msg);
}

public class MarketDataIncrementalRefreshHandler : FixMessageHandler
{
public void Handle(Message msg)
{
DateTime sourceDT = DateTime.ParseExact(message.Header.GetField(52), "yyyyMMdd-HH:mm:ss.fff", ci);
DateTime dt = TimeZoneInfo.ConvertTimeToUtc(sourceDT, utcZone);
DateTime nowUTC = TimeZoneInfo.ConvertTime(DateTime.UtcNow, utcZone, utcZone);
TimeSpan diffToUK = nowUTC - dt;

var noMDEntriesGroups = this.GetAllNoMDEntries(msg)
foreach (var noMDEntriesGroup in noMDEntriesGroups)
{
masterForm.MDATA.AddData(
noMDEntriesGroup.Symbol,
noMDEntriesGroup.TickBandNoDecPlaces,
sourceDT);
}
}

private IEnumerable<NoMDEntriesGroup> GetAllNoMDEntries(Message msg)
{
switch (message.GetString(8)) // BeginString
{
case Values.BeginString_FIX42:
return this.GetAllNoMDEntries((QuickFix.FIX42.MarketDataSnapshotFullRefresh)msg);
case Values.BeginString_FIX44:
return this.GetAllNoMDEntries((QuickFix.FIX44.MarketDataSnapshotFullRefresh)msg);
default:
throw new NotSupportedException("This version of FIX is unsupported");
}
}

private IEnumerable<NoMDEntriesGroup> GetAllNoMDEntries(QuickFix.FIX42.MarketDataSnapshotFullRefresh msg)
{
int count = message.NoMDEntries.getValue();
QuickFix.FIX42.MarketDataSnapshotFullRefresh.NoMDEntriesGroup repeatingMDItem = new QuickFix.FIX42.MarketDataSnapshotFullRefresh.NoMDEntriesGroup();
for (int i = 1; i <= count; i++)
{
message.GetGroup(i, repeatingMDItem);

yield return new NoMDEntriesGroup
{
Symbol = repeatingMDItem.GetField(55),
TickBandNoDecPlaces = int.Parse(repeatingMDItem.GetField(5071)
};
}
}

private IEnumerable<NoMDEntriesGroup> GetAllNoMDEntries(QuickFix.FIX44.MarketDataSnapshotFullRefresh msg)
{
// Should be practically identical to the above version, with 4.4 subbed for 4.2
}

private class NoMDEntriesGroup
{
public string Symbol { get; set; }
public int TickBandNoDecPlaces { get; set; }
}
}

关于c# - QuickFix/N 如何最好地处理多个 FIX 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29968329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com