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());
            }
        }
        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
            });
        }
Exemple #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());
        }
Exemple #4
0
 private IObservable <OrderBook> CombineWithSnapshot(
     IObservable <IOrderBookMessage> changes,
     string instrument)
 {
     return(changes.Scan(
                OrderBookAggregator.CreateDefault(
                    _logFactory,
                    Name,
                    CexIoInstrument.ToLykkeInstrument(instrument, _orderBookSettings.CurrencyMapping)),
                (context, ev) => context.ApplyChange(ev))
            .Select(x => x.OrderBook));
 }
        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()
            });
        }
Exemple #6
0
 public void cex_io_instruments_to_lykke(string cexIo, string lykke)
 {
     Assert.Equal(lykke, CexIoInstrument.ToLykkeInstrument(cexIo, _mapping));
     Assert.Equal(cexIo, CexIoInstrument.FromLykkeInstrument(lykke, _mapping));
 }