Beispiel #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());
            }
        }
        public OrderModel ToOrder(CurrencyMapping mapping)
        {
            var instrument = CexIoInstrument.FromPair(Symbol1, Symbol2);

            TradeType type;

            switch (Type?.ToLowerInvariant())
            {
            case "buy":
                type = TradeType.Buy;
                break;

            case "sell":
                type = TradeType.Sell;
                break;

            default:
                throw new InvalidOperationException($"Type {Type} is unknown");
            }

            return(new OrderModel
            {
                Id = Id,
                AssetPair = CexIoInstrument.ToLykkeInstrument(instrument, mapping),
                Price = Price,
                OriginalVolume = Amount,
                TradeType = type,
                Timestamp = Time,
                RemainingAmount = Pending,
                ExecutedVolume = Amount - Pending
            });
        }
Beispiel #3
0
        public async Task <IReadOnlyCollection <string> > GetInstruments()
        {
            var limits = await Api.GetCurrencyLimits();

            return(limits
                   .Select(x => CexIoInstrument.FromPair(x.Symbol1, x.Symbol2))
                   .Select(x => CexIoInstrument.ToLykkeInstrument(x, _currencyMapping))
                   .ToArray());
        }
        public OrderModel ToOrder(CurrencyMapping mapping, string orderType)
        {
            var instrument = CexIoInstrument.FromPair(Symbol1, Symbol2);

            return(new OrderModel
            {
                Id = Id,
                TradeType = Enum.Parse <TradeType>(Type, true),
                Price = Price,
                Timestamp = Time,
                RemainingAmount = Remains,
                AssetPair = CexIoInstrument.ToLykkeInstrument(instrument, mapping),
                OriginalVolume = Amount,
                ExecutedVolume = Amount - Remains,
                ExecutionStatus = Status.ToOrderStatus()
            });
        }