Esempio n. 1
0
        public string GetDepositAddress(IExchangeMarket aMarket)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }
            string lResult;
            string lTicker = aMarket.SellingCurrencyInfo.Ticker;

            using (PoloniexClient lClient = new PoloniexClient())
            {
                var lResponse = lClient.GetDepositAddresses();
                if (!lResponse.Success)
                {
                    throw new Exception("Failed to retrieve Poloniex Address. " + lResponse.Error.Message);
                }
                if (lResponse.Data.TryGetValue(lTicker, out string lAddress))
                {
                    lResult = lAddress;
                }
                else
                {
                    var lNewAddressResponse = lClient.GenerateNewAddress(lTicker);
                    if (!lNewAddressResponse.Success || !Convert.ToBoolean(lNewAddressResponse.Data.success))
                    {
                        throw new Exception("Failed to retrieve Poloniex Address. " + lResponse.Error.Message);
                    }
                    lResult = lNewAddressResponse.Data.response;
                }
            }
            return(lResult);
        }
Esempio n. 2
0
        public IMarketPriceInfo GetMarketPrice(IExchangeMarket aMarket)
        {
            MarketPriceInfo lResult = new MarketPriceInfo();

            if (!aMarket.TryCastToLocalMarket(out ExchangeMarket lExchangeMarket))
            {
                throw new ArgumentException(nameof(aMarket), "Invalid Market");
            }
            if (FMarketPrices.TryGetValue(lExchangeMarket.MarketPairID, out MarketPriceInfo lValue))
            {
                lResult = lValue;
            }
            return(lResult);
        }
Esempio n. 3
0
        public string GetDepositAddress(IExchangeMarket aMarket)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            using (var lClient = new BitfinexClient())
            {
                var lAddressResponse = lClient.GetDepositAddressAsync(aMarket.SellingCurrencyInfo.Name.ToLowerInvariant(), WithdrawWallet.Exchange).Result;
                if (!lAddressResponse.Success)
                {
                    throw new Exception($"Failed to get deposit address for bitfinex. Details: {lAddressResponse.Error}");
                }
                return(lAddressResponse.Data.Address);
            }
        }
Esempio n. 4
0
        public decimal GetBalance(IExchangeMarket aMarket)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            using (PoloniexClient lClient = new PoloniexClient())
            {
                var lResponse = lClient.GetBalances();
                if (!lResponse.Success || !lResponse.Data.TryGetValue(aMarket.SellingCurrencyInfo.Ticker, out decimal lBalance))
                {
                    throw new Exception("Failed to retrieve balance");
                }
                return(lBalance);
            }
        }
        public string GetDepositAddress(IExchangeMarket aMarket)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            using (BittrexClient lClient = new BittrexClient())
            {
                CallResult <BittrexDepositAddress> lResponse = lClient.GetDepositAddressAsync(aMarket.SellingCurrencyInfo.Ticker).Result;

                if (!lResponse.Success)
                {
                    throw new Exception("Failed to retrieve Bittrex Address. " + lResponse.Error.Message);
                }

                BittrexDepositAddress lAddress = lResponse.Data;

                return(lAddress.Address);
            }
        }
        public decimal GetBalance(IExchangeMarket aMarket)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            using (BittrexClient lClient = new BittrexClient())
            {
                if (!aMarket.TryCastToLocalMarket(out ExchangeMarket lExchangeMarket))
                {
                    throw new ArgumentException(nameof(aMarket), "Invalid Market");
                }
                CallResult <BittrexBalance> lResponse = lClient.GetBalanceAsync(lExchangeMarket.MarketPairID).Result;

                if (!lResponse.Success)
                {
                    throw new Exception("Failed to retrieve balance");
                }

                return(lResponse.Data.Available);
            }
        }
Esempio n. 7
0
        public decimal GetBalance(IExchangeMarket aMarket)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            using (var lClient = new BitfinexClient())
            {
                var lResponse = lClient.GetBalancesAsync().Result;
                if (!lResponse.Success)
                {
                    throw new Exception($"Failed to retrieve balance. Details: {lResponse.Error}");
                }
                var lBalances       = lResponse.Data;
                var lDecimalBalance = lBalances.Where(lBalance => lBalance.Currency == aMarket.SellingCurrencyInfo.Ticker).FirstOrDefault();
                if (lDecimalBalance == null)
                {
                    throw new Exception($"Failed to get balance for currency {aMarket.SellingCurrencyInfo.Name}");
                }
                return(lDecimalBalance.Balance);
            }
        }
Esempio n. 8
0
 public virtual bool Equals(IExchangeMarket other)
 {
     return(string.Equals(MarketID, other.MarketID, StringComparison.OrdinalIgnoreCase));
 }
Esempio n. 9
0
 internal static bool TryCastToLocalMarket(this IExchangeMarket aExchangeMarket, out ExchangeMarket aMarket)
 {
     aMarket = aExchangeMarket as ExchangeMarket;
     return(aMarket != null && !string.IsNullOrEmpty(aMarket.MarketPairID));
 }
Esempio n. 10
0
 public ForexController(IExchangeMarket exchangeMarket)
 {
     _exchangeMarket = exchangeMarket;
 }