public static string FromLykkeInstrument(string instrument, CurrencyMapping mapping)
        {
            if (instrument.Length == 6)
            {
                var l1 = instrument.Substring(0, 3);
                var l2 = instrument.Substring(3, 3);

                return(FromLykkePair(l1, l2, mapping));
            }

            if (instrument.Length == 7)
            {
                var candidate = instrument.Substring(0, 4);

                if (mapping.FourCharsCurrencies.Contains(candidate))
                {
                    return(FromLykkePair(candidate, instrument.Substring(4, 3), mapping));
                }
                else
                {
                    return(FromLykkePair(instrument.Substring(0, 3), instrument.Substring(3, 4), mapping));
                }
            }

            if (instrument.Length == 8)
            {
                return(FromLykkePair(instrument.Substring(0, 4), instrument.Substring(4, 4), mapping));
            }

            throw new ArgumentException("Instrument should be of length 6 or 7", nameof(instrument));
        }
        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 CexIoRestClient(IApiCredentials credentials, CurrencyMapping currencyMapping, ILogFactory logFactory)
 {
     _credentials     = credentials;
     _currencyMapping = currencyMapping;
     _client          = new HttpClient(new LoggingHandler(logFactory.CreateLog(this), new HttpClientHandler()))
     {
         BaseAddress = new Uri("https://cex.io/api/")
     };
 }
        private static string FromLykkePair(string l1, string l2, CurrencyMapping mapping)
        {
            if (mapping.Inverted.TryGetValue(l1, out var s1))
            {
                l1 = s1;
            }

            if (mapping.Inverted.TryGetValue(l2, out var s2))
            {
                l2 = s2;
            }

            return(FromPair(l1, l2));
        }
        public static string ToLykkeInstrument(string instrument, CurrencyMapping mapping)
        {
            var(symbol1, symbol2) = FromInstrument(instrument);

            if (mapping.Rename.TryGetValue(symbol1, out var s1))
            {
                symbol1 = s1;
            }

            if (mapping.Rename.TryGetValue(symbol2, out var s2))
            {
                symbol2 = s2;
            }

            return(symbol1 + symbol2);
        }
        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()
            });
        }
Beispiel #7
0
 public SpotController(CexIoAdapterSettings settings, ILogFactory logFactory)
 {
     _currencyMapping = settings.OrderBooks.CurrencyMapping;
     _log             = logFactory.CreateLog(this);
 }