Exemplo n.º 1
0
        public int SendBuyRequest(int price, int commodity, int amount)// The buy request function using the BuyRequest class
        {
            SimpleHTTPClient HTTPClient = new SimpleHTTPClient();
            BuyRequest       request    = new BuyRequest();

            request.type      = "buy";
            request.price     = price;
            request.commodity = commodity;
            request.amount    = amount;
            myNonce           = randomNonce();
            string token    = SimpleCryptoLibrary.CreateToken(user + "_" + myNonce, PrivateKey);
            bool   eflag    = false;
            string response = "";

            try
            {
                String s = SimpleCryptoLibrary.decrypt(myNonce, PrivateKey);
                Convert.ToInt32(s);
            }
            catch (Exception d)
            {
                if (d.ToString().Equals("non unique nonce"))
                {
                    myNonce = randomNonce();
                    String s = SimpleCryptoLibrary.decrypt(myNonce, PrivateKey);
                }
            }
            try
            {
                response = HTTPClient.SendPostRequest(url, user, token, myNonce, PrivateKey, request);
                Convert.ToInt32(response);
            }
            catch (Exception e)
            {
                error = response;
                eflag = true;
            }
            if (!eflag)
            {
                int output = Convert.ToInt32(response);
                logger.Info("A buy request was sent to the server for commodity id " + commodity + ", amount " + amount + ", in the price of " + price + ". The buy was succesful, the request ID was " + output);
                return(output);
            }

            else
            {
                logger.Error("A buy request was sent to the server for commodity id " + commodity + ", amount " + amount + ", in the price of " + price + ". An error occurred: " + error);
                return(-1);
            }
        }
Exemplo n.º 2
0
        public IMarketCommodityOffer SendQueryMarketRequest(int commodity) //The query market request function using the QueryMarketRequest class and returning a IMarketCommodityOffer object
        {
            SimpleHTTPClient   HTTPClient = new SimpleHTTPClient();
            QueryMarketRequest request    = new QueryMarketRequest();

            request.type      = "queryMarket";
            request.commodity = commodity;
            myNonce           = randomNonce();
            string token = SimpleCryptoLibrary.CreateToken(user + "_" + myNonce, PrivateKey);
            MarketCommodityOffer response = null;
            bool eflag = false;

            try
            {
                String s = SimpleCryptoLibrary.decrypt(myNonce, PrivateKey);
                Convert.ToInt32(s);
            }
            catch (Exception d)
            {
                if (d.ToString().Equals("non unique nonce"))
                {
                    myNonce = randomNonce();
                    String s = SimpleCryptoLibrary.decrypt(myNonce, PrivateKey);
                }
            }
            try
            {
                response = HTTPClient.SendPostRequest <QueryMarketRequest, MarketCommodityOffer>(url, user, token, myNonce, PrivateKey, request);
            }
            catch (Exception e)
            {
                error = e.Message;
                eflag = true;
            }
            if (eflag)
            {
                logger.Error("A query market request was sent to the server for commodity ID " + commodity + ". An error occurred: " + error);
                return(null);
            }

            else
            {
                logger.Info("A query market request was sent to the server for commodity ID " + commodity + ". The response from the server was: " + response);
                return(response);
            }
        }
Exemplo n.º 3
0
        public List <MarketUserRequests> SendUserRequestsQuery()
        {
            SimpleHTTPClient  HTTPClient = new SimpleHTTPClient();
            UserRequestsQuery request    = new UserRequestsQuery();

            request.type = "queryUserRequests";
            myNonce      = randomNonce();
            string token = SimpleCryptoLibrary.CreateToken(user + "_" + myNonce, PrivateKey);
            List <MarketUserRequests> response = new List <MarketUserRequests>();
            bool eflag = false;

            try
            {
                String s = SimpleCryptoLibrary.decrypt(myNonce, PrivateKey);
                Convert.ToInt32(s);
            }
            catch (Exception d)
            {
                if (d.ToString().Equals("non unique nonce"))
                {
                    myNonce = randomNonce();
                    String s = SimpleCryptoLibrary.decrypt(myNonce, PrivateKey);
                }
            }
            try
            {
                response = HTTPClient.SendPostRequest <UserRequestsQuery, List <MarketUserRequests> >(url, user, token, myNonce, PrivateKey, request);
            }
            catch (Exception e)
            {
                error = e.Message;
                eflag = true;
            }
            if (eflag)
            {
                logger.Error("The server received a SendUserRequestsQuery request. An error occurred: " + error);
                return(null);
            }

            else
            {
                logger.Info("The server received a SendUserRequestsQuery request.");
                return(response);
            }
        }
Exemplo n.º 4
0
        public bool SendCancelBuySellRequest(int id) // The cancel request function using the CancelRequest class
        {
            SimpleHTTPClient HTTPClient = new SimpleHTTPClient();
            CancelRequest    request    = new CancelRequest();

            request.type = "cancelBuySell";
            request.id   = id;
            myNonce      = randomNonce();
            string token    = SimpleCryptoLibrary.CreateToken(user + "_" + myNonce, PrivateKey);
            string response = HTTPClient.SendPostRequest(url, user, token, myNonce, PrivateKey, request);

            if (response.Equals("Ok"))
            {
                logger.Info("A cancel request was sent to the server for ID " + id + ". Successfully canceled.");
                return(true);
            }

            else
            {
                error = response;
                logger.Error("A cancel request was sent to the server for ID " + id + ". An error occurred: " + error);
                return(false);
            }
        }