Example #1
0
        /// <summary>
        /// Get trading history between <paramref name="fromCurrency"/> and <paramref name="toCurrency"/> from LykkeExchange
        /// </summary>
        /// <param name="apiKey">API key</param>
        /// <param name="fromCurrency">Currency to exchange from</param>
        /// <param name="toCurrency">Currecny to exchange to</param>
        /// <param name="skip">Number of recent trading histories to skip</param>
        /// <param name="take">Number of recent histories to collect after skipping <paramref name="skip"/></param>
        /// <returns><see cref="LykkeTradeHistory"/></returns>
        public LykkeTradeHistory[] GetWalletTradeInformation(string apiKey, string fromCurrency, string toCurrency, int skip, int take)
        {
            var currencyCombination = GetCurrencyCombination(fromCurrency, toCurrency);
            var exchangeRate        = FetchExchangeRate(currencyCombination);

            if (exchangeRate == null)
            {
                throw new CurrencyCombinationNotSupportedAtExchange(LykkeExchangeName, fromCurrency, toCurrency);
            }

            var url = TransactionApiUrl + "History/trades?assetPairId=" + currencyCombination + "&skip=" + skip + "&take=" + take;

            var headers = new Dictionary <string, string>();

            headers.Add("api-key", apiKey);

            var urlResponse = ThirdPartyRestCallsUtility.Get(url, headers);

            try
            {
                var lykkeExchangeRates = JsonConvert.DeserializeObject <LykkeTradeHistory[]>(urlResponse);
                return(lykkeExchangeRates);
            }
            catch (Exception)
            {
                return(new LykkeTradeHistory[0]);
            }
        }
Example #2
0
        private LykkeMarketExchangeRate FetchExchangeRate(string currencyCombination)
        {
            var urlResponse = ThirdPartyRestCallsUtility.Get(Url + currencyCombination);

            var exchangeRate = ExtractExchangeRate(urlResponse);

            return(exchangeRate);
        }
Example #3
0
        /// <summary>
        /// Returns all available balances in the exchange wallet
        /// </summary>
        /// <param name="apiKey"></param>
        /// <returns></returns>
        public LykkeWalletBalance[] GetBalances(string apiKey)
        {
            var url     = TransactionApiUrl + "Wallets";
            var headers = new Dictionary <string, string>();

            headers.Add("api-key", apiKey);

            var urlResponse = ThirdPartyRestCallsUtility.Get(url, headers);

            if (urlResponse != null)
            {
                LykkeWalletBalance[] walletBalances = JsonConvert.DeserializeObject <LykkeWalletBalance[]>(urlResponse, this.JsonSerializerSettings);
                return(walletBalances);
            }

            return(null);
        }
Example #4
0
        private static List <LykkeTrade> FetchTradingHistory(int skip, int count, string currencyCombination)
        {
            var urlToRequest = PublicTradingHistoryUrl + currencyCombination + "?skip=" + skip;

            if (count > 0)
            {
                urlToRequest = urlToRequest + "&take=" + count;
            }

            string urlResponse;

            try
            {
                urlResponse = ThirdPartyRestCallsUtility.Get(urlToRequest);
            }
            catch (Exception)
            {
                urlResponse = null;
            }

            var tradingHistory = ExtractExchangeTradingHistory(urlResponse);

            return(tradingHistory);
        }