Exemple #1
0
    // Writes Chunk c's state metadata into given buffer
    // and returns the amount of bytes written
    public static int CompressMetadataState(Chunk c, byte[] buffer, int targetPos = 0)
    {
        List <ushort> palleteList = Compression.GetPallete(Pallete.METADATA);
        int           bytes;

        NativeArray <int> writtenBytes = new NativeArray <int>(new int[1] {
            0
        }, Allocator.TempJob);
        NativeArray <ushort> chunkData    = NativeTools.CopyToNative(c.metadata.GetStateData());
        NativeArray <byte>   buff         = NativeTools.CopyToNative(buffer);
        NativeArray <ushort> palleteArray = NativeTools.CopyToNative(palleteList.ToArray());

        CompressionJob cmdJob = new CompressionJob {
            chunkData    = chunkData,
            buffer       = buff,
            palleteArray = palleteArray,
            writtenBytes = writtenBytes
        };

        JobHandle handle = cmdJob.Schedule();

        handle.Complete();

        NativeArray <byte> .Copy(buff, 0, buffer, targetPos, writtenBytes[0]);

        bytes = writtenBytes[0];

        chunkData.Dispose();
        palleteArray.Dispose();
        buff.Dispose();
        writtenBytes.Dispose();

        return(bytes);
    }
Exemple #2
0
    // Builds Chunk's State Metadata using Decompression algorithm
    public static void DecompressMetadataStateClient(Chunk c, byte[] buffer, int initialPos)
    {
        // Preparation Variables
        List <ushort> palleteList = Compression.GetPallete(Pallete.METADATA);

        NativeArray <ushort> data     = new NativeArray <ushort>(Chunk.chunkWidth * Chunk.chunkWidth * Chunk.chunkDepth, Allocator.TempJob);
        NativeArray <byte>   readData = NativeTools.CopyToNative(buffer);
        NativeArray <ushort> pallete  = NativeTools.CopyToNative(palleteList.ToArray());

        DecompressJob dbJob = new DecompressJob {
            data       = data,
            readData   = readData,
            pallete    = pallete,
            initialPos = initialPos
        };
        JobHandle job = dbJob.Schedule();

        job.Complete();

        c.metadata.SetStateData(data.ToArray());

        data.Dispose();
        readData.Dispose();
        pallete.Dispose();
    }
Exemple #3
0
    // Builds Chunk's VoxelData using Decompression algorithm
    public static void DecompressBlocks(Chunk c, byte[] buffer)
    {
        // Preparation Variables
        Pallete       p           = Compression.BiomeToPallete(c.biomeName);
        List <ushort> palleteList = Compression.GetPallete(p);

        NativeArray <ushort> data     = new NativeArray <ushort>(Chunk.chunkWidth * Chunk.chunkWidth * Chunk.chunkDepth, Allocator.TempJob);
        NativeArray <byte>   readData = NativeTools.CopyToNative(buffer);
        NativeArray <ushort> pallete  = NativeTools.CopyToNative(palleteList.ToArray());

        DecompressJob dbJob = new DecompressJob {
            data       = data,
            readData   = readData,
            pallete    = pallete,
            initialPos = 0
        };
        JobHandle job = dbJob.Schedule();

        job.Complete();

        c.data.SetData(data.ToArray());


        data.Dispose();
        readData.Dispose();
        pallete.Dispose();
    }
Exemple #4
0
        private static void Main(string[] args)
        {
            if (args.Length < 2 || args.Length > 5)
            {
                Console.WriteLine(
                    "Usage: dxf_regional_book_sample <host:port> <symbol> [-T <token>] [-p]\n" +
                    "where\n" +
                    "    host:port  - The address of dxfeed server (demo.dxfeed.com:7300)\n" +
                    "    symbol     - IBM\n" +
                    "    -T <token> - The authorization token\n" +
                    "    -p         - Enables the data transfer logging\n\n" +
                    "example: dxf_regional_book_sample demo.dxfeed.com:7300 MSFT\n"
                    );
                return;
            }

            var address             = args[HOST_INDEX];
            var symbol              = args[SYMBOL_INDEX];
            var token               = new InputParam <string>(null);
            var logDataTransferFlag = false;

            for (var i = SYMBOL_INDEX + 1; i < args.Length; i++)
            {
                if (!token.IsSet && i < args.Length - 1 &&
                    TryParseTaggedStringParam("-T", args[i], args[i + 1], token))
                {
                    i++;
                    continue;
                }

                if (logDataTransferFlag == false && args[i].Equals("-p"))
                {
                    logDataTransferFlag = true;
                    i++;
                }
            }

            Console.WriteLine("Connecting to {0} on {1}...", address, symbol);

            try {
                NativeTools.InitializeLogging("dxf_regional_book_sample.log", true, true, logDataTransferFlag);
                using (var con = token.IsSet
                    ? new NativeConnection(address, token.Value, DisconnectHandler)
                    : new NativeConnection(address, DisconnectHandler)) {
                    using (con.CreateRegionalBook(symbol, new RegionalBookListener(), new QuoteListener())) {
                        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);
            }
        }
Exemple #5
0
        private static void Main(string[] args)
        {
            if (args.Length < 1 || args.Length > 5)
            {
                PrintUsage();

                return;
            }

            var address           = args[HOST_INDEX];
            var recordsPrintLimit = new InputParam <int>(DEFAULT_RECORDS_PRINT_LIMIT);
            var token             = new InputParam <string>(null);

            for (var i = HOST_INDEX + 1; i < args.Length; i++)
            {
                if (!recordsPrintLimit.IsSet && i < args.Length - 1 &&
                    TryParseRecordsPrintLimitParam(args[i], args[i + 1], recordsPrintLimit))
                {
                    i++;

                    continue;
                }

                if (!token.IsSet && i < args.Length - 1 &&
                    TryParseTaggedStringParam("-T", args[i], args[i + 1], token))
                {
                    i++;
                }
            }

            Console.WriteLine($"Connecting to {address} for Order View");

            try {
                NativeTools.InitializeLogging("dxf_order_view_sample.log", true, true);
                using (var con = token.IsSet
                    ? new NativeConnection(address, token.Value, DisconnectHandler)
                    : new NativeConnection(address, DisconnectHandler)) {
                    using (var sub =
                               con.CreateOrderViewSubscription(new OrderViewEventListener(recordsPrintLimit.Value))) {
                        sub.SetSource("NTV", "DEA", "DEX");
                        sub.SetSymbols("AAPL", "GOOG", "IBM", "F");

                        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}");
            }
        }
Exemple #6
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}");
            }
        }
Exemple #7
0
    // Writes Chunk c's data using a Pallete's compression into given buffer
    // and returns the amount of bytes written
    public static int CompressBlocks(Chunk c, byte[] buffer, int targetPos = 0)
    {
        int           bytes;
        Pallete       p           = Compression.BiomeToPallete(c.biomeName);
        List <ushort> palleteList = Compression.GetPallete(p);


        NativeArray <int> writtenBytes = new NativeArray <int>(new int[1] {
            0
        }, Allocator.TempJob);
        NativeArray <ushort> chunkData    = NativeTools.CopyToNative(c.data.GetData());
        NativeArray <byte>   buff         = NativeTools.CopyToNative(buffer);
        NativeArray <ushort> palleteArray = NativeTools.CopyToNative(palleteList.ToArray());

        CompressionJob cbJob = new CompressionJob {
            chunkData    = chunkData,
            buffer       = buff,
            palleteArray = palleteArray,
            writtenBytes = writtenBytes
        };

        JobHandle handle = cbJob.Schedule();

        handle.Complete();

        NativeArray <byte> .Copy(buff, 0, buffer, targetPos, writtenBytes[0]);

        bytes = writtenBytes[0];

        chunkData.Dispose();
        palleteArray.Dispose();
        buff.Dispose();
        writtenBytes.Dispose();

        return(bytes);
    }
Exemple #8
0
        private static void Main(string[] args)
        {
            if (args.Length < 3 || args.Length > 9)
            {
                ShowUsage();

                return;
            }

            var address             = args[HostIndex];
            var symbol              = args[SymbolIndex];
            var source              = new InputParam <string>(OrderSource.NTV.Name);
            var dateTime            = new InputParam <DateTime?>(null);
            var recordsPrintLimit   = new InputParam <int>(DefaultRecordsPrintLimit);
            var token               = new InputParam <string>(null);
            var logDataTransferFlag = false;

            for (var i = SymbolIndex + 1; i < args.Length; i++)
            {
                if (!dateTime.IsSet && TryParseDateTimeParam(args[i], dateTime))
                {
                    continue;
                }

                if (!recordsPrintLimit.IsSet && i < args.Length - 1 &&
                    TryParseRecordsPrintLimitParam(args[i], args[i + 1], recordsPrintLimit))
                {
                    i++;

                    continue;
                }

                if (!token.IsSet && i < args.Length - 1 &&
                    TryParseTaggedStringParam("-T", args[i], args[i + 1], token))
                {
                    i++;

                    continue;
                }

                if (logDataTransferFlag == false && args[i].Equals("-p"))
                {
                    logDataTransferFlag = true;
                    i++;

                    continue;
                }

                if (!source.IsSet)
                {
                    source.Value = args[i];
                }
            }

            Console.WriteLine(
                $"Connecting to {address} for [Order#{source.Value} (book)] on [{symbol}] ...");

            using (var con = token.IsSet
                ? new NativeConnection(address, token.Value, DisconnectHandler, ConnectionStatusChangeHandler)
                : new NativeConnection(address, DisconnectHandler, ConnectionStatusChangeHandler))
            {
                IDxSubscription s = null;
                try
                {
                    NativeTools.InitializeLogging("dxf_simple_order_book_sample.log", true, true, logDataTransferFlag);
                    s = con.CreateSnapshotSubscription(EventType.Order, dateTime.Value, new OrderListener(recordsPrintLimit.Value));
                    s.SetSource(source.Value);
                    s.AddSymbols(symbol);

                    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}");
                }
                finally
                {
                    s?.Dispose();
                }
            }
        }
Exemple #9
0
        private static void Main(string[] args)
        {
            if (args.Length < 3 || args.Length > 9)
            {
                Console.WriteLine(
                    "Usage: dxf_snapshot_sample <host:port> <event> <symbol> [<source>] [-l <records_print_limit>] [-T <token>] [-p]\n" +
                    "where\n" +
                    "    host:port - address of dxfeed server (demo.dxfeed.com:7300)\n" +
                    "    event     - snapshot event Order, Candle, TimeAndSale, SpreadOrder,\n" +
                    "                Greeks, Series for MarketMaker see source parameter\n" +
                    "    symbol    - symbol string, it is allowed to use only one symbol\n" +
                    "                a) event symbol: IBM, MSFT, ...\n" +
                    "                b) candle symbol attribute: XBT/USD{=d},\n" +
                    "                   AAPL{=d,price=mark}, ...\n" +
                    "    source    - used only for Order or MarketMaker subscription,\n" +
                    "                also it is allowed to use only one source\n" +
                    "                a) source for Order, e.g. NTV, BYX, BZX, DEA, ISE, \n" +
                    "                   DEX, IST\n" +
                    "                b) source for MarketMaker, one of following: AGGREGATE_ASK\n" +
                    "                   or AGGREGATE_BID (default value for Order snapshots)\n" +
                    "                If source is not specified MarketMaker snapshot will be\n" +
                    "                subscribed by default.\n\n" +
                    $"    -l <records_print_limit> - The number of displayed records (0 - unlimited, default: {DEFAULT_RECORDS_PRINT_LIMIT})\n" +
                    "    -T <token>               - The authorization token\n" +
                    "    -p                       - Enables the data transfer logging\n\n" +
                    "order example: dxf_snapshot_sample demo.dxfeed.com:7300 Order AAPL NTV\n" +
                    "market maker example:\n" +
                    "    dxf_snapshot_sample demo.dxfeed.com:7300 Order AAPL AGGREGATE_BID\n" +
                    "or just:\n" +
                    "    dxf_snapshot_sample demo.dxfeed.com:7300 Order AAPL\n" +
                    "candle example: dxf_snapshot_sample demo.dxfeed.com:7300 Candle XBT/USD{=d}"
                    );
                return;
            }

            var address = args[HOST_INDEX];
            var symbol  = args[SYMBOL_INDEX];

            EventType eventType;

            if (!Enum.TryParse(args[EVENT_INDEX], true, out eventType) ||
                eventType != EventType.Order && eventType != EventType.Candle &&
                eventType != EventType.TimeAndSale && eventType != EventType.SpreadOrder &&
                eventType != EventType.Greeks && eventType != EventType.Series)
            {
                Console.WriteLine($"Unsupported event type: {args[EVENT_INDEX]}");
                return;
            }

            var source              = new InputParam <string>(OrderSource.AGGREGATE_BID);
            var recordsPrintLimit   = new InputParam <int>(DEFAULT_RECORDS_PRINT_LIMIT);
            var token               = new InputParam <string>(null);
            var logDataTransferFlag = false;

            for (var i = SYMBOL_INDEX + 1; i < args.Length; i++)
            {
                if (!recordsPrintLimit.IsSet && i < args.Length - 1 &&
                    TryParseRecordsPrintLimitParam(args[i], args[i + 1], recordsPrintLimit))
                {
                    i++;

                    continue;
                }

                if (!token.IsSet && i < args.Length - 1 &&
                    TryParseTaggedStringParam("-T", args[i], args[i + 1], token))
                {
                    i++;

                    continue;
                }

                if (logDataTransferFlag == false && args[i].Equals("-p"))
                {
                    logDataTransferFlag = true;
                    i++;

                    continue;
                }

                if (!source.IsSet)
                {
                    TryParseStringParam(args[i], source);
                }
            }

            if (eventType == EventType.Order)
            {
                if (source.Value.Equals(OrderSource.AGGREGATE_BID) || source.Value.Equals(OrderSource.AGGREGATE_ASK))
                {
                    Console.WriteLine("Connecting to {0} for MarketMaker snapshot on {1}...", address, symbol);
                }
                else
                {
                    Console.WriteLine("Connecting to {0} for Order#{1} snapshot on {2}...", address, source.Value,
                                      symbol);
                }
            }
            else
            {
                Console.WriteLine("Connecting to {0} for {1} snapshot on {2}...", address, eventType, symbol);
            }

            try {
                NativeTools.InitializeLogging("dxf_snapshot_sample.log", true, true, logDataTransferFlag);
                using (var con = token.IsSet
                    ? new NativeConnection(address, token.Value, DisconnectHandler)
                    : new NativeConnection(address, DisconnectHandler)) {
                    using (var s = con.CreateSnapshotSubscription(eventType, DEFAULT_TIME,
                                                                  new SnapshotListener(recordsPrintLimit.Value))) {
                        switch (eventType)
                        {
                        case EventType.Order:
                            s.AddSource(source.Value);
                            s.AddSymbol(symbol);
                            break;

                        case EventType.Candle:
                            s.AddSymbol(CandleSymbol.ValueOf(symbol));
                            break;

                        default:
                            s.AddSymbol(symbol);
                            break;
                        }

                        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}");
            }
        }
Exemple #10
0
        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine(
                    "Usage: dxf_ipf_connect_sample <ipf_host> <user> <password> <host:port> <events>\n" +
                    "or:    dxf_ipf_connect_sample <file> <host:port> <event>\n" +
                    "where\n" +
                    "    ipf_host  - The valid ipf host to download instruments (https://tools.dxfeed.com/ipf)\n" +
                    "    user      - The user name to host access\n" +
                    "    password  - The user password to host access\n" +
                    "    host:port - The address of dxfeed server (demo.dxfeed.com:7300)\n" +
                    "    events    - Any of the {Profile,Quote,Trade,TimeAndSale,Summary,\n" +
                    "                TradeETH,Candle,Greeks,TheoPrice,Underlying,Series,\n" +
                    "                Configuration}\n" +
                    "    file      - The name of file or archive (.gz or .zip) contains instrument profiles\n\n" +
                    "example: dxf_ipf_connect_sample https://tools.dxfeed.com/ipf?TYPE=STOCK demo demo demo.dxfeed.com:7300 Quote,Trade\n" +
                    "or:      dxf_ipf_connect_sample https://demo:[email protected]/ipf?TYPE=STOCK demo.dxfeed.com:7300 Quote,Trade\n" +
                    "or:      dxf_ipf_connect_sample profiles.zip demo.dxfeed.com:7300 Quote,Trade\n"
                    );
                return;
            }

            var           path     = args[0];
            var           user     = string.Empty;
            var           password = string.Empty;
            string        dxFeedAddress;
            EventType     events;
            List <string> symbols;

            try {
                var reader = new InstrumentProfileReader();
                IList <InstrumentProfile> profiles;
                var dxFeedAddressParamIndex = 1;

                if (IsFilePath(path))
                {
                    //Read profiles from local file system
                    using (var inputStream = new FileStream(path, FileMode.Open)) {
                        profiles = reader.Read(inputStream, path);
                    }
                }
                else
                {
                    if (args.Length == 5)
                    {
                        user     = args[1];
                        password = args[2];
                        dxFeedAddressParamIndex += 2;
                    }

                    //Read profiles from server
                    profiles = reader.ReadFromFile(path, user, password);
                }

                dxFeedAddress = args[dxFeedAddressParamIndex];
                var eventsString = args[dxFeedAddressParamIndex + 1];

                if (!Enum.TryParse(eventsString, true, out events))
                {
                    Console.WriteLine($"Unsupported event type: {eventsString}");
                    return;
                }


                if (profiles.Count == 0)
                {
                    Console.WriteLine("There are no profiles");

                    return;
                }

                Console.WriteLine("Profiles from '{0}' count: {1}", path, profiles.Count);

                symbols = profiles.Select(profile => profile.GetSymbol()).ToList();

                Console.WriteLine(value: $"Symbols: {string.Join(", ", symbols.Take(42).ToArray())}...");
            } catch (Exception exc) {
                Console.WriteLine($"Exception occured: {exc}");

                return;
            }

            Console.WriteLine($"Connecting to {dxFeedAddress} for [{events} on [{string.Join(", ", symbols.Take(42).ToArray())}...] ...");

            NativeTools.InitializeLogging("dxf_ipf_connect_sample.log", true, true);

            using (var connection = new NativeConnection(dxFeedAddress, DisconnectHandler, ConnectionStatusChangeHandler)) {
                IDxSubscription subscription = null;
                try {
                    subscription = connection.CreateSubscription(events, new EventPrinter());

                    if (events == EventType.Candle)
                    {
                        subscription.AddSymbols(symbols.ConvertAll(CandleSymbol.ValueOf).ToArray());
                    }
                    else
                    {
                        subscription.AddSymbols(symbols.ToArray());
                    }

                    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}");
                } finally {
                    subscription?.Dispose();
                }
            }
        }
Exemple #11
0
        private static void Main(string[] args)
        {
            if (args.Length < 3 || args.Length > 7)
            {
                Console.WriteLine(
                    "Usage: dxf_events_sample <host:port> <event> <symbol> [<date>] [-T <token>] [-p]\n" +
                    "where\n" +
                    "    host:port  - The address of dxfeed server (demo.dxfeed.com:7300)\n" +
                    "    event      - Any of the {Profile,Order,Quote,Trade,TimeAndSale,Summary,\n" +
                    "                 TradeETH,SpreadOrder,Greeks,TheoPrice,Underlying,Series,\n" +
                    "                 Configuration}\n" +
                    "    symbol     - IBM, MSFT, ...\n\n" +
                    "    date       - The date of time series event in the format YYYY-MM-DD (optional)\n" +
                    "    -T <token> - The authorization token\n" +
                    "    -p         - Enables the data transfer logging\n\n" +
                    "example: dxf_events_sample demo.dxfeed.com:7300 quote,trade MSFT.TEST,IBM.TEST\n" +
                    "or: dxf_events_sample demo.dxfeed.com:7300 TimeAndSale MSFT,IBM 2016-10-10\n"
                    );
                return;
            }

            var address = args[HOST_INDEX];

            EventType events;

            if (!Enum.TryParse(args[EVENT_INDEX], true, out events))
            {
                Console.WriteLine($"Unsupported event type: {args[EVENT_INDEX]}");
                return;
            }

            var symbols             = args[SYMBOL_INDEX].Split(',');
            var dateTime            = new InputParam <DateTime?>(null);
            var token               = new InputParam <string>(null);
            var logDataTransferFlag = false;

            for (var i = SYMBOL_INDEX + 1; i < args.Length; i++)
            {
                if (!dateTime.IsSet && TryParseDateTimeParam(args[i], dateTime))
                {
                    continue;
                }

                if (!token.IsSet && i < args.Length - 1 &&
                    TryParseTaggedStringParam("-T", args[i], args[i + 1], token))
                {
                    i++;
                    continue;
                }

                if (logDataTransferFlag == false && args[i].Equals("-p"))
                {
                    logDataTransferFlag = true;
                    i++;
                }
            }

            Console.WriteLine($"Connecting to {address} for [{events}] on [{string.Join(", ", symbols)}] ...");

            try {
                NativeTools.InitializeLogging("dxf_events_sample.log", true, true, logDataTransferFlag);
                using (var con = token.IsSet
                    ? new NativeConnection(address, token.Value, DisconnectHandler)
                    : new NativeConnection(address, DisconnectHandler)) {
                    using (var s = con.CreateSubscription(events, dateTime.Value, new EventListener())) {
                        s.AddSymbols(symbols);

                        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}");
            }
        }
Exemple #12
0
        static void Main(string[] args)
        {
            if (args.Length < 3 || args.Length > 13)
            {
                Console.WriteLine(
                    "Usage: dxf_client <host:port> <event> <symbol> [<date>] [<source>] [snapshot] [-l <records_print_limit>] [-T <token>] [-s <subscr_data>] [-p]\n" +
                    "where\n" +
                    "    host:port - The address of dxfeed server (demo.dxfeed.com:7300)\n" +
                    "    event     - Any of the {Profile,Order,Quote,Trade,TimeAndSale,Summary,\n" +
                    "                TradeETH,SpreadOrder,Candle,Greeks,TheoPrice,Underlying,Series,\n" +
                    "                Configuration}\n" +
                    "    symbol    - a) IBM, MSFT, ... ; * - all symbols\n" +
                    "                b) if it is Candle event you can specify candle symbol\n" +
                    "                   attribute by string, for example: XBT/USD{=d}\n" +
                    "    date      - The date of time series event in the format YYYY-MM-DD (optional)\n" +
                    "    source    - Used only for Order or MarketMaker subscription:\n" +
                    "                a) OPTIONAL source for order events is any combination of:\n" +
                    "                   NTV,NFX,ESPD,XNFI,ICE,ISE,DEA,DEX,BYX,BZX,BATE,CHIX,CEUX,\n" +
                    "                   BXTR,IST,BI20,ABE,FAIR,GLBX,ERIS,XEUR,CFE,C2OX,SMFE...;\n" +
                    "                b) source for Order snapshot can be one of following: NTV,NFX,\n" +
                    "                   ESPD,XNFI,ICE,ISE,DEA,DEX,BYX,BZX,BATE,CHIX,CEUX,BXTR,IST,BI20,\n" +
                    "                   ABE,FAIR,GLBX,ERIS,XEUR,CFE,C2OX,SMFE...\n" +
                    "                c) source for MarketMaker snapshot, can be COMPOSITE_ASK\n" +
                    "                   or COMPOSITE_BID\n" +
                    "    snapshot  - Use keyword 'snapshot' for create snapshot subscription,\n" +
                    "                otherwise leave empty\n" +
                    $"    -l <records_print_limit> - The number of displayed records (0 - unlimited, default: {DEFAULT_RECORDS_PRINT_LIMIT})\n" +
                    "    -T <token>               - The authorization token\n\n" +
                    "    -s <subscr_data>         - The subscription data: ticker|TICKER, stream|STREAM, history|HISTORY\n" +
                    "    -p                       - Enables the data transfer logging\n\n" +
                    "examples:\n" +
                    "  events: dxf_client demo.dxfeed.com:7300 Quote,Trade MSFT.TEST,IBM.TEST\n" +
                    "  events: dxf_client demo.dxfeed.com:7300 Quote,Trade MSFT.TEST,IBM.TEST -s stream\n" +
                    "  order: dxf_client demo.dxfeed.com:7300 Order MSFT.TEST,IBM.TEST NTV,IST\n" +
                    "  candle: dxf_client demo.dxfeed.com:7300 Candle XBT/USD{=d} 2016-10-10\n" +
                    "  underlying: dxf_client demo.dxfeed.com:7300 Underlyingn AAPL\n" +
                    "  series: dxf_client demo.dxfeed.com:7300 Series AAPL\n" +
                    "  order snapshot: dxf_client demo.dxfeed.com:7300 Order AAPL NTV snapshot\n" +
                    "  order snapshot: dxf_client demo.dxfeed.com:7300 Order AAPL NTV snapshot -l 0\n" +
                    "  market maker snapshot: dxf_client demo.dxfeed.com:7300 Order AAPL COMPOSITE_BID snapshot\n" +
                    "  market maker snapshot: dxf_client demo.dxfeed.com:7300 Order AAPL COMPOSITE_BID snapshot -l 3\n" +
                    "  candle snapshot: dxf_client demo.dxfeed.com:7300 Candle XBT/USD{=d} 2016-10-10 snapshot\n" +
                    "  candle snapshot: dxf_client demo.dxfeed.com:7300 Candle XBT/USD{=d} 2016-10-10 snapshot -l 10\n" +
                    "  candle snapshot: dxf_client demo.dxfeed.com:7300 Candle XBT/USD{=d,pl=0.5} 2016-10-10 snapshot -l 10\n"
                    );
                return;
            }

            var address = args[HOST_INDEX];

            EventType events;

            if (!Enum.TryParse(args[EVENT_INDEX], true, out events))
            {
                Console.WriteLine($"Unsupported event type: {args[EVENT_INDEX]}");
                return;
            }

            var symbols             = args[SYMBOL_INDEX];
            var sources             = new InputParam <string[]>(new string[] { });
            var isSnapshot          = new InputParam <bool>(false);
            var dateTime            = new InputParam <DateTime?>(null);
            var recordsPrintLimit   = new InputParam <int>(DEFAULT_RECORDS_PRINT_LIMIT);
            var token               = new InputParam <string>(null);
            var subscriptionData    = new InputParam <EventSubscriptionFlag>(EventSubscriptionFlag.Default);
            var logDataTransferFlag = false;

            for (var i = SYMBOL_INDEX + 1; i < args.Length; i++)
            {
                if (!dateTime.IsSet && TryParseDateTimeParam(args[i], dateTime))
                {
                    continue;
                }
                if (!isSnapshot.IsSet && TryParseSnapshotParam(args[i], isSnapshot))
                {
                    continue;
                }
                if (!recordsPrintLimit.IsSet && i < args.Length - 1 &&
                    TryParseRecordsPrintLimitParam(args[i], args[i + 1], recordsPrintLimit))
                {
                    i++;

                    continue;
                }

                if (!token.IsSet && i < args.Length - 1 &&
                    TryParseTaggedStringParam("-T", args[i], args[i + 1], token))
                {
                    i++;

                    continue;
                }

                if (!subscriptionData.IsSet && i < args.Length - 1 &&
                    TryParseEventSubscriptionFlagParam("-s", args[i], args[i + 1], subscriptionData))
                {
                    i++;

                    continue;
                }

                if (logDataTransferFlag == false && args[i].Equals("-p"))
                {
                    logDataTransferFlag = true;
                    i++;

                    continue;
                }

                if (!sources.IsSet)
                {
                    TryParseSourcesParam(args[i], sources);
                }
            }

            var snapshotString   = isSnapshot.Value ? " snapshot" : string.Empty;
            var timeSeriesString = dateTime.IsSet && !isSnapshot.Value ? " time-series" : string.Empty;

            Console.WriteLine(
                $"Connecting to {address} for [{events}{snapshotString}]{timeSeriesString} on [{symbols}] ...");

            NativeTools.InitializeLogging("dxf_client.log", true, true, logDataTransferFlag);

            var listener = new EventPrinter();

            using (var con = token.IsSet
                ? new NativeConnection(address, token.Value, DisconnectHandler, ConnectionStatusChangeHandler)
                : new NativeConnection(address, DisconnectHandler, ConnectionStatusChangeHandler)) {
                IDxSubscription s = null;
                try {
                    if (isSnapshot.Value)
                    {
                        s = con.CreateSnapshotSubscription(events, dateTime.Value,
                                                           new SnapshotPrinter(recordsPrintLimit.Value));
                    }
                    else if (dateTime.IsSet)
                    {
                        s = subscriptionData.IsSet
                            ? con.CreateSubscription(events, dateTime.Value, subscriptionData.Value, listener)
                            : con.CreateSubscription(events, dateTime.Value, listener);
                    }
                    else
                    {
                        s = subscriptionData.IsSet
                            ? con.CreateSubscription(events, subscriptionData.Value, listener)
                            : con.CreateSubscription(events, listener);
                    }

                    if (events.HasFlag(EventType.Order) && sources.Value.Length > 0)
                    {
                        s.SetSource(sources.Value);
                    }

                    if (events == EventType.Candle)
                    {
                        var candleSymbol = CandleSymbol.ValueOf(symbols);
                        s.AddSymbol(candleSymbol);
                    }
                    else
                    {
                        s.AddSymbols(symbols.Split(','));
                    }

                    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}");
                } finally {
                    s?.Dispose();
                }
            }
        }
Exemple #13
0
        private static void Main(string[] args)
        {
            if (args.Length < 1 || args.Length > 3)
            {
                Console.WriteLine(
                    "Usage: dxf_order_view_xcheck <host:port> [-T <token>]\n" +
                    "where\n" +
                    "    host:port  - The address of dxfeed server (demo.dxfeed.com:7300)\n" +
                    "    -T <token> - The authorization token\n\n" +
                    "example: dxf_order_view_xcheck demo.dxfeed.com:7300\n"
                    );

                return;
            }

            var address = args[HOST_INDEX];
            var token   = new InputParam <string>(null);

            for (var i = HOST_INDEX + 1; i < args.Length; i++)
            {
                if (!token.IsSet && i < args.Length - 1 &&
                    TryParseTaggedStringParam("-T", args[i], args[i + 1], token))
                {
                    i++;
                }
            }

            Console.WriteLine("Connecting to {0} for Order View", address);

            try {
                NativeTools.InitializeLogging("dxf_order_view_xcheck.log", true, true);
                using (var con = token.IsSet
                    ? new NativeConnection(address, token.Value, DisconnectHandler)
                    : new NativeConnection(address, DisconnectHandler)) {
                    var l    = new OrderViewEventListener();
                    var subs = new List <IDxSubscription>();

                    /*
                     * We CAN NOT use one instance OrderViewSubscription here.
                     * If OrderViewSubscription is configured with multiple sources,
                     * it MIXES sources to one "view" and this "view" is NOT
                     * transactional-safe and atomic anymore.
                     * You could see "crosses" between orders with different sources
                     * in the mixed view, it is normal. Atomicity is only guaranteed
                     * for order book from one source!
                     */
                    foreach (var src in new[] { "NTV" /*, "DEX", "BZX" */ })
                    {
                        var s = con.CreateOrderViewSubscription(l);
                        s.SetSource(src);
                        s.SetSymbols(/*"AAPL",*/ "FB" /*, "SPY"*/);
                        subs.Add(s);
                    }

                    Console.WriteLine("Press enter to stop");
                    Console.ReadLine();
                    foreach (var sub in subs)
                    {
                        sub.Dispose();
                    }
                }
            } catch (DxException dxException) {
                Console.WriteLine($"Native exception occured: {dxException.Message}");
            } catch (Exception exc) {
                Console.WriteLine($"Exception occured: {exc.Message}");
            }
        }
Exemple #14
0
        private static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                WriteHelp();
                return;
            }

            try {
                var address             = args[HOST_INDEX];
                var baseSymbol          = args[SYMBOL_INDEX];
                var dateTime            = new InputParam <DateTime?>(new DateTime(1970, 1, 1, 0, 0, 0, 0));
                var token               = new InputParam <string>(null);
                var exchange            = CandleSymbolAttributes.Exchange.DEFAULT;
                var periodValue         = 1.0;
                var period              = CandleSymbolAttributes.Period.DEFAULT;
                var price               = CandleSymbolAttributes.Price.DEFAULT;
                var session             = CandleSymbolAttributes.Session.DEFAULT;
                var alignment           = CandleSymbolAttributes.Alignment.DEFAULT;
                var priceLevel          = CandleSymbolAttributes.PriceLevel.DEFAULT;
                var logDataTransferFlag = false;

                var attributesAreSet = false;
                for (var i = SYMBOL_INDEX + 1; i < args.Length; i++)
                {
                    if (!dateTime.IsSet && TryParseDateTimeParam(args[i], dateTime))
                    {
                        continue;
                    }

                    if (!token.IsSet && i < args.Length - 1 &&
                        TryParseTaggedStringParam("-T", args[i], args[i + 1], token))
                    {
                        i++;

                        continue;
                    }

                    if (logDataTransferFlag == false && args[i].Equals("-p"))
                    {
                        logDataTransferFlag = true;
                        i++;

                        continue;
                    }

                    const string KEY_VALUE_REGEX = @"([a-z]+)(=)([a-z]+|\d+\.?\d*)";
                    var          match           = Regex.Match(args[i], KEY_VALUE_REGEX, RegexOptions.IgnoreCase);

                    if (match.Groups.Count < 4 || !match.Success)
                    {
                        Console.WriteLine("Invalid Attributes");
                        WriteHelp();
                        return;
                    }

                    if (match.Groups[1].Value.Equals("exchange"))
                    {
                        if (match.Groups[3].Length == 1 && char.IsLetter(match.Groups[3].Value[0]))
                        {
                            exchange         = CandleSymbolAttributes.Exchange.NewExchange(match.Groups[3].Value[0]);
                            attributesAreSet = true;
                        }
                    }
                    else if (match.Groups[1].Value.Equals("period"))
                    {
                        periodValue      = double.Parse(match.Groups[3].Value, new CultureInfo("en-US"));
                        attributesAreSet = true;
                    }
                    else if (match.Groups[1].Value.Equals("type"))
                    {
                        period = CandleSymbolAttributes.Period.NewPeriod(periodValue,
                                                                         CandleType.Parse(match.Groups[3].Value));
                        attributesAreSet = true;
                    }
                    else if (match.Groups[1].Value.Equals("price"))
                    {
                        price            = CandleSymbolAttributes.Price.Parse(match.Groups[3].Value);
                        attributesAreSet = true;
                    }
                    else if (match.Groups[1].Value.Equals("session"))
                    {
                        session          = CandleSymbolAttributes.Session.Parse(match.Groups[3].Value);
                        attributesAreSet = true;
                    }
                    else if (match.Groups[1].Value.Equals("alignment"))
                    {
                        alignment        = CandleSymbolAttributes.Alignment.Parse(match.Groups[3].Value);
                        attributesAreSet = true;
                    }
                    else if (match.Groups[1].Value.Equals("priceLevel"))
                    {
                        priceLevel       = CandleSymbolAttributes.PriceLevel.Parse(match.Groups[3].Value);
                        attributesAreSet = true;
                    }
                }

                var symbol = (attributesAreSet)
                    ? CandleSymbol.ValueOf(baseSymbol, exchange, period, price, session, alignment, priceLevel)
                    : CandleSymbol.ValueOf(baseSymbol);

                Console.WriteLine($"Connecting to {address} for Candle on {symbol} ...");

                NativeTools.InitializeLogging("dxf_candle_sample.log", true, true, logDataTransferFlag);
                using (var con = token.IsSet
                    ? new NativeConnection(address, token.Value, DisconnectHandler)
                    : new NativeConnection(address, DisconnectHandler)) {
                    using (var s = con.CreateSubscription(dateTime.Value, new EventListener())) {
                        s.AddSymbol(symbol);

                        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.GetType()}, message: {exc.Message}");
            }
        }
        async Task ExecuteShareBlobCommandAsync()
        {
            if (IsBusy)
            {
                return;
            }

            App.Logger.Track(AppEvent.ShareBlob.ToString());


            if (HasBlobBeenSaved)
            {
                try
                {
#if __ANDROID__
                    string          mimeType = MediaTypeMapper.GetMimeType(BlobFileExtension);
                    Android.Net.Uri uri      = Android.Net.Uri.Parse("file:///" + GetBlobFilePath());
                    Intent          intent   = new Intent(Intent.ActionView);
                    intent.SetDataAndType(uri, mimeType);
                    intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);
                    try
                    {
                        Xamarin.Forms.Forms.Context.StartActivity(intent);
                    }
                    catch (Exception ex)
                    {
                        MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                        {
                            Title   = "Unable to Share",
                            Message = "No applications available to open files of type " + BlobFileExtension,
                            Cancel  = "OK"
                        });
                        throw ex;
                    }
#elif __IOS__
                    var extensionClassRef = new NSString(UTType.TagClassFilenameExtension);
                    var mimeTypeClassRef  = new NSString(UTType.TagClassMIMEType);

                    var uti = NativeTools.UTTypeCreatePreferredIdentifierForTag(extensionClassRef.Handle, new NSString(BlobFileExtension).Handle, IntPtr.Zero);
                    //TODO: open file based off of type
                    var fi   = NSData.FromFile(GetBlobFilePath());
                    var item = NSObject.FromObject(fi);


                    var activityItems = new[] { item };



                    var activityController = new UIActivityViewController(activityItems, null);

                    var topController = UIApplication.SharedApplication.KeyWindow.RootViewController;

                    while (topController.PresentedViewController != null)
                    {
                        topController = topController.PresentedViewController;
                    }

                    topController.PresentViewController(activityController, true, () => { });
#endif
                }
                catch (Exception ex)
                {
                    App.Logger.Report(ex, Severity.Error);
                }
            }
        }