Exemple #1
0
        private async Task <IReadOnlyCollection <(string, string)> > GetPairs(CexIoRestClient restApi)
        {
            _log.Info("Getting currency limits from REST API");
            using (var ct = new CancellationTokenSource(_orderBookSettings.Timeouts.RetrieveCurrencyLimits))
            {
                var limits             = (await restApi.GetCurrencyLimits(ct.Token)).ToList();
                var instruments        = new List <string>();
                var skippedInstruments = new List <string>();
                var result             = new List <(string, string)>();

                foreach (var currencyInfo in limits)
                {
                    string instrument = CexIoInstrument.FromPair(currencyInfo.Symbol1, currencyInfo.Symbol2, false);

                    if (instrument == null)
                    {
                        skippedInstruments.Add($"{currencyInfo.Symbol1}:{currencyInfo.Symbol2}");
                        continue;
                    }

                    instruments.Add(instrument);
                    result.Add((currencyInfo.Symbol1, currencyInfo.Symbol2));
                }

                _log.Info($"Got instruments: {string.Join(", ", instruments)}");
                _log.Info($"Skipped instruments: {string.Join(", ", skippedInstruments)}");
                return(result.ToArray());
            }
        }
Exemple #2
0
        private IObservable <OrderBook> GetRawOrderBooks()
        {
            var creds = new ApiCredentials
            {
                ApiKey    = _orderBookSettings.WebSocketCredentials.ApiKey,
                ApiSecret = _orderBookSettings.WebSocketCredentials.ApiSecret,
                UserId    = _orderBookSettings.WebSocketCredentials.UserId
            };

            var restApi = new CexIoRestClient(creds, _orderBookSettings.CurrencyMapping, _logFactory);

            _log.Info("Retrieving existing pairs");
            var pairs = GetPairs(restApi).Result;

            _log.Info($"{pairs.Count} retrieved");

            var timeouts = new WebSocketTimeouts(
                readTimeout: _orderBookSettings.Timeouts.SocketInactivity,
                connectTimeout: _orderBookSettings.Timeouts.WebSocketConnect,
                writeToSocket: _orderBookSettings.Timeouts.WriteToSocket);

            var wsClient = new CexIoListener(pairs, creds, timeouts, _log);

            var orderbooks = wsClient.Messages
                             .Select(x => x.Message as IOrderBookMessage)
                             .Where(x => x != null)
                             .GroupBy(x => x.Pair)
                             .SelectMany(ProcessSingleInstrument);

            return(orderbooks);
        }
Exemple #3
0
        public async Task get_currency_limits()
        {
            var rest   = new CexIoRestClient(new InternalApiCredentials(), _mapping, EmptyLogFactory.Instance);
            var limits = await rest.GetCurrencyLimits();

            Assert.NotEmpty(limits);
        }