Exemple #1
0
        static float TotalWealth(Yobit.YobitApiClient yobitApiClient, string resultCoin)
        {
            resultCoin = resultCoin.ToLower();

            var accountInfo = yobitApiClient.GetInfo();

            if (accountInfo.success == 0)
            {
                throw new Exception("Метод GetInfo возвратил ошибку: " + accountInfo.error);
            }
            var   accountCoinPairs = new CoinsPairs([email protected]_incl_orders.Select(pair => new CoinPair(pair.Key, resultCoin)));
            var   ticker           = yobitApiClient.Ticker(accountCoinPairs);
            float sumWealth        = 0;

            foreach (var coin in [email protected]_incl_orders.Keys)
            {
                if (coin == resultCoin)
                {
                    sumWealth += [email protected]_incl_orders[coin];
                    Console.WriteLine($"On balance: {[email protected]_incl_orders[resultCoin]}{resultCoin}");
                    continue;
                }
                var coinPair     = new CoinPair(coin, resultCoin);
                var coinSumPrice = [email protected]_incl_orders[coin] * ticker[coinPair.ToString()].sell;
                if (coinPair.Reverted)
                {
                    coinSumPrice = [email protected]_incl_orders[coin] / ticker[coinPair.ToString()].sell;                   // на случай usd_rur
                }
                sumWealth += coinSumPrice;

                Console.WriteLine($"{[email protected]_incl_orders[coin]}{coin} {(!coinPair.Reverted ? "*" : "/")} {ticker[coinPair.ToString()].sell}{resultCoin} = {coinSumPrice}{resultCoin}");
            }
            Console.WriteLine($"Total: {sumWealth}{resultCoin}");
            return(sumWealth);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var yobitClient = new Yobit.YobitApiClient("key", "secret", new YobitClientLogger());

            // PublicAPI
            //var info = yobitClient.Info();
            //var coinPairs = new CoinsPairs { new CoinPair ("ETH", "USD") };
            //var depth = yobitClient.Depth(coinPairs);
            //var ticker = yobitClient.Ticker(coinPairs);
            //var trades = yobitClient.Trades(coinPairs);

            // TradeAPI
            //var getInfo = yobitClient.GetInfo();
            //Thread.Sleep(1000);
            //var trade = yobitClient.Trade(new CoinPair("btc", "usd"), TradeOperationType.Sell, 15000, 0.10000001);

            // Total value of my wealth in rubles
            Console.WriteLine("TotalWealth in RUR:");
            var myTotalWealth = TotalWealth(yobitClient, "RUR");

            Thread.Sleep(1000);
            Console.WriteLine("==========================================================================");
            Console.WriteLine("TotalWealth in USD:");
            myTotalWealth = TotalWealth(yobitClient, "USD");
            //Console.WriteLine("==========================================================================");
            //Console.WriteLine("TotalWealth in BTC:");
            //myTotalWealth = TotalWealth(yobitClient, "BTC"); // wrong result !

            Console.ReadLine();
        }