示例#1
0
        public async Task <T> GetOneCallApiAsync <T>(double lat, double lon, string lang, OneCallExclude[] exclude = null, string units = "metric", string accessToken = null, string version = "2.5")
        {
            var args = new NameValueDictionary
            {
                { "lat", lat.ToString(CultureInfo.InvariantCulture) },
                { "lon", lon.ToString(CultureInfo.InvariantCulture) },
                { "lang", lang },
                { "units", units },
            };

            if (exclude != null)
            {
                string exludeStr = String.Empty;
                foreach (OneCallExclude exlud in exclude)
                {
                    exludeStr += exlud.ToString() + ",";
                }

                args.Add("exclude", exludeStr.ToString());
            }

            if (accessToken == null)
            {
                args.Add("appid", m_accessKey.ToString(CultureInfo.InvariantCulture));
            }
            else if (accessToken != null)
            {
                args.Add("appid", accessToken.ToString(CultureInfo.InvariantCulture));
            }

            return(await CallApiAsync <T>($"/data/{version}/onecall", RequestType.Get, args).ConfigureAwait(false));
        }
示例#2
0
        /// <summary>
        /// Requires at least 'Developer' plan API subscription.
        /// https://openweathermap.org/api/hourly-forecast
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="lat"></param>
        /// <param name="lon"></param>
        /// <param name="lang"></param>
        /// <param name="numHours">Default or <=0 to get the max, >0 to get a set number of hourly forecasts.</param>
        /// <param name="units"></param>
        /// <param name="accessToken"></param>
        /// <param name="version"></param>
        /// <returns></returns>
        public async Task <T> GetHourlyForecastApiAsync <T>(double lat, double lon, string lang, int numHours = 0, string units = "metric", string accessToken = null, string version = "2.5")
        {
            var args = new NameValueDictionary
            {
                { "lat", lat.ToString(CultureInfo.InvariantCulture) },
                { "lon", lon.ToString(CultureInfo.InvariantCulture) },
                { "lang", lang },
                { "units", units },
            };

            if (numHours > 0)
            {
                args["cnt"] = numHours.ToString();
            }

            if (accessToken == null)
            {
                args.Add("appid", m_accessKey.ToString(CultureInfo.InvariantCulture));
            }
            else if (accessToken != null)
            {
                args.Add("appid", accessToken.ToString(CultureInfo.InvariantCulture));
            }

            return(await CallApiAsync <T>($"/data/{version}/forecast/hourly", RequestType.Get, args).ConfigureAwait(false));
        }
示例#3
0
        private static string GetSignature(NameValueDictionary args, string secretKey)
        {
            var sb = new StringBuilder();

            foreach (var arg in args)
            {
                sb.Append(arg.Key);
                sb.Append("=");
                sb.Append(arg.Value);
                sb.Append("&");
            }

            sb.Append("secret_key=");
            sb.Append(secretKey);

            using (var md = MD5.Create())
            {
                using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(sb.ToString())))
                {
                    var hashData = md.ComputeHash(stream);

                    // Format as hexadecimal string.
                    var hashBuilder = new StringBuilder();
                    foreach (byte data in hashData)
                    {
                        hashBuilder.Append(data.ToString("x2", CultureInfo.InvariantCulture));
                    }
                    return(hashBuilder.ToString().ToUpperInvariant());
                }
            }
        }
示例#4
0
    public WebResponse(HttpWebRequest request, HttpWebResponse response)
    {
      _requestContentType = request == null ? null : request.ContentType;
      _response = response;
      _headers = new NameValueDictionary(response == null
        ? new System.Collections.Specialized.NameValueCollection()
        : response.Headers);

      _content = new MemoryStream();
      if (_response != null)
      {
        using (var stream = _response.GetResponseStream())
        {
          stream.CopyTo(_content);
        }
        _content.Position = 0;
        _response.Close();
      }

#if !NET4
      if (request.CookieContainer != null && response.Cookies.Count > 0)
      {
        request.CookieContainer.BugFix_CookieDomain();
      }
#endif
    }
示例#5
0
        // Releases the escrow of contact specified by ID { contact_id }.
        // On success there"s a complimentary message on the data key.
        public async Task <dynamic> ContactReleasePin(string contactId, string pincode)
        {
            var args = new NameValueDictionary
            {
                { "pincode", pincode },
            };

            return(await CallApiAsync("/api/contact_release_pin/" + contactId + "/", RequestType.Post, args).ConfigureAwait(false));
        }
示例#6
0
        // Checks the given PIN code against the user"s currently active PIN code.
        // You can use this method to ensure the person using the session is the legitimate user.
        public async Task <dynamic> CheckPinCode(string code)
        {
            var args = new NameValueDictionary
            {
                { "code", code },
            };

            return(await CallApiAsync("/api/pincode/", RequestType.Post, args).ConfigureAwait(false));
        }
示例#7
0
        // Checks the given PIN code against the user"s currently active PIN code.
        // You can use this method to ensure the person using the session is the legitimate user.
        public dynamic CheckPinCode(string code)
        {
            var args = new NameValueDictionary
            {
                { "code", code },
            };

            return(CallApi("/api/pincode/", RequestType.Post, args));
        }
示例#8
0
        // contacts is a comma-separated list of contact IDs that you want to access in bulk.
        // The token owner needs to be either a buyer or seller in the contacts, contacts that do not pass this check are simply not returned.
        // A maximum of 50 contacts can be requested at a time.
        // The contacts are not returned in any particular order.
        public async Task <dynamic> GetContactsInfo(string contacts)
        {
            var args = new NameValueDictionary
            {
                { "contacts", contacts },
            };

            return(await CallApiAsync("/api/contact_info/", RequestType.Get, args).ConfigureAwait(false));
        }
示例#9
0
        // contacts is a comma-separated list of contact IDs that you want to access in bulk.
        // The token owner needs to be either a buyer or seller in the contacts, contacts that do not pass this check are simply not returned.
        // A maximum of 50 contacts can be requested at a time.
        // The contacts are not returned in any particular order.
        public dynamic GetContactsInfo(string contacts)
        {
            var args = new NameValueDictionary
            {
                { "contacts", contacts },
            };

            return(CallApi("/api/contact_info/", RequestType.Get, args));
        }
示例#10
0
        private string Query(string methodName)
        {
            var args = new NameValueDictionary
            {
                { "method", methodName },
            };

            return(InternalQuery(args));
        }
示例#11
0
        // Releases the escrow of contact specified by ID { contact_id }.
        // On success there"s a complimentary message on the data key.
        public dynamic ContactReleasePin(string contactId, string pincode)
        {
            var args = new NameValueDictionary
            {
                { "pincode", pincode },
            };

            return(CallApi("/api/contact_release_pin/" + contactId + "/", RequestType.Post, args));
        }
示例#12
0
        // Sends amount bitcoins from the token owner"s wallet to address.
        // Note that this API requires its own API permission called Money.
        // On success, this API returns just a message indicating success.
        // It is highly recommended to minimize the lifetime of access tokens with the money permission.
        // Call / api / logout / to make the current token expire instantly.
        public dynamic WalletSend(decimal amount, string address)
        {
            var args = new NameValueDictionary
            {
                { "amount", amount.ToString(CultureInfo.InvariantCulture) },
                { "address", address },
            };

            return(CallApi("/api/wallet-send/", RequestType.Post, args));
        }
示例#13
0
        // Sends amount bitcoins from the token owner"s wallet to address.
        // Note that this API requires its own API permission called Money.
        // On success, this API returns just a message indicating success.
        // It is highly recommended to minimize the lifetime of access tokens with the money permission.
        // Call / api / logout / to make the current token expire instantly.
        public async Task <dynamic> WalletSend(decimal amount, string address)
        {
            var args = new NameValueDictionary
            {
                { "amount", amount.ToString(CultureInfo.InvariantCulture) },
                { "address", address },
            };

            return(await CallApiAsync("/api/wallet-send/", RequestType.Post, args).ConfigureAwait(false));
        }
示例#14
0
        public bool CancelOrder(int orderId)
        {
            var args = new NameValueDictionary
            {
                { "id", orderId.ToString(CultureInfo.InvariantCulture) }
            };
            var json   = Query("cancel_order", args);
            var result = DeserializeBitstampObject <bool>(json);

            return(result);
        }
示例#15
0
        public dynamic NewInvoice(string currency_code, decimal amount, string description, string return_url)
        {
            var args = new NameValueDictionary
            {
                { "currency", currency_code },
                { "amount", amount.ToString(CultureInfo.InvariantCulture) },
                { "description", description },
                { "return_url", return_url },
            };

            return(CallApi("/api/merchant/new_invoice/", RequestType.Post, args));
        }
示例#16
0
        private dynamic CallApiPostFile(string apiCommand, NameValueDictionary args, string fileName)
        {
            using (var httpContent = new MultipartFormDataContent())
            {
                if (args != null)
                {
                    foreach (var keyValuePair in args)
                    {
                        httpContent.Add(new StringContent(keyValuePair.Value),
                                        string.Format(CultureInfo.InvariantCulture, "\"{0}\"", keyValuePair.Key));
                    }
                }

                if (fileName != null)
                {
                    var fileBytes = File.ReadAllBytes(fileName);
                    httpContent.Add(new ByteArrayContent(fileBytes), "\"document\"",
                                    "\"" + Path.GetFileName(fileName) + "\"");
                }

                var bodyAsBytes = httpContent.ReadAsByteArrayAsync().Result;

                var nonce     = GetCurrentUnixTimestampMillis().ToString(CultureInfo.InvariantCulture);
                var signature = GetSignatureBinary(apiCommand, nonce, bodyAsBytes);

                using (var request = new HttpRequestMessage(
                           HttpMethod.Post,
                           new Uri(m_client.BaseAddress, apiCommand)
                           ))
                {
                    request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    request.Headers.Add("Apiauth-Key", m_accessKey);
                    request.Headers.Add("Apiauth-Nonce", nonce);
                    request.Headers.Add("Apiauth-Signature", signature);
                    request.Content = httpContent;

                    var response = m_client.SendAsync(request).Result;
                    if (!response.IsSuccessStatusCode)
                    {
                        var resultAsString = response.Content.ReadAsStringAsync().Result;
                        var json           = JsonConvert.DeserializeObject <dynamic>(resultAsString);
                        throw new LocalBitcoinsException(true, apiCommand, json);
                    }

                    {
                        var resultAsString = response.Content.ReadAsStringAsync().Result;
                        var json           = JsonConvert.DeserializeObject <dynamic>(resultAsString);
                        return(json);
                    }
                }
            }
        }
示例#17
0
        public async Task <T> GetFiveDayForecastApiAsync <T>(string cityName, string lang, string units = "metric", string version = "2.5")
        {
            var args = new NameValueDictionary
            {
                { "q", cityName },
                { "lang", lang },
                { "units", units },
            };

            args.Add("appid", m_accessKey.ToString(CultureInfo.InvariantCulture));

            return(await CallApiAsync <T>($"/data/{version}/forecast", RequestType.Get, args).ConfigureAwait(false));
        }
示例#18
0
        public TradeAnswer Sell(decimal price, decimal amount)
        {
            var args = new NameValueDictionary
            {
                { "amount", DecimalToString(amount) },
                { "price", DecimalToString(price) },
            };

            var json   = Query("sell", args);
            var answer = DeserializeBitstampObject <TradeAnswer>(json);

            return(answer);
        }
示例#19
0
        // Attempts to create a contact to trade bitcoins.
        // Amount is a number in the advertisement"s fiat currency.
        // Returns the API URL to the newly created contact at actions.contact_url.
        // Whether the contact was able to be funded automatically is indicated at data.funded.
        // Only non-floating LOCAL_SELL may return unfunded, all other trade types either fund or fail.
        public dynamic CreateContact(string contactId, decimal amount, string message = null)
        {
            var args = new NameValueDictionary
            {
                { "amount", amount.ToString(CultureInfo.InvariantCulture) },
            };

            if (message != null)
            {
                args.Add("message", message);
            }

            return(CallApi("/api/contact_create/" + contactId + "/", RequestType.Post, args));
        }
示例#20
0
        // Starts a dispute with the contact, if possible.
        // You can provide a short description using topic. This helps support to deal with the problem.
        public dynamic StartDispute(string contactId, string topic = null)
        {
            NameValueDictionary args = null;

            if (topic != null)
            {
                args = new NameValueDictionary
                {
                    { "topic", topic },
                };
            }

            return(CallApi("/api/contact_dispute/" + contactId + "/", RequestType.Post, args));
        }
示例#21
0
        // Attempts to create a contact to trade bitcoins.
        // Amount is a number in the advertisement"s fiat currency.
        // Returns the API URL to the newly created contact at actions.contact_url.
        // Whether the contact was able to be funded automatically is indicated at data.funded.
        // Only non-floating LOCAL_SELL may return unfunded, all other trade types either fund or fail.
        public async Task <dynamic> CreateContact(string contactId, decimal amount, string message = null)
        {
            var args = new NameValueDictionary
            {
                { "amount", amount.ToString(CultureInfo.InvariantCulture) },
            };

            if (message != null)
            {
                args.Add("message", message);
            }

            return(await CallApiAsync("/api/contact_create/" + contactId + "/", RequestType.Post, args).ConfigureAwait(false));
        }
示例#22
0
        // Gives feedback to user.
        // Possible feedback values are: trust, positive, neutral, block, block_without_feedback as strings.
        // You may also set feedback message field with few exceptions. Feedback block_without_feedback clears the message and with block the message is mandatory.
        public dynamic PostFeedbackToUser(string userName, string feedback, string message = null)
        {
            var args = new NameValueDictionary
            {
                { "feedback", feedback },
            };

            if (message != null)
            {
                args.Add("msg", message);
            }

            return(CallApi("/api/feedback/" + userName + "/", RequestType.Post, args));
        }
示例#23
0
        // Starts a dispute with the contact, if possible.
        // You can provide a short description using topic. This helps support to deal with the problem.
        public async Task <dynamic> StartDispute(string contactId, string topic = null)
        {
            NameValueDictionary args = null;

            if (topic != null)
            {
                args = new NameValueDictionary
                {
                    { "topic", topic },
                };
            }

            return(await CallApiAsync("/api/contact_dispute/" + contactId + "/", RequestType.Post, args).ConfigureAwait(false));
        }
示例#24
0
        // Gives feedback to user.
        // Possible feedback values are: trust, positive, neutral, block, block_without_feedback as strings.
        // You may also set feedback message field with few exceptions. Feedback block_without_feedback clears the message and with block the message is mandatory.
        public async Task <dynamic> PostFeedbackToUser(string userName, string feedback, string message = null)
        {
            var args = new NameValueDictionary
            {
                { "feedback", feedback },
            };

            if (message != null)
            {
                args.Add("msg", message);
            }

            return(await CallApiAsync("/api/feedback/" + userName + "/", RequestType.Post, args).ConfigureAwait(false));
        }
示例#25
0
        public CancelOrderAnswer CancelOrder(int orderId)
        {
            var args = new NameValueDictionary
            {
                { "order_id", orderId.ToString(CultureInfo.InvariantCulture) }
            };
            var result = JObject.Parse(Query("CancelOrder", args));

            if (result.Value <int>("success") == 0)
            {
                throw new WexApiException(result.Value <string>("error"));
            }

            return(CancelOrderAnswer.ReadFromJObject(result["return"] as JObject));
        }
示例#26
0
        static string BuildPostData(NameValueDictionary d)
        {
            var s = new StringBuilder();

            foreach (var key in d.Keys)
            {
                var value = d[key];
                s.AppendFormat("{0}={1}", key, WebUtility.UrlEncode(value));
                s.Append("&");
            }
            if (s.Length > 0)
            {
                s.Remove(s.Length - 1, 1);
            }
            return(s.ToString());
        }
示例#27
0
        public TradeAnswer Trade(WexPair pair, TradeType type, decimal rate, decimal amount)
        {
            var args = new NameValueDictionary
            {
                { "pair", WexPairHelper.ToString(pair) },
                { "type", TradeTypeHelper.ToString(type) },
                { "rate", DecimalToString(rate) },
                { "amount", DecimalToString(amount) }
            };
            var result = JObject.Parse(Query("Trade", args));

            if (result.Value <int>("success") == 0)
            {
                throw new WexApiException(result.Value <string>("error"));
            }
            return(TradeAnswer.ReadFromJObject(result["return"] as JObject));
        }
示例#28
0
        public TradeHistory GetTradeHistory(
            int?from       = null,
            int?count      = null,
            int?fromId     = null,
            int?endId      = null,
            bool?orderAsc  = null,
            DateTime?since = null,
            DateTime?end   = null
            )
        {
            var args = new NameValueDictionary();

            if (from != null)
            {
                args.Add("from", from.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (count != null)
            {
                args.Add("count", count.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (fromId != null)
            {
                args.Add("from_id", fromId.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (endId != null)
            {
                args.Add("end_id", endId.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (orderAsc != null)
            {
                args.Add("order", orderAsc.Value ? "ASC" : "DESC");
            }
            if (since != null)
            {
                args.Add("since", UnixTime.GetFromDateTime(since.Value).ToString(CultureInfo.InvariantCulture));
            }
            if (end != null)
            {
                args.Add("end", UnixTime.GetFromDateTime(end.Value).ToString(CultureInfo.InvariantCulture));
            }

            var json   = Query("TradeHistory", args);
            var result = DeserializeBtceObject <TradeHistory>(json);

            return(result);
        }
示例#29
0
        // Post a message to contact
        public dynamic PostMessageToContact(string contactId, string message, string attachFileName = null)
        {
            if (attachFileName != null && !File.Exists(attachFileName))
            {
                throw new LocalBitcoinsException("PostMessageToContact", "File not found: " + attachFileName);
            }

            NameValueDictionary args = null;

            if (!string.IsNullOrEmpty(message))
            {
                args = new NameValueDictionary
                {
                    { "msg", message },
                };
            }

            return(CallApiPostFile("/api/contact_message_post/" + contactId + "/", args, attachFileName));
        }
示例#30
0
        public async Task <T> GetCurrentWeatherAsync <T>(string cityName, string lang, string units = "metric", string accessToken = null, string version = "2.5")
        {
            var args = new NameValueDictionary
            {
                { "q", cityName },
                { "lang", lang },
                { "units", units },
            };

            if (accessToken == null)
            {
                args.Add("appid", m_accessKey.ToString(CultureInfo.InvariantCulture));
            }
            else if (accessToken != null)
            {
                args.Add("appid", accessToken.ToString(CultureInfo.InvariantCulture));
            }

            return(await CallApiAsync <T>($"/data/{version}/weather/", RequestType.Get, args).ConfigureAwait(false));
        }
示例#31
0
        public OrderList ActiveOrders(WexPair?pair = null)
        {
            var args = new NameValueDictionary();

            if (pair != null)
            {
                args.Add("pair", WexPairHelper.ToString(pair.Value));
            }

            var json = Query("ActiveOrders", args);

            if (json.Contains("\"no orders\""))
            {
                return(new OrderList());
            }

            var result = DeserializeBtceObject <OrderList>(json);

            return(result);
        }