/// <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]); } }
private LykkeMarketExchangeRate FetchExchangeRate(string currencyCombination) { var urlResponse = ThirdPartyRestCallsUtility.Get(Url + currencyCombination); var exchangeRate = ExtractExchangeRate(urlResponse); return(exchangeRate); }
/// <summary> /// Execute a market order in lykke exchange. Buy or Sell a volume of an asset for another asset. /// </summary> /// <param name="apiKey">API key</param> /// <param name="fromCurrency">Currecny to exchange from</param> /// <param name="toCurrency">Currecny to exchange to</param> /// <param name="tradeType"> /// SELL <paramref name="fromCurrency"/> for <paramref name="toCurrency"/>or BUY <paramref name="fromCurrency"/> for <paramref name="toCurrency"/> /// </param> /// <param name="value">Volume of trade</param> /// <returns>Amount of resultant <paramref name="toCurrency"/> after executing market order.</returns> public LykkeMoney MarketOrder(string apiKey, string fromCurrency, string toCurrency, LykkeTradeType tradeType, decimal value) { // Actual market order implementation var currencyCombination = GetCurrencyCombination(fromCurrency, toCurrency); var orderAction = tradeType == LykkeTradeType.BUY ? "Buy" : "Sell"; var exchangeRate = FetchExchangeRate(currencyCombination); if (exchangeRate == null) { throw new CurrencyCombinationNotSupportedAtExchange(LykkeExchangeName, fromCurrency, toCurrency); } var url = TransactionApiUrl + "Orders/market"; var headers = new Dictionary <string, string>(); headers.Add("api-key", apiKey); var postData = new Dictionary <string, object>(); postData.Add("AssetPairId", currencyCombination); postData.Add("Asset", fromCurrency.ToString()); postData.Add("OrderAction", orderAction); postData.Add("Volume", value); var postDataString = JsonConvert.SerializeObject(postData); try { LykkeWalletBalance preExecutionBalance = GetBalance(apiKey, toCurrency.ToString()); var urlResponse = ThirdPartyRestCallsUtility.Post(url, postDataString, headers); LykkeWalletBalance postExecutionBalance = GetBalance(apiKey, toCurrency.ToString()); if (urlResponse != null) { var marketResult = JsonConvert.DeserializeObject <MarketResult>(urlResponse, this.JsonSerializerSettings); var price = marketResult.Result; var tradeResult = (postExecutionBalance.Balance - preExecutionBalance.Balance); return(new LykkeMoney(tradeResult, toCurrency)); } else { throw new MarketOrderFailedException(LykkeExchangeName, fromCurrency.ToString(), toCurrency.ToString()); } } catch (Exception e) { throw new MarketOrderFailedException(LykkeExchangeName, fromCurrency.ToString(), toCurrency.ToString()); } }
/// <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); }
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); }