Exemplo n.º 1
0
 /// <summary>
 /// Creates a LykkeHistory object with given arguments.
 /// </summary>
 /// <param name="FromCurrency">Trade from currency</param>
 /// <param name="ToCurrency">Trade to currency</param>
 /// <param name="Amount">Trade Volume</param>
 /// <param name="Price">Trading price</param>
 /// <param name="TradeType">Type of the trade. <see cref="LykkeTradeType"/></param>
 /// <param name="DateTime">Time Stamp of the trade</param>
 public LykkeHistory(string FromCurrency, string ToCurrency, decimal Amount, decimal Price, LykkeTradeType TradeType, DateTime DateTime)
 {
     this.FromCurrency = FromCurrency;
     this.ToCurrency   = ToCurrency;
     this.Amount       = Amount;
     this.Price        = Price;
     this.TradeType    = TradeType;
     this.DateTime     = DateTime;
 }
Exemplo n.º 2
0
        /// <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());
            }
        }