예제 #1
0
        public double LotToUSD(string product, bool BUY)
        {
            var SETTINGS = OSBlotter.Get(product);

            return(this.ConvertToUSD(product, BUY, int.Parse(SETTINGS.OrderSize)));
        }
예제 #2
0
        private bool Action(string PRODUCT, bool BUY)
        {
            if (!OSBlotter.IsLoaded)
            {
                return(false);
            }

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            var SETTINGS  = OSBlotter.Get(PRODUCT); // CEDC_Configuration.GetProductSetting(TOKEN, PRODUCT); //Product settings - minimum lot etc //var b5 = CEDT_TreadingService.GetPositionBlotter(TOKEN); //Summary position for all currencies - all positions
            int OrderSize = int.Parse(SETTINGS.OrderSize);

            if (PRODUCT == "XAU/USD")
            {
                OrderSize *= 10;
            }

            DealResponse INFO;

            // double cost = this.ToUSD(PRODUCT, BUY, OrderSize);

            string Rate;
            string BuySell;

            if (BUY)
            {
                BuySell = "B";
            }
            else
            {
                BuySell = "S";
            }

            bool  bDealSucced = true;
            int   timeout;
            Rates RATE = ORBlotter.Get(PRODUCT);

            do
            {
                timeout = 0;
                if (BUY)
                {
                    Rate = ABBREVIATIONS.ToString(RATE.ASK, RATE.Decimals);    // BID.ToString();
                }
                else
                {
                    Rate = ABBREVIATIONS.ToString(RATE.BID, RATE.Decimals);                                                               //ASK.ToString();
                }
                INFO = CEDT_TreadingService.InstantExecution(TOKEN, PRODUCT, BuySell, OrderSize.ToString(), Rate, ACCOUNT.OpeningHazard); // var INFO = CEDT_TreadingService.DealRequest(TOKEN, PRODUCT, BuySell, OrderSize.ToString(), Rate); //quick // CEDT_TreadingService.DealRequestAtBest(TOKEN, PRODUCT, BuySell, "100000"); //execute whatever but slow

                if (INFO.ErrorNo != "")
                {
                    timeout = RATE.WaitForUpdate(2000);
                    if (timeout < 0)
                    {
                        TsslInfo.Text = "Rate does not changed in 2s, Timeout Error !"; bDealSucced = false; break;
                    }
                    else
                    {
                        TsslInfo.Text = "Time needed for rate to update: " + timeout + " [ms]";
                    }
                }
            } while (timeout != 0);



            if (bDealSucced)
            {
                this.UpdateDeals();
                Deals DEAL = ODBlotter.Get(INFO.dealId);
                if (DEAL != null)
                {
                    double dPipValue = Math.Pow(10, -RATE.Decimals);
                    DEAL.BID = RATE.BID;
                    DEAL.ASK = RATE.ASK;
                    ODBlotter.Add(DEAL);
                }


                this.UpdateAccount();
            }


            return(bDealSucced);
        }