Beispiel #1
0
        public async Task <List <Pair> > GetAllPairsByQuoteCurrency(string quoteCurrency)
        {
            var pairs = new List <Pair>();

            using (var huobi = new HuobiClient())
            {
                var symbols = (await huobi.GetSymbolsAsync()).Data.Where(x => x.Symbol.ToLower().Contains(quoteCurrency.ToLower())).ToList();
                foreach (var huobiSymbol in symbols)
                {
                    if (huobiSymbol.State == HuobiSymbolState.Online)
                    {
                        var symbolDetails = await huobi.GetSymbolDetails24HAsync(huobiSymbol.Symbol);

                        if (symbolDetails.Data == null)
                        {
                            continue;
                        }

                        var pair = new Pair
                        {
                            TotalTradedQuoteAssetVolume = symbolDetails.Data.Volume.Value,
                            QuoteCurrency = quoteCurrency,
                            BaseCurrency  = ExtractBaseCurrency(huobiSymbol.Symbol, quoteCurrency)
                        };
                        pairs.Add(pair);
                    }
                }
            }
            return(pairs);
        }
Beispiel #2
0
        static async Task Main(string[] args)
        {
            // REST client
            using (var client = new HuobiClient())
            {
                // Public method
                var marketDetails = await client.GetSymbolDetails24HAsync("ethusdt");

                if (marketDetails.Success) // Check the success flag for error handling
                {
                    Console.WriteLine($"Got market stats, last price: {marketDetails.Data.Close}");
                }
                else
                {
                    Console.WriteLine($"Failed to get stats, error: {marketDetails.Error}");
                }

                // Private method
                client.SetApiCredentials("APIKEY", "APISECRET"); // Change to your credentials
                var accounts = await client.GetAccountsAsync();

                if (accounts.Success) // Check the success flag for error handling
                {
                    Console.WriteLine($"Got account list, account id #1: {accounts.Data.First().Id}");
                }
                else
                {
                    Console.WriteLine($"Failed to get account list, error: {accounts.Error}");
                }
            }

            Console.WriteLine("");
            Console.WriteLine("Press enter to continue to the socket client..");
            Console.ReadLine();

            // Socket client
            var socketClient = new HuobiSocketClient();
            await socketClient.SubscribeToKlineUpdatesAsync("ethusdt", HuobiPeriod.FiveMinutes, data =>
            {
                Console.WriteLine("Received kline update. Last price: " + data.Data.Close);
            });

            Console.ReadLine();
        }