Ejemplo n.º 1
0
        public override void GetSecurities()
        {
            string url = _urlBuilder.Build("/v1/common/symbols");

            var httpClient = new HttpClient();

            string response = httpClient.GetStringAsync(url).Result;

            OnSecurityEvent(_securityCreator.Create(response));
        }
Ejemplo n.º 2
0
        public override void GetSecurities()
        {
            string url = _urlBuilder.Build("/api/v1/contract_contract_info");

            var httpClient = new HttpClient();

            string response = httpClient.GetStringAsync(url).Result;

            OnSecurityEvent(CreateSecurities(response));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves all klines in a specific range.
        /// <para>Candlestick[] data</para>
        /// <para>string status</para>
        /// </summary>
        /// <param name="request"></param>
        /// <returns>GetCandlestickResponse</returns>
        public void GetCandlestickAsync(GetRequest request,
                                        System.Action <GetCandlestickResponse.Candlestick[], string> action)
        {
            string url = _urlBuilder.Build("/market/history/kline", request);

            HttpRequest.GetAsync <GetCandlestickResponse>(url).ContinueWith((task) => {
                var res = task.Result;
                action(res.data, res.status);
            });
        }
Ejemplo n.º 4
0
        public void Build_RequestParameter_Success()
        {
            var builder = new PublicUrlBuilder("api.huobi.pro");
            var request = new GetRequest()
                          .AddParam("symbol", "btcusdt")
                          .AddParam("period", "1min")
                          .AddParam("size", "1");

            string result = builder.Build("/market/history/kline", request);

            Assert.Equal("https://api.huobi.pro/market/history/kline?period=1min&size=1&symbol=btcusdt", result);
        }
Ejemplo n.º 5
0
        private List <Candle> GetCandles(int oldInterval, string security, DateTime startTime, DateTime endTime)
        {
            lock (_locker)
            {
                try
                {
                    var needIntervalForQuery = CandlesCreator.DetermineAppropriateIntervalForRequest(oldInterval, _supportedIntervals, out var needInterval);

                    var from = TimeManager.GetTimeStampSecondsToDateTime(startTime);
                    var to   = TimeManager.GetTimeStampSecondsToDateTime(endTime);

                    string timeStamp = TimeManager.GetUnixTimeStampSeconds().ToString();
                    var    headers   = new Dictionary <string, string>();
                    headers.Add("Timestamp", timeStamp);

                    RestRequestBuilder requestBuilder = new RestRequestBuilder();
                    requestBuilder.AddParam("contract", security);
                    requestBuilder.AddParam("from", from.ToString());
                    requestBuilder.AddParam("to", to.ToString());
                    requestBuilder.AddParam("interval", needIntervalForQuery);

                    PublicUrlBuilder urlBuilder = new PublicUrlBuilder(_host, _path, _wallet);

                    var candlesJson = _requestREST.SendGetQuery("GET", "", urlBuilder.Build("/candlesticks", requestBuilder), headers);

                    var candlesOut = JsonConvert.DeserializeObject <GfCandle[]>(candlesJson);

                    var oldCandles = CreateCandlesFromJson(candlesOut);

                    if (oldInterval == needInterval)
                    {
                        return(oldCandles);
                    }

                    var newCandles = CandlesCreator.CreateCandlesRequiredInterval(needInterval, oldInterval, oldCandles);

                    return(newCandles);
                }
                catch
                {
                    SendLogMessage(OsLocalization.Market.Message95 + security, LogMessageType.Error);

                    return(null);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// contract info
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="contractType"></param>
        /// <param name="contractCode"></param>
        /// <returns></returns>
        public async Task <GetContractInfoResponse> GetContractInfoAsync(string symbol = null, string contractType = null, string contractCode = null)
        {
            // location
            string location = "/api/v1/contract_contract_info";

            // option
            string option = null;

            if (symbol != null)
            {
                option += $"&symbol={symbol}";
            }
            if (contractType != null)
            {
                option += $"&contract_type={contractType}";
            }
            if (contractCode != null)
            {
                option += $"&contract_code={contractCode}";
            }
            if (option != null)
            {
                location += $"?{option.Substring(1)}";
            }

            string url = _urlBuilder.Build(location);

            return(await HttpRequest.GetAsync <GetContractInfoResponse>(url));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get all Huobi's supported trading symbol.
        /// </summary>
        /// <returns>GetSymbolsResponse</returns>
        public async Task <GetSymbolsResponse> GetSymbolsAsync()
        {
            string url = _urlBuilder.Build("/v1/common/symbols");

            return(await HttpRequest.GetAsync <GetSymbolsResponse>(url));
        }
        /// <summary>
        /// get contract info
        /// </summary>
        /// <param name="contractCode"></param>
        /// <returns></returns>
        public async Task <GetContractInfoResponse> GetContractInfoAsync(string contractCode = null)
        {
            // location
            string location = "/linear-swap-api/v1/swap_contract_info";

            // option
            string option = null;

            if (contractCode != null)
            {
                option += $"contract_code={contractCode}";
            }
            if (option != null)
            {
                location += $"?{option}";
            }

            string url = _urlBuilder.Build(location);

            return(await HttpRequest.GetAsync <GetContractInfoResponse>(url));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns current market status
        /// </summary>
        /// <returns>GetMarketStatusResponse</returns>
        public async Task <GetMarketStatusResponse> GetMarketStatusAsync()
        {
            string url = _urlBuilder.Build("/v2/market-status");

            return(await HttpRequest.GetAsync <GetMarketStatusResponse>(url));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Retrieves all klines in a specific range.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <GetKlineResponse> GetKlineAsync(GetRequest request)
        {
            string url = _urlBuilder.Build("/market/history/kline", request);

            return(await HttpRequest.GetAsync <GetKlineResponse>(url));
        }
Ejemplo n.º 11
0
        /// <summary>
        ///  get contract info
        /// </summary>
        /// <param name="contractCode"></param>
        /// <param name="businessType"></param>
        /// <param name="contractType"></param>
        /// <param name="pair"></param>
        /// <param name="tradePartition"></param>
        /// <returns></returns>
        public async Task <GetContractInfoResponse> GetContractInfoAsync(string contractCode   = null, string businessType = null,
                                                                         string contractType   = null, string pair         = null,
                                                                         string tradePartition = null)
        {
            // location
            string location = "/linear-swap-api/v1/swap_contract_info";

            // option
            string option = null;

            if (contractCode != null)
            {
                option += $"&contract_code={contractCode}";
            }
            if (businessType != null)
            {
                option += $"&business_type={businessType}";
            }
            if (contractType != null)
            {
                option += $"&contract_type={contractType}";
            }
            if (pair != null)
            {
                option += $"&pair={pair}";
            }
            if (tradePartition != null)
            {
                option += $"&trade_partition={tradePartition}";
            }
            if (option != null)
            {
                location += $"?{option.Substring(1)}";
            }

            string url = _urlBuilder.Build(location);

            return(await HttpRequest.GetAsync <GetContractInfoResponse>(url));
        }