예제 #1
0
        public TradingEngine(MarketDataChannel chnnls, TradingSession sess, string companyId, string traderId, string locationId = null)
        {
            senderCompId     = companyId;
            senderTraderId   = traderId;
            senderLocationId = locationId;

            channels = chnnls;
            if (channels != null)
            {
                snapshotConnection    = channels.Connections.Find(x => x.Type == MarketDataChannelConnectionType.Snapshot && x.Feed == "A");
                incrementalConnection = channels.Connections.Find(x => x.Type == MarketDataChannelConnectionType.Incremental && x.Feed == "A");

                snapshotServer    = new FixUdpServer(snapshotConnection);
                incrementalServer = new FixUdpServer(incrementalConnection);
            }
            else
            {
                snapshotServer = new FixUdpServer(new MarketDataChannelConnection()
                {
                    IPAddress = IPAddress.Loopback, Port = 7998
                });
                incrementalServer = new FixUdpServer(new MarketDataChannelConnection()
                {
                    IPAddress = IPAddress.Loopback, Port = 7999
                });
            }

            session          = sess;
            session.Changed += HandleSessionChanged;
        }
예제 #2
0
 public FixUdpServer(MarketDataChannelConnection connection)
 {
     ipEndPoint = new IPEndPoint(connection.IPAddress, connection.Port);
     udpClient  = new UdpClient();
     Console.WriteLine($"{connection.Type} market data udp server ready at {ipEndPoint}");
 }
예제 #3
0
        public static List <MarketDataChannel> Load(string file, bool overwriteWithLoopbackIP = false)
        {
            var xml = XDocument.Load(file);

            var channels = new List <MarketDataChannel>();

            foreach (var channelNode in xml.Root.Descendants("channel"))
            {
                var channel = new MarketDataChannel()
                {
                    Id    = Convert.ToInt32(channelNode.Attribute("id").Value),
                    Label = channelNode.Attribute("label").Value,
                };

                foreach (var productNode in channelNode.Descendants("product"))
                {
                    var product = productNode.Attribute("code").Value;
                    var grp     = productNode.Elements().First().Attribute("code").Value;
                    channel.Products.Add(product);
                }

                foreach (var connectionNode in channelNode.Descendants("connection"))
                {
                    var conn = new MarketDataChannelConnection()
                    {
                        Id       = connectionNode.Attribute("id").Value,
                        Type     = GetType(connectionNode.Descendants("type").First().Attribute("feed-type").Value),
                        Protocol = GetProtocol(connectionNode.Descendants("protocol").First().Value),
                        Port     = Convert.ToInt32(connectionNode.Descendants("port").First().Value),
                        Feed     = connectionNode.Descendants("feed").First().Value
                    };

                    if (connectionNode.Descendants("ip").Any())
                    {
                        if (overwriteWithLoopbackIP)
                        {
                            conn.IPAddress = IPAddress.Loopback;
                        }
                        else
                        {
                            string address = connectionNode.Descendants("ip").First().Value;
                            conn.IPAddress = IPAddress.Parse(address);
                        }
                    }

                    foreach (var hostIPNode in connectionNode.Descendants("host-ip"))
                    {
                        if (overwriteWithLoopbackIP)
                        {
                            if (!conn.HostIPAddresses.Contains(IPAddress.Loopback))
                            {
                                conn.HostIPAddresses.Add(IPAddress.Loopback);
                            }
                        }
                        else
                        {
                            string address = hostIPNode.Value;
                            conn.HostIPAddresses.Add(IPAddress.Parse(address));
                        }
                    }

                    channel.Connections.Add(conn);
                }

                channels.Add(channel);
            }

            return(channels);
        }