예제 #1
0
        /// <summary>
        /// Return the basic information of ETF creation and redemption, as well as ETF constituents
        /// </summary>
        /// <returns>GetETFInfoResponse</returns>
        public async Task <GetETFInfoResponse> GetETFInfoAsync()
        {
            var request = new GetRequest()
                          .AddParam("etf_name", ETF_NAME);
            string url = _urlBuilder.Build(GET_METHOD, "/etf/swap/config", request);

            return(await HttpRequest.GetAsync <GetETFInfoResponse>(url));
        }
예제 #2
0
        /// <summary>
        /// Get stable coin quote
        /// </summary>
        /// <param name="currency">Stable coin name (USDT/PAX/USDC/TUSD)</param>
        /// <param name="amount">Amount of stable coin to exchange (the value must be an intger)</param>
        /// <param name="type">Type of the exchange (buy/sell)</param>
        /// <returns>GetStableCoinResponse</returns>
        public async Task <GetStableCoinResponse> GetStableCoinAsync(string currency, string amount, string type)
        {
            var request = new GetRequest()
                          .AddParam("currency", currency)
                          .AddParam("amount", amount)
                          .AddParam("type", type);
            string url = _urlBuilder.Build(GET_METHOD, "/v1/stable-coin/quote", request);

            return(await HttpRequest.GetAsync <GetStableCoinResponse>(url));
        }
        /// <summary>
        /// Transfer specific asset from spot trading account to cross margin account
        /// </summary>
        /// <param name="currency">The currency to transfer</param>
        /// <param name="amount">The amount of currency to transfer</param>
        /// <returns>TransferResponse</returns>
        public async Task <TransferResponse> TransferIn(string currency, string amount)
        {
            string url = _urlBuilder.Build(POST_METHOD, "/v1/cross-margin/transfer-in");

            string body = $"{{ \"currency\":\"{currency}\", \"amount\":\"{amount}\" }}";

            return(await HttpRequest.PostAsync <TransferResponse>(url, body));
        }
예제 #4
0
        private async void PortfolioRequester(CancellationToken token)
        {
            try
            {
                string url = _privateUriBuilder.Build("GET", "/v1/account/accounts");

                var httpClient = new HttpClient();

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

                Portfolios = new List <Portfolio>();

                GetAccountInfoResponse accountInfo = JsonConvert.DeserializeObject <GetAccountInfoResponse>(response);

                foreach (var info in accountInfo.data)
                {
                    var portfolio = new Portfolio();
                    portfolio.Number       = info.type + "_" + info.id;
                    portfolio.ValueBegin   = 1;
                    portfolio.ValueCurrent = 1;
                    portfolio.ValueBlocked = 1;

                    Portfolios.Add(portfolio);
                }

                OnPortfolioEvent(Portfolios);

                while (!token.IsCancellationRequested)
                {
                    try
                    {
                        await Task.Delay(5000, token);

                        GetPortfolios();
                    }
                    catch (TaskCanceledException)
                    {
                        return;
                    }
                    catch (Exception exception)
                    {
                        SendLogMessage("MessageReader error: " + exception, LogMessageType.Error);
                    }
                }
            }
            catch (Exception e)
            {
                SendLogMessage(e.ToString(), LogMessageType.Error);
            }
        }
예제 #5
0
        /// <summary>
        /// Returns a list of accounts owned by this API user
        /// <para>AccountInfo[] data</para>
        /// <para>string status</para>
        /// </summary>
        /// <returns>GetAccountInfoResponse</returns>
        public void GetAccountInfoAsync(System.Action <GetAccountInfoResponse.AccountInfo[], string> action = null)
        {
            string url = _urlBuilder.Build(GET_METHOD, "/v1/account/accounts");

            HttpRequest.GetAsync <GetAccountInfoResponse>(url).ContinueWith((task) => {
                if (action != null)
                {
                    var res = task.Result;
                    action(res.data, res.status);
                }
            });
        }
예제 #6
0
        public void Build_NoRequestParameter_Success()
        {
            var    builder = new PrivateUrlBuilder("abcdefg-hijklmn-opqrst-uvwxyz", "12345-67890-12345-67890", "api.huobi.pro");
            string result  = builder.Build("GET", "/v1/account/accounts");

            string expected = @"https://api.huobi.pro/v1/account/accounts?AccessKeyId=abcdefg-hijklmn-opqrst-uvwxyz&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2020-04-01T12%3A34%3A56&Signature=3IUZcEak4IIRrh7%2FidFrP2Jj77MaWGXR%2FoQbe9gL4%2BI%3D";

            Assert.Equal(expected, result);
        }
예제 #7
0
        public override void GetPortfolios()
        {
            if (Portfolios == null)
            {
                return;
            }
            foreach (var portfolio in Portfolios)
            {
                string url = _privateUriBuilder.Build("POST", "/swap-api/v1/swap_account_info");

                StringContent httpContent = new StringContent(new JsonObject().ToString(), Encoding.UTF8, "application/json");

                var httpClient = new HttpClient();

                var response = httpClient.PostAsync(url, httpContent).Result;

                string result = response.Content.ReadAsStringAsync().Result;

                if (result.Contains("Incorrect Access key"))
                {
                    SendLogMessage("Huobi: Incorrect Access API key", LogMessageType.Error);
                    return;
                }

                FuturesAccountInfo accountInfo = JsonConvert.DeserializeObject <FuturesAccountInfo>(result);

                portfolio.ClearPositionOnBoard();

                for (int i = 0; accountInfo.data != null && i < accountInfo.data.Count; i++)
                {
                    var currentData = accountInfo.data[i];

                    PositionOnBoard pos = new PositionOnBoard();
                    pos.SecurityNameCode = currentData.symbol;
                    pos.ValueBegin       = currentData.margin_available;
                    pos.ValueCurrent     = currentData.margin_available;
                    pos.ValueBlocked     = currentData.margin_frozen;

                    portfolio.SetNewPosition(pos);
                }
            }

            OnPortfolioEvent(Portfolios);
        }
예제 #8
0
        /// <summary>
        /// transfer
        /// </summary>
        /// <param name="currency"></param>
        /// <param name="amount"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public async Task <TransferResponse> TransferAsync(string currency, double amount, string type)
        {
            // ulr
            string url = _urlBuilder.Build(POST_METHOD, "/v1/futures/transfer");

            // content
            string content = $"{{ \"currency\":\"{currency}\", \"amount\":{amount}, \"type\":\"{type}\" }}";

            return(await HttpRequest.PostAsync <TransferResponse>(url, content));
        }
        /// <summary>
        /// transfer coin betwee spot and ***-USDT linear swap
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="amount"></param>
        /// <param name="marginAccount"></param>
        /// <param name="currency"></param>
        /// <returns></returns>
        public async Task <TransferResponse> TransferAsync(string from, string to, string currency, double amount)
        {
            // ulr
            string url = _urlBuilder.Build(POST_METHOD, "/v2/account/transfer");

            // content
            string content = $"{{ \"from\":\"{from}\", \"to\":\"{to}\", \"currency\":\"{currency}\", \"amount\":{amount} }}";

            return(await HttpRequest.PostAsync <TransferResponse>(url, content));
        }
예제 #10
0
        public void Build_NoRequestParameter_Success()
        {
            var      builder  = new PrivateUrlBuilder("access", "secret", "api.huobi.pro");
            DateTime dateTime = new DateTime(2019, 11, 21, 10, 0, 0);


            string result = builder.Build("GET", "/v1/account/accounts", dateTime);


            string escapedTime = Uri.EscapeDataString(dateTime.ToString("s"));
            string expected    = string.Format(@"https://api.huobi.pro/v1/account/accounts?AccessKeyId=access&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp={0}&Signature=rWnLcMt3XBAsmXoNHtTQVpvMbH%2FcE1PXFwQAGeYwt3s%3D",
                                               escapedTime);

            Assert.Equal(expected, result);
        }
예제 #11
0
        /// <summary>
        /// Get deposit address of corresponding chain, for a specific crypto currency (except IOTA)
        /// <para>Address[] data</para>
        /// <para>int code //Status code</para>
        /// <para>string message //Error message (if any)</para>
        /// </summary>
        /// <param name="request"></param>
        /// <returns>GetDepositAddressResponse</returns>
        public void GetDepositAddressAsync(GetRequest request,
                                           System.Action <GetDepositAddressResponse.Address[], int, string> action)
        {
            string url = _urlBuilder.Build(GET_METHOD, "/v2/account/deposit/address", request);

            HttpRequest.GetAsync <GetDepositAddressResponse>(url).ContinueWith((task) => {
                var res = task.Result;
                action(res.data, res.code, res.message);
            });
        }
        public void Build_RequestParameter_Success()
        {
            var      builder  = new PrivateUrlBuilder("access", "secret", "api.huobi.pro");
            DateTime dateTime = new DateTime(2019, 11, 21, 10, 0, 0);
            var      request  = new GetRequest()
                                .AddParam("account-id", "123")
                                .AddParam("currency", "btc");


            string result = builder.Build("GET", "/v1/account/history", dateTime, request);


            string escapedTime = Uri.EscapeDataString(dateTime.ToString("s"));
            string expected    = string.Format(@"https://api.huobi.pro/v1/account/history?AccessKeyId=access&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp={0}&account-id=123&currency=btc&Signature=SGZYJ9Ub%2FhFerEBbSWsCxl8Djk%2BLRBgEZOB4fLc4T9Q%3D",
                                               escapedTime);

            Assert.Equal(expected, result);
        }
예제 #13
0
        /// <summary>
        /// Place a new order and send to the exchange to be matched.
        /// </summary>
        /// <param name="request"></param>
        /// <returns>PlaceOrderResponse</returns>
        public async Task <PlaceOrderResponse> PlaceOrderAsync(PlaceOrderRequest request)
        {
            string url = _urlBuilder.Build(POST_METHOD, "/v1/order/orders/place");

            return(await HttpRequest.PostAsync <PlaceOrderResponse>(url, request.ToJson()));
        }
예제 #14
0
        /// <summary>
        /// Place a new order and send to the exchange to be matched.
        /// </summary>
        /// <param name="request"></param>
        /// <returns>PlaceOrderResponse</returns>
        public async Task <PlaceOrderResponse> PlaceOrderAsync(PlaceOrderRequest request)
        {
            string url = _urlBuilder.Build(POST_METHOD, "/swap-api/v1/swap_trigger_order");

            return(await HttpRequest.PostAsync <PlaceOrderResponse>(url, JsonConvert.SerializeObject(request)));
        }
        /// <summary>
        /// Place a new order and send to the exchange to be matched.
        /// <para>string data // Order id</para>
        /// <para>string errorCode</para>
        /// <para>string errorMessage</para>
        /// </summary>
        /// <param name="request"></param>
        /// <returns>PlaceOrderResponse</returns>
        public void PlaceOrderAsync(PlaceOrderRequest request,
                                    System.Action <string, string, string> action = null)
        {
            string url = _urlBuilder.Build(POST_METHOD, "/v1/order/orders/place");

            HttpRequest.PostAsync <PlaceOrderResponse>(url, request.ToJson()).ContinueWith((task) => {
                if (action != null)
                {
                    var res = task.Result;
                    action(res.data, res.errorCode, res.errorMessage);
                }
            });
        }
예제 #16
0
        /// <summary>
        /// The parent user creates sub users
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <CreateSubUserResponse> CreateSubUserAsync(CreateSubUserRequest request)
        {
            string url = _urlBuilder.Build(POST_METHOD, "/v2/sub-user/creation");

            return(await HttpRequest.PostAsync <CreateSubUserResponse>(url, request.ToJson()));
        }
예제 #17
0
        /// <summary>
        /// get balance valuation
        /// </summary>
        /// <param name="valuationAsset"></param>
        /// <returns></returns>
        public async Task <GetBalanceValuationResponse> GetBalanceValuationAsync(string valuationAsset = null)
        {
            // ulr
            string url = _urlBuilder.Build(POST_METHOD, "/linear-swap-api/v1/swap_balance_valuation");

            // content
            string content = null;

            if (valuationAsset != null)
            {
                content = $",\"valuation_asset\": \"{valuationAsset}\"";
            }
            if (content != null)
            {
                content = $"{{ {content.Substring(1)} }}";
            }
            return(await HttpRequest.PostAsync <GetBalanceValuationResponse>(url, content));
        }
예제 #18
0
        /// <summary>
        /// isolated switch position mode
        /// </summary>
        /// <param name="marginAccount"></param>
        /// <param name="positionMode"></param>
        /// <returns></returns>
        public async Task <PositionModeResponse> IsolatedSwitchPositionModeAsync(string marginAccount, string positionMode)
        {
            // url
            string url = _urlBuilder.Build(POST_METHOD, "/linear-swap-api/v1/swap_switch_position_mode");

            // content
            string content = "";

            if (marginAccount != null)
            {
                content += $",\"margin_account\": \"{marginAccount}\"";
            }
            if (positionMode != null)
            {
                content += $",\"position_mode\": \"{positionMode}\"";
            }

            if (content != null)
            {
                content = $"{{ {content.Substring(1)} }}";
            }

            return(await HttpRequest.PostAsync <PositionModeResponse>(url, content));
        }
예제 #19
0
        /// <summary>
        /// Returns a list of accounts owned by this API user
        /// </summary>
        /// <returns>GetAccountInfoResponse</returns>
        public async Task <GetAccountInfoResponse> GetAccountInfoAsync()
        {
            string url = _urlBuilder.Build(GET_METHOD, "/v1/account/accounts");

            return(await HttpRequest.GetAsync <GetAccountInfoResponse>(url));
        }
예제 #20
0
        /// <summary>
        /// Get deposit address of corresponding chain, for a specific crypto currency (except IOTA)
        /// </summary>
        /// <param name="request"></param>
        /// <returns>GetDepositAddressResponse</returns>
        public async Task <GetDepositAddressResponse> GetDepositAddressAsync(GetRequest request)
        {
            string url = _urlBuilder.Build(GET_METHOD, "/v2/account/deposit/address", request);

            return(await HttpRequest.GetAsync <GetDepositAddressResponse>(url));
        }
예제 #21
0
        /// <summary>
        /// The user get the UID
        /// </summary>
        /// <returns></returns>
        public async Task <GetUIDResponse> GetUIDAsync()
        {
            string url = _urlBuilder.Build(GET_METHOD, "/v2/user/uid");

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