コード例 #1
0
        private static void GetPrices(TradingApiClient client)
        {
            PricesResponse prices;
            var            sw = new Stopwatch();

            sw.Start();

            prices = client.PublicApi.GetPrices(new PricesRequest());
            ValidateResult(prices.Error);

            sw.Stop();

            Console.WriteLine($"Count prices: {prices.Payload.Count}. ExecTime: {sw.ElapsedMilliseconds} ms");
        }
コード例 #2
0
        private static async Task GetPriceSnapshot(string[] filter, TradingApiClient client)
        {
            var priceRequest = new PricesRequest();

            priceRequest.AssetPairIds.AddRange(filter);

            var prices = await client.PublicApi.GetPricesAsync(priceRequest);

            ValidateResult(prices.Error);
            Console.WriteLine($"Count prices: {prices.Payload.Count}.");

            foreach (var price in prices.Payload)
            {
                Console.WriteLine($"{price.AssetPairId}: Ask={price.Ask}; Bid={price.Bid}; Time={price.Timestamp}");
            }
        }
コード例 #3
0
        static async Task Main(string[] args)
        {
            try
            {
                string[] filter = ReadFilterFromConsole();

                var client = new TradingApiClient("https://hft-apiv2-grpc.lykke.com", "");

                await GetPriceSnapshot(filter, client);

                await FollowPriceUpdate(filter, client);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
コード例 #4
0
        static async Task Main(string[] args)
        {
            try
            {
                string filter = ReadFilterFromConsole();

                var client = new TradingApiClient("https://hft-apiv2-grpc.lykke.com", "");


                UpdateThread(client, filter);

                await PrintThread();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
コード例 #5
0
        private static async Task FollowPriceUpdate(string[] filter, TradingApiClient client)
        {
            var priceUpdateRequest = new PriceUpdatesRequest();

            priceUpdateRequest.AssetPairIds.AddRange(filter);

            Console.WriteLine("Subscribe to prices.");
            var priceStream = client.PublicApi.GetPriceUpdates(priceUpdateRequest);

            var token = new CancellationToken();

            while (await priceStream.ResponseStream.MoveNext(token))
            {
                var update = priceStream.ResponseStream.Current;

                Console.WriteLine($"{update.AssetPairId}  Bid: {update.Bid}  Ask: {update.Ask}  {update.Timestamp}");
            }

            Console.WriteLine("Price stream are closed.");
        }
コード例 #6
0
        static async Task UpdateThread(TradingApiClient client, string filter)
        {
            var reqiest = new OrderbookUpdatesRequest();

            reqiest.AssetPairId = filter;
            var stream = client.PublicApi.GetOrderbookUpdates(reqiest);

            var token = new CancellationToken();

            while (await stream.ResponseStream.MoveNext(token))
            {
                var update = stream.ResponseStream.Current;

                foreach (Orderbook.Types.PriceVolume ask in update.Asks)
                {
                    var price = decimal.Parse(ask.P);
                    if (ask.V == "0")
                    {
                        _ask.Remove(price);
                    }
                    else
                    {
                        _ask[price] = ask.V;
                    }
                }

                foreach (Orderbook.Types.PriceVolume bid in update.Bids)
                {
                    var price = decimal.Parse(bid.P);
                    if (bid.V == "0")
                    {
                        _bid.Remove(price);
                    }
                    else
                    {
                        _bid[price] = bid.V;
                    }
                }
            }
        }
コード例 #7
0
 public ApiTrader(string apiEndpoint, string apiKey)
 {
     Client = new TradingApiClient(apiEndpoint, apiKey);
 }