예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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();
            }
        }
예제 #4
0
        public IMarketResponse SendSellRequest(int price, int commodity, int amount)
        {
            SellRequest sellReq        = new SellRequest(commodity, amount, price); //create and define sell request
            MBuySell    marketResponse = new MBuySell();

            try
            {
                marketResponse.id = client.SendPostRequest <SellRequest>(url, user, privateKey, sellReq);
                myLogger.Info("Sent Sell Request{commodity:" + commodity + ", price:" + price + ", amount:" + amount + ", url:" + url + "}");
            }
            catch (Exception e)
            {
                return(catchMethod(e));
            }

            myHistory.Info("Sent Sell Request-\r\ncommodity:" + commodity + ", price:" + price + ", amount:" + amount + "\nResponse: " + marketResponse.ToString());

            return(marketResponse);
        }
예제 #5
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);
        }
예제 #6
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);
        }