Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public bool conditionIsMet(AlgoProcess process)
        {
            if (process.agent.commoditiesInfo == null)
            {
                return(false);
            }

            int currentAsk = 999999;

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

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