Пример #1
0
        public void run(int count)
        {
            //for (int count=0; count < maxReq & blocks.Count>0; count++) {
            if (queue.Count > 0)
            {
                //Take out and remove first logic block
                AlgoProcess currentLogic = queue[0];
                queue.RemoveAt(0);

                //run the logic block
                bool success = currentLogic.run();
                //TODO: update logger for AdvancedAMA
                //myLogger.Info("AMA logic " + (count + 1) + "/" + maxReq + ": Activated - Logic info: " + currentLogic.ToString());

                //decide where to put the logicProcess in the list
                if (success)
                {
                    queue.Insert(0, currentLogic);
                }
                else
                {
                    queue.Add(currentLogic);
                }
            }
        }
Пример #2
0
        public bool run()
        {
            //for (int count=0; count < maxReq & blocks.Count>0; count++) {
            lock (queue)
            {
                if (queue.Count > 0)
                {
                    bool success = false;
                    try
                    {
                        //Take out next AlgoProcess from Queue
                        AlgoProcess currentLogic = queue.Dequeue();

                        success = currentLogic.runProcess();

                        myLogger.Info("AMA running logic: " + currentLogic.ToString());

                        //Add the AlgoProcess to the end of the queue
                        queue.Enqueue(currentLogic);
                    }
                    catch (Exception e) { };


                    return(success);
                }
                return(false);
            }
        }
Пример #3
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);
        }
Пример #4
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();
            }
        }
Пример #5
0
        public bool conditionIsMet(AlgoProcess process)
        {
            //Return true if the short-moving-average < mid-moving-average < long-moving-average
            DateTime minTimeRange = DateTime.Now.AddHours(-minTime);
            float    minAverage   = sql.PriceAverage(minTimeRange, DateTime.Now, process.commodity);

            DateTime medTimeRange = DateTime.Now.AddHours(-medTime);
            float    medAverage   = sql.PriceAverage(medTimeRange, DateTime.Now, process.commodity);

            DateTime maxTimeRange = DateTime.Now.AddHours(-maxTime);
            float    maxAverage   = sql.PriceAverage(maxTimeRange, DateTime.Now, process.commodity);

            if (minAverage < 0 | medAverage < 0 | maxAverage < 0)
            {
                return(false);
            }

            return((minAverage <= medAverage) & (medAverage < maxAverage));
        }
Пример #6
0
        public bool conditionIsMet(AlgoProcess process)
        {
            if (process.agent.userData == null)
            {
                return(false);
            }
            //Get data from process
            IDictionary <string, int> userCommodities = process.agent.userData.getCommodities();
            string commodity = process.commodity.ToString();

            //Verify if amount>0
            if (userCommodities.ContainsKey(commodity))
            {
                int commoditySupply = userCommodities[commodity];
                return(commoditySupply > 0);
            }
            else
            {
                return(false);
            }
        }
Пример #7
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);
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
0
 public virtual void add(AlgoProcess processList)
 {
     queue.Enqueue(processList);
 }
Пример #11
0
 //Returns true if there is no active request false otherwise
 public bool conditionIsMet(AlgoProcess process)
 {
     return(process.requestID == -1);
 }
Пример #12
0
 public abstract bool analyse(AlgoProcess list);
Пример #13
0
 public bool runStep(AlgoProcess list)
 {
     return(analyse(list));
 }
Пример #14
0
 public abstract bool runAction(AlgoProcess list);
Пример #15
0
 public bool runStep(AlgoProcess list)
 {
     return(runAction(list));
 }