Пример #1
0
 public static int MaxAutoBuyPrice(string class_instance, string lang, string apikey, SteamTrade.SteamWeb steamWeb)
 {
     //https://csgo.tm/api/ItemInfo/520025252_0/en/?key=dzrux9i3SpWyQS5eXZcoBSrN5P5BSvy  //in json properties get autoBuyOffers
     string requestLink = string.Format("https://csgo.tm/api/ItemInfo/{0}/{1}/?key={2}", class_instance, lang, apikey);
     dynamic jsonItemInfo = steamWeb.Fetch(requestLink, "GET", null, false, null);
     var price = jsonItemInfo.buy_offers[0].o_price;
     return 0;
 }
Пример #2
0
 public static string GetItemInfo(string class_instance, string lang, string apikey, SteamTrade.SteamWeb steamWeb)
 {
     string requestLink = string.Format("https://csgo.tm/api/ItemInfo/{0}/{1}/?key={2}", class_instance, lang, apikey);
     string response = steamWeb.Fetch(requestLink, "GET", null, false, null);
     if (response.Contains("error"))
     {
         throw new CsgotmException(response);
     }
     return response;
 }
Пример #3
0
 public static int GetMaxAutoBuyPriceForItem(ItemInSQL itemInSql, string lang, string apikey, SteamTrade.SteamWeb steamWeb)
 {
     //https://csgo.tm/api/ItemInfo/520025252_0/en/?key=  //in json properties get autoBuyOffers
     string requestLink = string.Format("https://csgo.tm/api/ItemInfo/{0}/{1}/?key={2}", itemInSql.ClassInstance, lang, apikey);
     string jsonItemInfo = steamWeb.Fetch(requestLink, "GET", null, false, null);
     dynamic deserializedResponse = JsonConvert.DeserializeObject(jsonItemInfo);
     int price = deserializedResponse.buy_offers[0].o_price;
     return price;
 }
Пример #4
0
        public static Boolean SetAutoBuy(ItemInSQL itemInSql, string apiKey, SteamTrade.SteamWeb steamWeb)
        {
            if (itemInSql.CanBuy == 1)
            {
                String deserializedResponse;
                string lang = "en"; //needed for some requests
                //TODO I'm inserting a new AutoBuyPrice, but can't change.
                //calculating new price for ItemInSQL
                int currentMaxAutoBuyPrice = GetMaxAutoBuyPriceForItem(itemInSql, lang, apiKey, steamWeb); //100
                int newPrice;
                if (currentMaxAutoBuyPrice < itemInSql.MinPriceBuy)
                {
                    newPrice = itemInSql.MinPriceBuy;
                }
                else if (currentMaxAutoBuyPrice < itemInSql.MaxPriceBuy)
                {
                    newPrice = currentMaxAutoBuyPrice + 1;
                }
                else
                {
                    newPrice = itemInSql.MaxPriceBuy;
                }
                //trying to update price for ItemInSQL
                string updateLink = string.Format("https://csgo.tm/api/UpdateOrder/{0}/{1}/{2}/?key={3}",
                    itemInSql.GetItemClass(), itemInSql.GetItemInstance(), newPrice, apiKey);

                string updateJsonResponse = steamWeb.Fetch(updateLink, "GET", null, false, null);
                deserializedResponse = JsonConvert.DeserializeObject(updateJsonResponse).ToString();
                //if couldn't find the order in base - create a new one.
                if (deserializedResponse.ToString().Contains("Данная заявка на покупку не найдена"))
                {
                    string insertLink = string.Format("https://csgo.tm/api/InsertOrder/{0}/{1}/{2}/{3}/?key={4}",
                        itemInSql.GetItemClass(), itemInSql.GetItemInstance(), newPrice, itemInSql.Hash, apiKey);
                    string insertJsonResponse = steamWeb.Fetch(insertLink, "GET", null, false, null);
                    deserializedResponse = JsonConvert.DeserializeObject(insertJsonResponse).ToString();
                    if (deserializedResponse.Contains("true"))
                    {
                        Console.WriteLine("A new autobuy order for ItemInSQL " + itemInSql.ItemName +
                                          " was created successfully!" +
                                          " Price: " + (double) newPrice/100 + " руб.");
                        return true;
                    }
                    else if (deserializedResponse.Contains("Неверно задана цена покупки"))
                    {
                        Console.WriteLine("Wrong price for " +itemInSql.ItemName + "! Check the prices for buying in database!");
                        return false;
                    }
                    Console.WriteLine("For item: " + itemInSql.ItemName);
                    Console.WriteLine(deserializedResponse);
                }
                else if (deserializedResponse.ToString().Contains("недостаточно средств на счету"))
                {
                    Console.WriteLine("Autobuy false. For " + itemInSql.ItemName +
                                      " - not enough funds in wallet! Пополните кошелек!");
                    return false;
                }
                else if (deserializedResponse.ToString().Contains("true"))
                {
                    Console.WriteLine("Autobuy price for " + itemInSql.ItemName + " was updated successfully! New price: " +
                                      (double) newPrice/100 + " руб.");
                    return true;
                }
                //TODO
                Console.WriteLine("We should never reach here." +
                                  " A new error ");
            }
            return false;
        }
Пример #5
0
        public Boolean LoginToCsgotm(SteamTrade.SteamWeb steamWeb)
        {
            try
            {
                String response = steamWeb.Fetch("https://csgo.tm/login/", "GET", null, false, "https://csgo.tm/");

                /*csgo.tm redirects us to Openid-Steam-login page, where we must imitate pression of "sign in" button. For it, on
            Openid-Steam-login page Steam gives us special data - nonce, which is a one-time-used key for login. And openidparams -
            seems as public RSA-key, but not sure. We need to retreive it from response and post it to the link below.
            */

                NameValueCollection postData = new NameValueCollection();
                String nonce = GetAttributeFromResponse(response, "nonce");
                String openidparams = GetAttributeFromResponse(response, "openidparams");
                postData.Add("action", "steam_openid_login");
                postData.Add("openid.mode", "checkid_setup");
                postData.Add("openidparams", openidparams);
                postData.Add("nonce", nonce);
                steamWeb.Fetch("https://steamcommunity.com/openid/login", "POST", postData, false, null);
                Log.Success("Logged in successfully");
                return true;
                //here we're loggining
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                return false;
            }
        }