Exemplo n.º 1
0
        /// <summary>
        /// Constructor of order creation.
        /// </summary>
        /// <param name="user"> Exmo exchange user</param>
        /// <param name="pair"> currency pair</param>
        /// <param name="quantity"> quantity for the order</param>
        /// <param name="price"> price for the order</param>
        /// <param name="type"> type of order, can have the following values
        /// buy - buy order
        /// sell - sell order
        /// market_buy - market buy-order
        /// market_sell - market sell-order
        /// market_buy_total - market buy-order for a certain amount
        /// market_sell_total - market sell-order for a certain amount
        /// </param>
        public Order_Create(User user, string pair, double quantity, double price, string type)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "pair", pair }, { "quantity", quantity.ToString().Replace(",", ".") },
                { "price", price.ToString().Replace(",", ".") }, { "type", type.ToString() }
            };
            JObject jObject = (JObject)ExmoAPI.GetJSONObject("order_create", parameters, user);

            if (jObject.ContainsKey("result"))
            {
                RequestSucceed = Convert.ToBoolean(jObject["result"]);
            }
            else
            {
                RequestSucceed = false;
                RequestError   = "Unexpected server answer.";
                return;
            }
            if (jObject.ContainsKey("error"))
            {
                RequestError = jObject["error"].ToString();
            }
            if (jObject.ContainsKey("order_id"))
            {
                order_id = jObject["order_id"].ToString();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor of information about user's account.
        /// </summary>
        /// <param name="user"> Exmo exchange user</param>
        /// <remarks> User marked as ref for ID field filling</remarks>
        public User_Info(ref User user)
        {
            JObject jObject = (JObject)ExmoAPI.GetJSONObject(
                "user_info", new Dictionary <string, string>(), user);

            if (!CheckResult(ref jObject))
            {
                uid = RequestError;
                return;
            }

            user.userID = uid = jObject.ContainsKey("uid") ?
                                jObject["uid"].ToString() : "";
            server_date = jObject.ContainsKey("server_date") ?
                          Convert.ToInt64(jObject["server_date"].ToString()) : 0;

            if (jObject.ContainsKey("balances"))
            {
                balances = JsonConvert.DeserializeObject <Dictionary <string, double> >
                               (jObject["balances"].ToString());
            }
            if (jObject.ContainsKey("reserved"))
            {
                reserved = JsonConvert.DeserializeObject <Dictionary <string, double> >
                               (jObject["reserved"].ToString());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructor of order cancellation.
        /// </summary>
        /// <param name="pair"> currency pair</param>
        /// <param name="quantity"> quantity to buy</param>
        public Required_Amount(string pair, double quantity)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "pair", pair }, { "quantity", quantity.ToString().Replace(',', '.') }
            };
            JObject jObject = (JObject)ExmoAPI.GetJSONObject(
                "required_amount", parameters, new User("", ""));

            if (!CheckResult(ref jObject))
            {
                return;
            }

            if (jObject.ContainsKey("quantity"))
            {
                quantity = Convert.ToDouble(jObject["quantity"]);
            }
            if (jObject.ContainsKey("amount"))
            {
                amount = Convert.ToDouble(jObject["amount"]);
            }
            if (jObject.ContainsKey("avg_price"))
            {
                avg_price = Convert.ToDouble(jObject["avg_price"]);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Currency list constructor.
        /// </summary>
        public Currency()
        {
            JToken jArray = ExmoAPI.GetJSONObject("currency");

            if (jArray is JArray)
            {
                currencies = jArray.ToObject <List <string> >();
            }
            else
            {
                JObject jObject = (JObject)jArray;
                if (jObject.ContainsKey("result"))
                {
                    RequestSucceed = Convert.ToBoolean(jObject["result"]);
                }
                else
                {
                    RequestSucceed = false;
                }
                if (jObject.ContainsKey("error"))
                {
                    RequestError = jObject["error"].ToString();
                }
                foreach (KeyValuePair <string, JToken> item in jObject)
                {
                    currencies.Add(item.ToString());
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor of the list of user’s cancelled orders.
        /// </summary>
        /// <param name="user"> Exmo exchange user</param>
        /// <param name="limit"> the number of returned deals (default: 100, мmaximum: 10 000)</param>
        /// <param name="offset"> last deal offset (default: 0)</param>
        public User_Cancelled_Orders(User user, int limit = 100, int offset = 0)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "limit", limit.ToString() }, { "offset", offset.ToString() }
            };
            JToken jArray = ExmoAPI.GetJSONObject("user_cancelled_orders",
                                                  parameters, user);

            if (jArray is JArray)
            {
                userCancelledOrders = jArray.ToObject <List <Order> >();
            }
            else
            {
                JObject jObject = (JObject)jArray;
                if (jObject.ContainsKey("result"))
                {
                    RequestSucceed = Convert.ToBoolean(jObject["result"]);
                }
                else
                {
                    RequestSucceed = false;
                }
                if (jObject.ContainsKey("error"))
                {
                    RequestError = jObject["error"].ToString();
                }
                foreach (var item in jObject)
                {
                    userCancelledOrders.Add(new Order(item.ToString()));
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Constructor of the list of user’s active orders.
        /// </summary>
        /// <param name="user"> Exmo exchange user</param>
        public User_Open_Orders(User user)
        {
            JObject jObject = (JObject)ExmoAPI.GetJSONObject("user_open_orders",
                                                             new Dictionary <string, string>(), user);

            if (!CheckResult(ref jObject))
            {
                userOpenOrders.Add(jObject.First.ToString(),
                                   new List <Order> {
                    new Order(RequestError)
                });
                return;
            }
            foreach (var pair in jObject)
            {
                try
                {
                    List <Order> ordersList =
                        JsonConvert.DeserializeObject <List <Order> >(pair.Value.ToString(),
                                                                      new JsonSerializerSettings {
                        ContractResolver = OrderDataContractResolver.Instance
                    });
                    userOpenOrders.Add(pair.Key, ordersList);
                }
                catch (Exception ex)
                {
                    userOpenOrders.Add(ex.Message, new List <Order>());
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Constructor of the list of addresses for cryptocurrency deposit.
        /// </summary>
        /// <param name="user"> Exmo exchange user</param>
        public Deposit_Address(User user)
        {
            JObject jObject = (JObject)ExmoAPI.GetJSONObject(
                "deposit_address", new Dictionary <string, string>(), user);

            if (!CheckResult(ref jObject))
            {
                depositAddress.Add(RequestError, jObject.Last.ToString());
                return;
            }
            foreach (var pair in jObject)
            {
                depositAddress.Add(pair.Key, pair.Value.ToString());
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Constructor of the list of user’s deals.
        /// </summary>
        /// <param name="user"> Exmo exchange user</param>
        /// <param name="pairs"> one or various currency pairs separated by commas (example: BTC_USD,BTC_EUR)</param>
        /// <param name="limit"> the number of returned deals (default: 100, мmaximum: 10 000)</param>
        /// <param name="offset"> last deal offset (default: 0)</param>
        public User_Trades(User user, List <string> pairs, int limit = 100, int offset = 0)
        {
            if (pairs == null)
            {
                RequestSucceed = false;
                RequestError   = "Pair is not specified.";
                return;
            }

            string pairsString = "";
            int    counter     = 0;

            foreach (string pair in pairs)
            {
                pairsString += pair;
                if (++counter != pairs.Count)
                {
                    pairsString += ",";
                }
            }
            Dictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "pair", pairsString }, { "limit", limit.ToString() }, { "offset", offset.ToString() }
            };
            JObject jObject = (JObject)ExmoAPI.GetJSONObject("user_trades", parameters, user);

            if (!CheckResult(ref jObject))
            {
                userTrades.Add(jObject.First.ToString(),
                               new List <Order> {
                    new Order(RequestError)
                });
                return;
            }
            foreach (string pair in pairs)
            {
                try
                {
                    List <Order> pairOrders =
                        JsonConvert.DeserializeObject <List <Order> >(jObject[pair].ToString());
                    userTrades.Add(pair, pairOrders);
                }
                catch (Exception ex)
                {
                    userTrades.Add(pair + ": " + ex.Message, new List <Order>());
                };
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Trades constructor with incoming list of pairs.
        /// </summary>
        public Trades(List <string> pairs, int limit = 100)
        {
            if (pairs == null)
            {
                RequestSucceed = false;
                RequestError   = "Pair is not specified.";
                return;
            }

            string request = "trades/?pair=";
            int    counter = 0;

            foreach (string pair in pairs)
            {
                request += pair;
                if (++counter != pairs.Count)
                {
                    request += ",";
                }
            }
            request += "&limit=" + limit;

            JObject jObject = (JObject)ExmoAPI.GetJSONObject(request);

            if (!CheckResult(ref jObject))
            {
                trades.Add(RequestError, new List <Trade>());
                return;
            }

            foreach (string pair in pairs)
            {
                try
                {
                    List <Trade> pairTrades =
                        JsonConvert.DeserializeObject <List <Trade> >(jObject[pair].ToString());
                    trades.Add(pair, pairTrades);
                }
                catch (Exception ex)
                {
                    trades.Add(pair + ": " + ex.Message, new List <Trade>());
                };
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Constructor of order history.
        /// </summary>
        /// <param name="user"> Exmo exchange user</param>
        /// <param name="order_id"> order identifier</param>
        public Order_Trades(User user, string order_id)
        {
            JObject jObject = (JObject)ExmoAPI.GetJSONObject("order_trades",
                                                             new Dictionary <string, string> {
                { "order_id", order_id }
            }, user);

            if (!CheckResult(ref jObject))
            {
                orderTrade.type = RequestError;
                return;
            }
            try
            {
                orderTrade = JsonConvert.DeserializeObject <Trade>(jObject.ToString());
            }
            catch (Exception ex)
            {
                orderTrade.type = ex.Message;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Ticker constructor.
        /// </summary>
        public Ticker()
        {
            JObject jObject = (JObject)ExmoAPI.GetJSONObject("ticker/");

            if (!CheckResult(ref jObject))
            {
                ticker.Add(RequestError, new Tick());
                return;
            }

            foreach (var pair in jObject)
            {
                try
                {
                    Tick pairTick = JsonConvert.DeserializeObject <Tick>(pair.Value.ToString());
                    ticker.Add(pair.Key, pairTick);
                }
                catch (Exception ex)
                {
                    ticker.Add(pair + ": " + ex.Message, new Tick());
                };
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Constructor of order cancellation request.
        /// </summary>
        /// <param name="user"> Exmo exchange user</param>
        /// <param name="order_id"> order identifier</param>
        public Order_Cancel(User user, string order_id)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "order_id", order_id }
            };
            JObject jObject = (JObject)ExmoAPI.GetJSONObject("order_cancel", parameters, user);

            if (jObject.ContainsKey("result"))
            {
                RequestSucceed = Convert.ToBoolean(jObject["result"]);
            }
            else
            {
                RequestSucceed = false;
                RequestError   = "Unexpected server answer.";
                return;
            }
            if (jObject.ContainsKey("error"))
            {
                RequestError = jObject["error"].ToString();
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Pair_Settings constructor.
        /// </summary>
        public Pair_Settings()
        {
            JObject jObject = (JObject)ExmoAPI.GetJSONObject("pair_settings/");

            if (!CheckResult(ref jObject))
            {
                pair_settings.Add(RequestError, new Settings());
                return;
            }

            foreach (var pair in jObject)
            {
                try
                {
                    Settings pairSettings =
                        JsonConvert.DeserializeObject <Settings>(pair.Value.ToString());
                    pair_settings.Add(pair.Key, pairSettings);
                }
                catch (Exception ex)
                {
                    pair_settings.Add(pair + ": " + ex.Message, new Settings());
                };
            }
        }