Ejemplo n.º 1
0
        public static int Buy(BuyOptions options)
        {
            SwitchAccount(options.Account);
            List <Market> toBuy = MarketSearch(options.NamesToSearch.Trim(','), options.Expiry, options.EpicPrefix, false, options.Exlude);

            int positionCount = toBuy.Count();

            float toInvest = (float)(options.Value / positionCount);

            List <IgBuyModel> buyList = new List <IgBuyModel>();
            int i = 0;

            Console.WriteLine($"Will buy");
            Console.WriteLine($"{"Name".PadRight(80)} {"Size".PadLeft(8)} {"Value".PadLeft(12)} {"Stop".PadLeft(10)} {"Limit".PadLeft(10)}");
            double total = 0;

            foreach (Market market in toBuy)
            {
                float positionSize = (float)Math.Round(toInvest / market.Bid, 2);

                IgBuyModel igBuy = new IgBuyModel
                {
                    currencyCode  = "GBP",
                    dealReference = $"NMCQ{i}{DateTime.Now.Year}{DateTime.Now.Month}{DateTime.Now.Day}",
                    direction     = "BUY",
                    epic          = market.Epic,
                    expiry        = market.Expiry,
                    size          = positionSize,
                    limitDistance = (float)(market.Bid * (options.LimitDistance / 100)),
                    stopDistance  = (float)(market.Bid * (options.StopDistance / 100))
                };
                i++;

                buyList.Add(igBuy);

                total += positionSize * market.Bid;

                Console.WriteLine($"{market.InstrumentName.PadRight(80)} { positionSize.ToString().PadRight(8) }  { Math.Round(positionSize * market.Bid, 2).ToString("N0").PadLeft(12) }   { (market.Bid - igBuy.stopDistance).ToString("N2").PadLeft(10)} {(market.Bid + igBuy.limitDistance).ToString("N2").PadLeft(10)}");
            }


            Console.WriteLine($"Your total risk will be { total.ToString("N0") }");

            Console.WriteLine($"Do you wish to purchase?");
            var letter = Console.ReadKey();

            if (letter.Key == ConsoleKey.Y)
            {
                Console.WriteLine();

                Console.WriteLine($"Executing Order...");
                foreach (IgBuyModel buy in buyList)
                {
                    Buy(buy);
                }
            }

            return(0);
        }
Ejemplo n.º 2
0
        public string Post(IgSessionModel igSession, IgBuyModel buyOrder)
        {
            string action = "/positions/otc";

            StringContent content = new StringContent(JsonConvert.SerializeObject(buyOrder), Encoding.UTF8, "application/json");

            return(igHttpClient.Post(igSession, action, 2, content));;
        }
Ejemplo n.º 3
0
        // TODO Needs testing in open market
        public static void Buy(IgBuyModel igBuy)
        {
            IgPositions igPosition = new IgPositions();
            string      response   = igPosition.Post(session, igBuy);

            Console.WriteLine(response);
            response = new IgConfirms().GetConfirms(session, igBuy.dealReference);
            Console.WriteLine(response);
        }