示例#1
0
        public static IMarketResponse sendRequest(Request req)
        {
            switch (req.type)
            {
            case "buy":
                BuyRequest buyReq = (BuyRequest)req;
                return(comm.SendBuyRequest(buyReq.price, buyReq.commodity, buyReq.amount));

            case "sell":
                SellRequest sellReq = (SellRequest)req;
                //return comm.SendSellRequest(sellReq.price, sellReq.commodity, sellReq.amount);
                IMarketResponse resp = comm.SendSellRequest(sellReq.price, sellReq.commodity, sellReq.amount);
                return(resp);

            case "cancelBuySell":
                CancelRequest cancelReq = (CancelRequest)req;
                return(comm.SendCancelBuySellRequest(cancelReq.id));

            case "queryBuySell":
                QueryBuySellRequest queryReq = (QueryBuySellRequest)req;
                return(comm.SendQueryBuySellRequest(queryReq.id));

            case "queryMarket":
                QueryMarketRequest queryMarketReq = (QueryMarketRequest)req;
                return(comm.SendQueryMarketRequest(queryMarketReq.commodity));

            case "queryUser":
                //return comm.SendQueryUserRequest();
                IMarketResponse resp1 = comm.SendQueryUserRequest();
                return(resp1);

            default:
                return(null);
            }
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            QueryUserRequest req = new QueryUserRequest();
            IMarketResponse  res = InterperatorPB.sendRequest(req);

            textBox1.Text = res.ToString().Replace("\n", "\r\n");
            myLogger.Info("User clicked UPDATE STATUS");
        }
        public void TestCryptoCommUserQuery()
        {
            ICommunicator   comm = new Communicator();
            IMarketResponse resp = comm.SendQueryUserRequest();

            Assert.IsNotNull(resp);
            //Assert.IsInstanceOfType(resp, typeof(MQUser));
            Trace.Write($"Server response is: {resp}");
        }
示例#4
0
        private void button1_Click(object sender, EventArgs e)
        {
            int commodity          = (int)numericUpDown1.Value;
            QueryMarketRequest req = new QueryMarketRequest(commodity);
            IMarketResponse    res = InterperatorPB.sendRequest(req);

            MessageBox.Show(this, res.ToString());

            myLogger.Info("User clicked QUERY COMMODITY: {commodity: " + commodity + "}");
        }
        public void TestCryptoCommCommodityQuery()
        {
            //Communicator comm = new Communicator(Url, "wrongUser", PrivateKey);
            Communicator    comm = new Communicator();
            IMarketResponse resp = comm.SendQueryMarketRequest(1);

            Assert.IsNotNull(resp);
            //Assert.IsInstanceOfType(resp, typeof(MQCommodity));
            Trace.Write($"Server response is: {resp}");
        }
        public void TestCryptoCommCancelRequest()
        {
            //Communicator comm = new Communicator(Url, "wrongUser", PrivateKey);
            Communicator    comm = new Communicator();
            IMarketResponse resp = comm.SendCancelBuySellRequest(11);

            Assert.IsNotNull(resp);
            //Assert.AreEqual("Id not found", resp.ToString());
            Trace.Write($"Server response is: {resp}");
        }
        public void TestCryptoCommWrongUser()
        {
            Communicator comm = new Communicator(Url, "wrongUser", PrivateKey);

            IMarketResponse resp = comm.SendQueryUserRequest();

            Assert.IsNotNull(resp);
            //Assert.AreEqual("Bad user",resp.ToString());
            Trace.Write($"Server response is: {resp}");
        }
示例#8
0
        private void button1_Click(object sender, EventArgs e)
        {
            //show status
            int id = (int)numericUpDown1.Value;
            QueryBuySellRequest req = new QueryBuySellRequest(id);
            IMarketResponse     res = InterperatorPB.sendRequest(req);

            MessageBox.Show(this, res.ToString());

            myLogger.Info("User clicked QUERY REQUEST: {ID: " + id + "}");
        }
        public void TestCryptoCommBuyRequestAndCancel()
        {
            //Communicator comm = new Communicator(Url, "wrongUser", PrivateKey);
            Communicator comm = new Communicator();

            IMarketResponse resp = comm.SendBuyRequest(1, 1, 1);

            Assert.IsNotNull(resp);
            //Assert.IsInstanceOfType(resp, typeof(MBuySell));
            Trace.Write($"Server response is: {resp}");
        }
示例#10
0
 public CommStubStaticReturn()
 {
     this.buy          = null;
     this.sell         = null;
     this.cancel       = null;
     this.qbuysell     = null;
     this.qmarket      = null;
     this.quser        = null;
     this.qAllmarket   = null;
     this.qAllrequests = null;
 }
示例#11
0
        private void button1_Click(object sender, EventArgs e)
        {
            //cancel
            int             id  = (int)numericUpDown1.Value;
            CancelRequest   req = new CancelRequest(id);
            IMarketResponse res = InterperatorPB.sendRequest(req);

            MessageBox.Show(this, res.ToString());

            myLogger.Info("User clicked CANCEL: {ID: " + id + "}");
        }
示例#12
0
        public object run(LogicProcess process)
        {
            IMarketResponse response = process.comm.SendQueryBuySellRequest(process.id);
            bool            success  = (response.getType() != ResponseType.qReq);

            if (!success)
            {
                process.id = -1;
            }

            next(process, success);
            return(response);
        }
示例#13
0
        static void Main()
        {
            mainAction action = mainAction.
                                normal;


            if (action == mainAction.normal)
            {
                Interperator interp = new PrimInterperator(new DefaultLoginInfo());
                Display.Welcome();

                while (true)
                {
                    String cmd = Console.ReadLine();
                    Console.WriteLine(interp.Interperate(cmd));
                }
            }
            else if (action == mainAction.test)
            {
                /** AMA test **/

                Console.WriteLine("We are a'go!");
                AMA testAMA = new DefaultAMA(new Communicator());
                //AMA testAMA = new DefaultAMA(new TestMarketCommunicator());
                testAMA.enable(true);

                System.Threading.Thread.Sleep(10000 * 3);
                testAMA.enable(false);
                Console.WriteLine("Done");
            }
            else
            {
                /** Comm test**/

                ICommunicator comm = new TestMarketCommunicator();
                //ICommunicator comm = new Communicator();


                IMarketResponse resp = comm.SendQueryUserRequest();
                Console.WriteLine(resp.ToString());


                resp = comm.SendQueryMarketRequest(1);
                Console.WriteLine(resp.ToString());



                String cmd = Console.ReadLine();
            }
        }
示例#14
0
 public CommStubStaticReturn(IMarketResponse buy, IMarketResponse sell,
                             IMarketResponse cancel, IMarketResponse qbuysell,
                             IMarketResponse qmarket, IMarketResponse quser,
                             List <MQCommodityWrapper> qAllmarket, List <MQReqWrapper> qAllrequests)
 {
     this.buy          = buy;
     this.sell         = sell;
     this.cancel       = cancel;
     this.qbuysell     = qbuysell;
     this.qmarket      = qmarket;
     this.quser        = quser;
     this.qAllmarket   = qAllmarket;
     this.qAllrequests = qAllrequests;
 }
示例#15
0
        public object run(LogicProcess process)
        {
            bool            success  = false;
            IMarketResponse response = process.comm.SendSellRequest(process.price, process.commodity, process.amount);

            if (response.getType() == ResponseType.buySell)
            {
                success = true;
                MBuySell resp = (MBuySell)response;
                process.id = resp.getID();
            }
            next(process, success);
            return(response);
        }
示例#16
0
        private void button1_Click(object sender, EventArgs e)
        {
            //send

            int             commodity = (int)numericUpDown1.Value;
            int             amount    = (int)numericUpDown2.Value;
            int             price     = (int)numericUpDown3.Value;
            BuyRequest      req       = new BuyRequest(commodity, amount, price);
            IMarketResponse res       = InterperatorPB.sendRequest(req);

            MessageBox.Show(this, res.ToString());

            myLogger.Info("User clicked BUY: {commodity: " + commodity + ", price: " + price + ", amount: " + amount + "}");
        }
示例#17
0
        public object run(LogicProcess process)
        {
            bool success = false;

            IMarketResponse response = process.comm.SendQueryMarketRequest(process.commodity);

            if (response.getType() == ResponseType.qCommodity)
            {
                MQCommodity resp = (MQCommodity)response;
                success = resp.getAsk() <= resp.getBid();
                next(process, success);
            }
            return(response);
        }
示例#18
0
        public object run(LogicProcess process)
        {
            bool            success  = false;
            IMarketResponse response = process.comm.SendQueryUserRequest();

            if (response.getType() == ResponseType.qUser)
            {
                MQUser resp = (MQUser)response;
                Dictionary <string, int> commodityList = resp.getCommodities();
                int currAmount = commodityList[process.commodity.ToString()];
                success = (currAmount > 0);
            }
            next(process, success);
            return(response);
        }
示例#19
0
        public override bool runAction(AlgoProcess list)
        {
            //Attempt to buy the commodity
            bool            success  = false;
            IMarketResponse response = list.comm.SendBuyRequest(list.buyPrice,
                                                                list.commodity, list.amount);

            //If buy request is succssful - update the buyRequestID of the list
            if (response.getType() == ResponseType.buySell)
            {
                success = true;
                MBuySell resp = (MBuySell)response;
                list.buyRequestID = resp.getID();
            }
            return(success);
        }
示例#20
0
        public override bool runAction(AlgoProcess list)
        {
            if (list.buyRequestID == -1)
            {
            }

            IMarketResponse response = list.comm.SendSellRequest(list.sellPrice,
                                                                 list.commodity, list.amount);

            //Currently not in use, but might be useful
            if (response.getType() == ResponseType.buySell)
            {
                MBuySell resp = (MBuySell)response;
                list.sellRequestID = resp.getID();
            }
        }
示例#21
0
        public object run(LogicProcess process)
        {
            bool success = false;

            IMarketResponse response = process.comm.SendQueryMarketRequest(process.commodity);

            //myLogger.Info("BidCompare: Sent query");

            if (response.getType() == ResponseType.qCommodity)
            {
                MQCommodity resp = (MQCommodity)response;
                success = resp.getBid() >= process.price;
                next(process, success);
            }
            return(response);
        }
示例#22
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog();
            dialog.FileName   = "Current Status";             // Default file name
            dialog.DefaultExt = ".pdf";                       // Default file extension
            dialog.Filter     = "PDF documents (.pdf)|*.pdf"; // Filter files by extension

            // Show open file dialog box
            Nullable <bool> result = dialog.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                // Open document
                string res = dialog.FileName;

                var doc1 = new Document();
                PdfWriter.GetInstance(doc1, new FileStream(res, FileMode.Create));

                QueryUserRequest       req1  = new QueryUserRequest();
                IMarketResponse        resp1 = InterperatorPB.sendRequest(req1);
                QueryAllBuySellRequest req2  = new QueryAllBuySellRequest();
                List <MQReqWrapper>    resp2 = InterperatorPB.sendAllUserRequest();

                doc1.Open();
                doc1.Add(new iTextSharp.text.Paragraph("CURRENT USER STATUS:"));
                doc1.Add(new iTextSharp.text.Paragraph("\n"));
                doc1.Add(new iTextSharp.text.Paragraph(resp1.ToString()));
                doc1.Add(new iTextSharp.text.Paragraph("\n"));

                if (!(resp2 == null))
                {
                    foreach (var element in resp2)
                    {
                        doc1.Add(new iTextSharp.text.Paragraph(element.ToString()));
                    }
                }

                doc1.Close();

                myLogger.Info("User Export status report");
            }
        }
示例#23
0
        public bool runAction(AlgoProcess process)
        {
            //Get available amount from process
            IDictionary <string, int> userCommodities = process.agent.userData.getCommodities();
            string commodity = process.commodity.ToString();
            int    amount    = userCommodities[commodity];

            //Calculate the buy price:
            //currentAsk + priceBuffer
            int priceBuffer = -1;
            int currentBid  = 0;

            //Find currentBid by using the data from the AMA
            bool foundPrice = false;

            for (int i = 0; i <= 9 & !foundPrice; i++)
            {
                MQCommodityWrapper current = process.agent.commoditiesInfo[i];
                if (current.id == process.commodity)
                {
                    foundPrice = true;
                    currentBid = current.getBid();
                }
            }

            int price = currentBid + priceBuffer;

            //Send request
            bool            success  = false;
            IMarketResponse response = process.comm.SendSellRequest(price, process.commodity, amount);

            if (response.getType() == ResponseType.buySell)
            {
                success = true;
                MBuySell resp = (MBuySell)response;
                process.requestID = resp.getID();
            }
            return(success);
        }
示例#24
0
        public bool runAction(AlgoProcess process)
        {
            //Calculate the buy price:
            //currentAsk + priceBuffer
            int priceBuffer = 1;
            int currentAsk  = 0;

            //Find currentAsk by using the data from the AMA
            bool foundPrice = false;

            for (int i = 0; i <= 9 & !foundPrice; i++)
            {
                MQCommodityWrapper current = process.agent.commoditiesInfo[i];
                if (current.id == process.commodity)
                {
                    foundPrice = true;
                    currentAsk = current.getAsk();
                }
            }

            //calculate price and amount
            double funds          = process.agent.userData.funds;
            double availableFunds = (int)((funds / 100) * fundsPercentage);
            int    price          = currentAsk + priceBuffer;

            int amount = (int)(availableFunds / price);

            //Send request
            bool            success  = false;
            IMarketResponse response = process.comm.SendBuyRequest(price, process.commodity, amount);

            if (response.getType() == ResponseType.buySell)
            {
                success = true;
                MBuySell resp = (MBuySell)response;
                process.requestID = resp.getID();
            }
            return(success);
        }