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); }
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(); }
public async Task <PlaceOrderResult> PlaceOrder(Pair pair, decimal amountToBuyInQuoteCurrency) { var result = new PlaceOrderResult(); using (var huobi = new HuobiClient()) { var accounts = await huobi.GetAccountsAsync(); var response = await huobi.PlaceOrderAsync(accounts.Data.Single().Id, ToHuobiSymbol(pair.QuoteCurrency, pair.BaseCurrency), HuobiOrderType.MarketBuy, amountToBuyInQuoteCurrency); if (response.Success) { result.Message = $"Market Buy Order placed. ID: {response.Data}"; result.Success = true; } else { result.Message = $"Error while placing Order: {response.Error?.Message}"; } } return(result); }
public Huobi(Keys settings) { HuobiClient.SetDefaultOptions(new HuobiClientOptions { ApiCredentials = new ApiCredentials(settings.ApiKeyHuobi, settings.SecretHuobi) }); }