예제 #1
0
        public void TestAMAsell()
        {
            bool   e            = false;
            Random rnd          = new Random();
            int    rndCommodity = rnd.Next(0, 10);

            int EXPECTEDcommAmount = 0;
            int ACTUALcommAmount   = 0;


            MarketClientClass    client        = new MarketClientClass();
            MarketUserData       userData      = client.SendQueryUserRequest();
            MarketCommodityOffer commodityInfo = client.SendQueryMarketRequest(rndCommodity);

            if (userData.Error != null | commodityInfo.Error != null)   //is NOT successfuly passed to the server
            {
                return;
            }


            foreach (int cmdty in userData.Commodities.Keys)        //passing on all commodities  .
            {
                if (cmdty == rndCommodity)
                {
                    EXPECTEDcommAmount = userData.Commodities[cmdty];      //checking how many we own from rndCommodity
                }
            }


            //we are selling 1
            AMA.AMA_Sell(commodityInfo.Bid, rndCommodity, 1);

            userData = client.SendQueryUserRequest();        //refresh userData

            foreach (int cmdty in userData.Commodities.Keys) //passing on all commodities
            {
                if (cmdty == rndCommodity)
                {
                    ACTUALcommAmount = userData.Commodities[cmdty];
                }
            }

            if (EXPECTEDcommAmount == ACTUALcommAmount)
            {
                e = !e;
            }



            if (e | EXPECTEDcommAmount == 0)
            {
                Assert.AreEqual <int>(EXPECTEDcommAmount, ACTUALcommAmount);
            }

            else
            {
                Assert.AreNotEqual <int>(EXPECTEDcommAmount, ACTUALcommAmount);
            }
        }
예제 #2
0
        public void TestAMAtimers()
        {
            AMA.ResetBothTimers();

            bool amaTimerIsSetted = AMA.checkAmaAutoTimerIsSet();

            Assert.AreEqual <bool>(true, amaTimerIsSetted);

            bool userTimerIsSetted = AMA.checkUserAmaTimerIsSet();

            Assert.AreEqual <bool>(true, userTimerIsSetted);
        }
예제 #3
0
 /// <summary>
 /// starts the manual AMA with a given parameters.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ManualAMAButton_Click(object sender, RoutedEventArgs e)
 {
     if (ManualAMAButton.IsEnabled)
     {
         AMA.TimerOfAutoUser(new List <UserAsksLink>(UserAsks));
         ManualAMAButton.Content = "Stop manual AMA";
     }
     else
     {
         AMA.ResetBothTimers();
         ManualAMAButton.Content = "Start manual AMA";
     }
     EnableDisableControls();
     AmaButton.IsEnabled = !AmaButton.IsEnabled;
 }
예제 #4
0
 /// <summary>
 /// sends a request to start the AMA
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AmaButton_Click(object sender, RoutedEventArgs e)
 {
     if (ManualAMAButton.IsEnabled)
     {
         AMA.TimerOfAMA(true);
         AmaButton.Content = "Stop automatic AMA";
     }
     else
     {
         AMA.TimerOfAMA(false);
         AmaButton.Content = "Start automatic AMA";
     }
     EnableDisableControls();
     ManualAMAButton.IsEnabled = !ManualAMAButton.IsEnabled;
 }
예제 #5
0
        public void TestTimer()
        {
            //setup
            int maxReq     = 10;
            int interval   = 6000;
            int multiplier = 2;

            CountLogic testLogic = new CountLogic();
            AMA        amaTest   = new AMA(maxReq, interval);

            amaTest.add(testLogic);
            amaTest.enable(true);

            System.Threading.Thread.Sleep(interval * multiplier);
            amaTest.enable(false);

            Assert.AreEqual(maxReq * multiplier, testLogic.count);
        }
예제 #6
0
        public IList <bool> Execute(ISecurity source)
        {
            int            count       = source.Bars.Count;
            IList <double> openPrices  = source.OpenPrices;
            IList <double> closePrices = source.ClosePrices;
            IList <double> highPrices  = source.HighPrices;
            IList <double> lowPrices   = source.LowPrices;
            IList <double> doubleList  = AMA.Calc(closePrices, this.ParPeriod, (IMemoryContext)this.Context);

            this.Context?.ReleaseArray((Array)doubleList);
            if (this.TypeCandles == TypeCandles.Открытие)
            {
                doubleList = AMA.Calc(openPrices, this.ParPeriod, (IMemoryContext)this.Context);
            }
            else if (this.TypeCandles == TypeCandles.Максимум)
            {
                doubleList = AMA.Calc(highPrices, this.ParPeriod, (IMemoryContext)this.Context);
            }
            else if (this.TypeCandles == TypeCandles.Минимум)
            {
                doubleList = AMA.Calc(lowPrices, this.ParPeriod, (IMemoryContext)this.Context);
            }
            bool[] flagArray = this.Context?.GetArray <bool>(count) ?? new bool[count];
            int    paRi1     = this.PARi;
            int    num       = this.PARi - 1;

            if (!this.ParOprim)
            {
                for (int paRi2 = this.PARi; paRi2 < count; ++paRi2)
                {
                    if (this.Par1 && !this.Par2 && !this.Par3 && !this.Par4)
                    {
                        bool flag = doubleList[paRi2] > doubleList[paRi2 - paRi1];
                        flagArray[paRi2] = flag;
                    }
                    else if (!this.Par1 && this.Par2 && !this.Par3 && !this.Par4)
                    {
                        bool flag = doubleList[paRi2] < doubleList[paRi2 - paRi1];
                        flagArray[paRi2] = flag;
                    }
                    else if (!this.Par1 && !this.Par2 && this.Par3 && !this.Par4)
                    {
                        bool flag = paRi2 >= this.PARi && doubleList[paRi2 - num] > doubleList[paRi2 - paRi1];
                        flagArray[paRi2] = flag;
                    }
                    else if (!this.Par1 && !this.Par2 && !this.Par3 && this.Par4)
                    {
                        bool flag = paRi2 >= this.PARi && doubleList[paRi2 - num] < doubleList[paRi2 - paRi1];
                        flagArray[paRi2] = flag;
                    }
                    else if (this.Par1 && this.Par2 && !this.Par3 && !this.Par4)
                    {
                        bool flag1 = doubleList[paRi2] > doubleList[paRi2 - paRi1];
                        bool flag2 = doubleList[paRi2] < doubleList[paRi2 - paRi1];
                        flagArray[paRi2] = flag1 || flag2;
                    }
                    else if (this.Par1 && !this.Par2 && this.Par3 && !this.Par4)
                    {
                        bool flag1 = doubleList[paRi2] > doubleList[paRi2 - paRi1];
                        bool flag2 = paRi2 >= this.PARi && doubleList[paRi2 - num] > doubleList[paRi2 - paRi1];
                        flagArray[paRi2] = flag1 || flag2;
                    }
                    else if (this.Par1 && !this.Par2 && !this.Par3 && this.Par4)
                    {
                        bool flag1 = doubleList[paRi2] > doubleList[paRi2 - paRi1];
                        bool flag2 = paRi2 >= this.PARi && doubleList[paRi2 - num] < doubleList[paRi2 - paRi1];
                        flagArray[paRi2] = flag1 || flag2;
                    }
                    else if (!this.Par1 && this.Par2 && this.Par3 && !this.Par4)
                    {
                        bool flag1 = doubleList[paRi2] < doubleList[paRi2 - paRi1];
                        bool flag2 = paRi2 >= this.PARi && doubleList[paRi2 - num] > doubleList[paRi2 - paRi1];
                        flagArray[paRi2] = flag1 || flag2;
                    }
                    else if (!this.Par1 && this.Par2 && !this.Par3 && this.Par4)
                    {
                        bool flag1 = doubleList[paRi2] < doubleList[paRi2 - paRi1];
                        bool flag2 = paRi2 >= this.PARi && doubleList[paRi2 - num] < doubleList[paRi2 - paRi1];
                        flagArray[paRi2] = flag1 || flag2;
                    }
                    else if (!this.Par1 && !this.Par2 && this.Par3 && this.Par4)
                    {
                        bool flag1 = paRi2 >= this.PARi && doubleList[paRi2 - num] > doubleList[paRi2 - paRi1];
                        bool flag2 = paRi2 >= this.PARi && doubleList[paRi2 - num] < doubleList[paRi2 - paRi1];
                        flagArray[paRi2] = flag1 || flag2;
                    }
                }
            }
            else if (this.ParOprim && (!this.Par1 && !this.Par2 && !this.Par3 && !this.Par4))
            {
                for (int paRi2 = this.PARi; paRi2 < count; ++paRi2)
                {
                    flagArray[paRi2] = false;
                    if (this.ParMode == 1)
                    {
                        flagArray[paRi2] = doubleList[paRi2] > doubleList[paRi2 - paRi1];
                    }
                    if (this.ParMode == 2)
                    {
                        flagArray[paRi2] = doubleList[paRi2] < doubleList[paRi2 - paRi1];
                    }
                    if (this.ParMode == 3)
                    {
                        flagArray[paRi2] = paRi2 >= this.PARi && doubleList[paRi2 - num] > doubleList[paRi2 - paRi1];
                    }
                    if (this.ParMode == 4)
                    {
                        flagArray[paRi2] = paRi2 >= this.PARi && doubleList[paRi2 - num] < doubleList[paRi2 - paRi1];
                    }
                }
            }
            return((IList <bool>)flagArray);
        }