示例#1
0
        public static async Task <bool> VerifyRecaptchaResponse(string secretKey, string response,
                                                                string remoteIp = null)
        {
            if (secretKey.IsNotNullOrEmpty() && response.IsNotNullOrEmpty())
            {
                using (var rest = new Rest(GoogleSiteVerifyUrl))
                {
                    rest.Add("secret", secretKey);
                    rest.Add("response", response);
                    if (remoteIp.IsNotNullOrEmpty())
                    {
                        rest.Add("remoteip", remoteIp);
                    }

                    var result = await rest.PostAsync <ReCaptchaVerificationResult>();

                    if (result?.ErrorCodes?.Length > 0)
                    {
                        foreach (var error in result.ErrorCodes)
                        {
                            switch (error)
                            {
                            case "missing-input-secret":
                                rest.LogError("The secret parameter is missing.");
                                break;

                            case "invalid-input-secret":
                                rest.LogError(" The secret parameter is invalid or malformed.");
                                break;

                            case "missing-input-response":
                                rest.LogError("The response parameter is missing.");
                                break;

                            case "invalid-input-response":
                                rest.LogError("The response parameter is invalid or malformed.");
                                break;

                            case "bad-request":
                                rest.LogError("The request is invalid or malformed.");
                                break;
                            }
                        }
                    }

                    return(result?.Success == true);
                }
            }

            return(false);
        }
示例#2
0
        public async Task <IOrder> ExecuteOrderAsync(OrderType orderType, string exchangeCurrency, string targetCurrency,
                                                     decimal amount,
                                                     decimal price)
        {
            var path    = "/orders";
            var content = new
            {
                type       = "limit",
                side       = orderType == OrderType.Buy ? "buy" : "sell",
                product_id = $"{exchangeCurrency}-{targetCurrency}",
                price,
                size          = amount,
                time_in_force = "GTC"
            };

            PrepareRequest(HttpMethod.Post, path, content.JsonSerialize());
            Rest.Add(content);
            return((await Rest.PostAsync <string>(path)).JsonDeserialize <GdaxOrder>());
        }
        private void PrepareRest(object values)
        {
            var v = values?.JsonSerialize()?.JsonDeserialize <Dictionary <string, string> >();

            v?.ToList()?.ForEach(item => Rest.Add(item.Key, item.Value));
        }