Пример #1
0
        private static void PerformTests(Dictionary <string, string> dict)
        {
            IExchangeAPI[] apis = ExchangeAPI.GetExchangeAPIDictionary().Values.ToArray();
            foreach (IExchangeAPI api in apis)
            {
                // test all public API for each exchange
                try
                {
                    string symbol = GetSymbol(api);

                    IReadOnlyCollection <string> symbols = api.GetSymbols();
                    Assert(symbols != null && symbols.Count != 0 && symbols.Contains(symbol));

                    ExchangeTrade[] trades = api.GetHistoricalTrades(symbol).ToArray();
                    Assert(trades.Length != 0 && trades[0].Price > 0m && trades[0].Amount > 0m);

                    var book = api.GetOrderBook(symbol);
                    Assert(book.Asks.Count != 0 && book.Bids.Count != 0 && book.Asks[0].Amount > 0m &&
                           book.Asks[0].Price > 0m && book.Bids[0].Amount > 0m && book.Bids[0].Price > 0m);

                    trades = api.GetRecentTrades(symbol).ToArray();
                    Assert(trades.Length != 0 && trades[0].Price > 0m && trades[0].Amount > 0m);

                    var ticker = api.GetTicker(symbol);
                    Assert(ticker != null && ticker.Ask > 0m && ticker.Bid > 0m && ticker.Last > 0m &&
                           ticker.Volume != null && ticker.Volume.PriceAmount > 0m && ticker.Volume.QuantityAmount > 0m);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Request failed, api: {0}, error: {1}", api, ex);
                }
            }
        }
Пример #2
0
        private static void TestExchanges()
        {
            IExchangeAPI[] apis = ExchangeAPI.GetExchangeAPIDictionary().Values.ToArray();
            foreach (IExchangeAPI api in apis)
            {
                // test all public API for each exchange
                try
                {
                    string symbol = GetSymbol(api);

                    IReadOnlyCollection <string> symbols = api.GetSymbols().ToArray();
                    Assert(symbols != null && symbols.Count != 0 && symbols.Contains(symbol, StringComparer.OrdinalIgnoreCase));
                    Console.WriteLine($"API {api.Name} GetSymbols OK (default: {symbol}; {symbols.Count} symbols)");

                    ExchangeTrade[] trades = api.GetHistoricalTrades(symbol).ToArray();
                    Assert(trades.Length != 0 && trades[0].Price > 0m && trades[0].Amount > 0m);
                    Console.WriteLine($"API {api.Name} GetHistoricalTrades OK ({trades.Length})");

                    var book = api.GetOrderBook(symbol);
                    Assert(book.Asks.Count != 0 && book.Bids.Count != 0 && book.Asks[0].Amount > 0m &&
                           book.Asks[0].Price > 0m && book.Bids[0].Amount > 0m && book.Bids[0].Price > 0m);
                    Console.WriteLine($"API {api.Name} GetOrderBook OK ({book.Asks.Count} asks, {book.Bids.Count} bids)");

                    trades = api.GetRecentTrades(symbol).ToArray();
                    Assert(trades.Length != 0 && trades[0].Price > 0m && trades[0].Amount > 0m);
                    Console.WriteLine($"API {api.Name} GetRecentTrades OK ({trades.Length} trades)");

                    var ticker = api.GetTicker(symbol);
                    Assert(ticker != null && ticker.Ask > 0m && ticker.Bid > 0m && ticker.Last > 0m &&
                           ticker.Volume != null && ticker.Volume.PriceAmount > 0m && ticker.Volume.QuantityAmount > 0m);
                    Console.WriteLine($"API {api.Name} GetTicker OK (ask: {ticker.Ask}, bid: {ticker.Bid}, last: {ticker.Last})");

                    try
                    {
                        var candles = api.GetCandles(symbol, 86400, DateTime.UtcNow.Subtract(TimeSpan.FromDays(7.0)), null).ToArray();
                        Assert(candles.Length != 0 && candles[0].ClosePrice > 0m && candles[0].HighPrice > 0m && candles[0].LowPrice > 0m && candles[0].OpenPrice > 0m &&
                               candles[0].HighPrice >= candles[0].LowPrice && candles[0].HighPrice >= candles[0].ClosePrice && candles[0].HighPrice >= candles[0].OpenPrice &&
                               !string.IsNullOrWhiteSpace(candles[0].Name) && candles[0].ExchangeName == api.Name && candles[0].PeriodSeconds == 86400 && candles[0].VolumePrice > 0.0 &&
                               candles[0].VolumeQuantity > 0.0 && candles[0].WeightedAverage >= 0m);

                        Console.WriteLine($"API {api.Name} GetCandles OK ({candles.Length})");
                    }
                    catch (NotSupportedException)
                    {
                        Console.WriteLine($"API {api.Name} GetCandles not supported");
                    }
                    catch (NotImplementedException)
                    {
                        Console.WriteLine($"API {api.Name} GetCandles not implemented");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Request failed, api: {0}, error: {1}", api, ex.Message);
                }
            }
        }
Пример #3
0
        public void GlobalSymbolTest()
        {
            string symbol    = "BTC-ETH";
            string altSymbol = "BTC-KRW"; // WTF Bitthumb...

            // sanity test that all exchanges return the same global symbol when converted back and forth
            foreach (IExchangeAPI api in ExchangeAPI.GetExchangeAPIDictionary().Values)
            {
                try
                {
                    string exchangeSymbol = api.GlobalSymbolToExchangeSymbol(symbol);
                    string globalSymbol   = api.ExchangeSymbolToGlobalSymbol(exchangeSymbol);
                    Assert.IsTrue(symbol == globalSymbol || altSymbol == globalSymbol);
                }
                catch (Exception ex)
                {
                    Assert.Fail($"Exchange {api.Name} error converting symbol: {ex}");
                }
            }
        }
        private static void TestExchanges(string nameRegex = null)
        {
            string GetSymbol(IExchangeAPI api)
            {
                if (api is ExchangeCryptopiaAPI || api is ExchangeLivecoinAPI)
                {
                    return("LTC/BTC");
                }
                else if (api is ExchangeKrakenAPI)
                {
                    return(api.NormalizeSymbol("XXBTZUSD"));
                }
                else if (api is ExchangeBittrexAPI || api is ExchangePoloniexAPI)
                {
                    return(api.NormalizeSymbol("BTC-LTC"));
                }
                else if (api is ExchangeBinanceAPI || api is ExchangeOkexAPI || api is ExchangeBleutradeAPI ||
                         api is ExchangeKucoinAPI || api is ExchangeHuobiAPI)
                {
                    return(api.NormalizeSymbol("ETH-BTC"));
                }
                else if (api is ExchangeYobitAPI)
                {
                    return(api.NormalizeSymbol("LTC_BTC"));
                }
                else if (api is ExchangeTuxExchangeAPI)
                {
                    return(api.NormalizeSymbol("BTC_ETH"));
                }
                return(api.NormalizeSymbol("BTC-USD"));
            }

            ExchangeTrade[] trades = null;
            bool histTradeCallback(IEnumerable <ExchangeTrade> tradeEnum)
            {
                trades = tradeEnum.ToArray();
                return(true);
            }

            IExchangeAPI[] apis = ExchangeAPI.GetExchangeAPIDictionary().Values.ToArray();
            foreach (IExchangeAPI api in apis)
            {
                if (nameRegex != null && !System.Text.RegularExpressions.Regex.IsMatch(api.Name, nameRegex, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                {
                    continue;
                }

                // test all public API for each exchange
                try
                {
                    string symbol = GetSymbol(api);

                    IReadOnlyCollection <string> symbols = api.GetSymbols().ToArray();
                    Assert(symbols != null && symbols.Count != 0 && symbols.Contains(symbol, StringComparer.OrdinalIgnoreCase));
                    Console.WriteLine($"API {api.Name} GetSymbols OK (default: {symbol}; {symbols.Count} symbols)");

                    var book = api.GetOrderBook(symbol);
                    Assert(book.Asks.Count != 0 && book.Bids.Count != 0 && book.Asks.First().Value.Amount > 0m &&
                           book.Asks.First().Value.Price > 0m && book.Bids.First().Value.Amount > 0m && book.Bids.First().Value.Price > 0m);
                    Console.WriteLine($"API {api.Name} GetOrderBook OK ({book.Asks.Count} asks, {book.Bids.Count} bids)");

                    var ticker = api.GetTicker(symbol);
                    try
                    {
                        Assert(ticker != null && ticker.Ask > 0m && ticker.Bid > 0m && ticker.Last > 0m &&
                               ticker.Volume != null && ticker.Volume.BaseVolume > 0m && ticker.Volume.ConvertedVolume > 0m);
                        Console.WriteLine($"API {api.Name} GetTicker OK (ask: {ticker.Ask}, bid: {ticker.Bid}, last: {ticker.Last})");
                    }
                    catch
                    {
                        Console.WriteLine($"API {api.Name} GetTicker data invalid or empty: {ticker}");
                    }

                    try
                    {
                        api.GetHistoricalTrades(histTradeCallback, symbol);
                        trades = api.GetRecentTrades(symbol).ToArray();
                    }
                    catch (NotImplementedException)
                    {
                        if (api is ExchangeHuobiAPI || api is ExchangeBithumbAPI)
                        {
                            Console.WriteLine($"API {api.Name} GetHistoricalTrades/GetRecentTrades not implemented");
                        }
                        else
                        {
                            throw;
                        }
                    }

                    try
                    {
                        Assert(trades.Length != 0 && trades[0].Price > 0m && trades[0].Amount > 0m);
                        Console.WriteLine($"API {api.Name} GetHistoricalTrades OK ({trades.Length})");
                        Assert(trades.Length != 0 && trades[0].Price > 0m && trades[0].Amount > 0m);
                        Console.WriteLine($"API {api.Name} GetRecentTrades OK ({trades.Length} trades)");
                    }
                    catch
                    {
                        Console.WriteLine($"API {api.Name} GetHistoricalTrades/GetRecentTrades data invalid or empty");
                    }

                    try
                    {
                        var candles = api.GetCandles(symbol, 86400, DateTime.UtcNow.Subtract(TimeSpan.FromDays(7.0)), null).ToArray();
                        Assert(candles.Length != 0 && candles[0].ClosePrice > 0m && candles[0].HighPrice > 0m && candles[0].LowPrice > 0m && candles[0].OpenPrice > 0m &&
                               candles[0].HighPrice >= candles[0].LowPrice && candles[0].HighPrice >= candles[0].ClosePrice && candles[0].HighPrice >= candles[0].OpenPrice &&
                               !string.IsNullOrWhiteSpace(candles[0].Name) && candles[0].ExchangeName == api.Name && candles[0].PeriodSeconds == 86400 && candles[0].BaseVolume > 0.0 &&
                               candles[0].ConvertedVolume > 0.0 && candles[0].WeightedAverage >= 0m);

                        Console.WriteLine($"API {api.Name} GetCandles OK ({candles.Length})");
                    }
                    catch (NotImplementedException)
                    {
                        Console.WriteLine($"API {api.Name} GetCandles not implemented");
                    }
                    catch
                    {
                        // These API require private access to get candles end points
                        if (!(api is ExchangeKucoinAPI))
                        {
                            throw;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Request failed, api: {0}, error: {1}", api, ex.Message);
                }
            }
        }