Ejemplo n.º 1
0
        /// <summary>
        /// Sends a rquest for sale of given amount of commodities for given price.
        /// </summary>
        /// <param name="price">The price offer for the sale</param>
        /// <param name="commodity">The commodity id</param>
        /// <param name="amount">The amount of commodities up for sale</param>
        /// <returns>A request id of the sale</returns>
        public int SendSellRequest(int price, int commodity, int amount)
        {
            SimpleHTTPClient client   = new SimpleHTTPClient();
            SellRequest      request  = new SellRequest("sell", commodity, amount, price);
            string           token    = SimpleCtyptoLibrary.CreateToken(User, PrivateKey);
            string           response = client.SendPostRequest(Url, User, token, request);
            int a;

            if (!int.TryParse(response, out a))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                if (response == "Bad commodity")
                {
                    throw (new MarketException("The request relates to a non existing commodity Id."));
                }
                if (response == "Insufficient commodity")
                {
                    throw (new MarketException("Not enough  amount of commodity to complete the sell."));
                }
            }

            Console.ForegroundColor = ConsoleColor.Green;
            int id = int.Parse(response);

            Console.WriteLine("You have successfully sold the commodities, here is your request Id: " + id);
            Console.ResetColor();
            return(id);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Offers best Bid price and best Ask price for a given commodity.
        /// </summary>
        /// <param name="commodity">The wanted commidity id.</param>
        /// <returns>Prints the best bid price and best ask price for given commodity.</returns>
        public IMarketCommodityOffer SendQueryMarketRequest(int commodity)
        {
            SimpleHTTPClient      client   = new SimpleHTTPClient();
            QueryMarket           request  = new QueryMarket("queryMarket", commodity);
            string                token    = SimpleCtyptoLibrary.CreateToken(User, PrivateKey);
            IMarketCommodityOffer response = client.SendPostRequest <QueryMarket, MarketCommodityOffer>(Url, User, token, request);

            return(response);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Describes a Sell/Purchase by given request id.
        /// </summary>
        /// <param name="id">The request id of the Purchase/Sell</param>
        /// <returns>Prints a description of the wanted Purchase/Sell, including information such as: commodity, price, amount, username and request type.</returns>
        public IMarketItemQuery SendQueryBuySellRequest(int id)
        {
            SimpleHTTPClient    client  = new SimpleHTTPClient();
            QueryBuySellRequest request = new QueryBuySellRequest(id, "queryBuySell");
            string           token      = SimpleCtyptoLibrary.CreateToken(User, PrivateKey);
            IMarketItemQuery response   = client.SendPostRequest <QueryBuySellRequest, MarketItemQuery>(Url, User, token, request);

            return(response);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Describes user information, including inventory, funds and active request ID's description.
        /// </summary>
        /// <returns>Prints a description of user information, including inventory, funds and active request ID's</returns>
        public IMarketUserData SendQueryUserRequest()
        {
            SimpleHTTPClient client   = new SimpleHTTPClient();
            QueryUser        request  = new QueryUser("queryUser");
            string           token    = SimpleCtyptoLibrary.CreateToken(User, PrivateKey);
            IMarketUserData  response = client.SendPostRequest <QueryUser, MarketUserData>(Url, User, token, request);

            return(response);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Canceles a buy/sell by refunding commodity/funds.
        /// </summary>
        /// <param name="id">The request id of the purchase/sell.</param>
        /// <returns>A boolean type variable validating the cancel.</returns>
        public bool SendCancelBuySellRequest(int id)
        {
            SimpleHTTPClient     client  = new SimpleHTTPClient();
            CancelBuySellRequest request = new CancelBuySellRequest("cancelBuySell", id);
            string token    = SimpleCtyptoLibrary.CreateToken(User, PrivateKey);
            string response = client.SendPostRequest(Url, User, token, request);

            int a;

            if (!int.TryParse(response, out a))
            {
                if (response == "Id not found")
                {
                    throw (new MarketException("The request ID was not found."));
                }
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("You have successfully canceled the request.");
            Console.ResetColor();
            return(true);
        }