Example #1
0
        private static void Main()
        {
            const string    ADDRESS       = "demo.dxfeed.com:7300";
            const string    SYMBOL        = "IBM";
            const string    SOURCE        = "NTV";
            const string    RAW_FILE_NAME = "test.raw";
            const EventType EVENT_TYPE    = EventType.Order;

            Console.WriteLine("Connecting to {0} for Order#{1} snapshot on {2}...", ADDRESS, SOURCE, SYMBOL);

            try {
                NativeTools.InitializeLogging("dxf_read_write_raw_data_sample.log", true, true);
                Console.WriteLine("Writing to raw file");
                using (var con = new NativeConnection(ADDRESS, DisconnectHandler)) {
                    con.WriteRawData(RAW_FILE_NAME);
                    using (var s = con.CreateSubscription(EVENT_TYPE, new EventListener())) {
                        s.AddSource(SOURCE);
                        s.AddSymbol(SYMBOL);

                        Console.WriteLine("Receiving events for 15 seconds");
                        Thread.Sleep(15000);
                    }
                }

                Console.WriteLine("Reading from raw file");
                using (var con = new NativeConnection(RAW_FILE_NAME, DisconnectHandler)) {
                    using (var s = con.CreateSubscription(EVENT_TYPE, new EventListener())) {
                        s.AddSource(SOURCE);
                        s.AddSymbol(SYMBOL);

                        Thread.Sleep(2000);
                        Console.WriteLine("Press enter to stop");
                        Console.ReadLine();
                    }
                }
            } catch (DxException dxException) {
                Console.WriteLine($"Native exception occured: {dxException.Message}");
            } catch (Exception exc) {
                Console.WriteLine($"Exception occured: {exc.Message}");
            }
        }