static void PlaceBets(MarketCatalogue mc, MarketBook mb, List <CoreLib.Betfair.TO.Runner> runnersToBack) { var betPlaced = false; decimal unitSize = decimal.Parse(ConfigurationManager.AppSettings["UnitSize"]); Log.Info($"Unit size for {mc.MarketId}-:{unitSize:c2}"); foreach (var runner in runnersToBack) { var betAmount = unitSize; List <PlaceInstruction> placeInstructions = new List <PlaceInstruction>(); var placeInstructionBack = new PlaceInstruction(); placeInstructionBack.Handicap = 0; placeInstructionBack.SelectionId = runner.SelectionId; placeInstructionBack.OrderType = OrderType.MARKET_ON_CLOSE; placeInstructionBack.MarketOnCloseOrder = new MarketOnCloseOrder(); placeInstructionBack.MarketOnCloseOrder.Liability = (double)betAmount; placeInstructionBack.Side = Side.BACK; placeInstructions.Add(placeInstructionBack); var customerRef = Guid.NewGuid().ToString().Substring(0, 20); var placeExecutionReport = Program.Client.placeOrders(mc.MarketId, customerRef, placeInstructions); Log.Info($"Placement report for {mc.MarketId}-{runner.SelectionId} BACK bets\tStatus:{placeExecutionReport.Status}\tError Code:{placeExecutionReport.ErrorCode}"); betPlaced = true; } if (betPlaced) { Console.Beep(); } }
public static void PlaceOrder(PlaceInstruction placeInstruction) { List <PlaceInstruction> placeInstructions = new List <PlaceInstruction>(); placeInstructions.Add(placeInstruction); Thread thread = new Thread(() => ThreadPlaceOrder(placeInstructions)); thread.Start(); }
public void PlaceBet(Component component) // component is a totall { double maxPrice = 1.04; if (component.Name.Equals("Over/Under 4.5 Goals") || component.Name.Equals("Over/Under 5.5 Goals") || component.Name.Equals("Over/Under 6.5 Goals")) { if (component.Name.Equals("Over/Under 6.5 Goals")) { maxPrice = 1.03; } IList <PlaceInstruction> placeInstructions = new List <PlaceInstruction>(); for (double price = 1.01; price < maxPrice; price += 0.01) { var limitOrder = new LimitOrder(); limitOrder.PersistenceType = PersistenceType.PERSIST; //save bet in-play limitOrder.Price = price; limitOrder.Size = 10; // placing a bet below minimum stake, expecting a error in report var placeInstruction = new PlaceInstruction(); placeInstruction.Handicap = 0; placeInstruction.Side = Side.LAY; placeInstruction.OrderType = OrderType.LIMIT; placeInstruction.LimitOrder = limitOrder; placeInstruction.SelectionId = GetSelectionId(client, (component as TotallPatern).MarketId); placeInstructions.Add(placeInstruction); } var customerRef = (component as TotallPatern).MarketId; PlaceExecutionReport placeExecutionReport = client.placeOrders((component as TotallPatern).MarketId, customerRef, placeInstructions); foreach (PlaceInstructionReport placeInstructionReport in placeExecutionReport.InstructionReports) { var betId = placeInstructionReport.BetId; var placedDate = placeInstructionReport.PlacedDate; var status = placeInstructionReport.Status.ToString(); var price = placeInstructionReport.Instruction.LimitOrder.Price; var size = placeInstructionReport.Instruction.LimitOrder.Size; Bet bet = new Bet(betId, placedDate, status, price, size); (component as TotallPatern).bets.Add(bet); component.childNode.Nodes.Add(bet.betNode); //component.childNode.BackColor = System.Drawing.Color.Pink; component.childNode.Expand(); bet.betNode.ForeColor = System.Drawing.Color.Blue; } } }
/// <summary> /// Parses a string command into an Instruction. /// </summary> /// <param name="command">The string command to parse</param> /// <returns>An concrete Instruction</returns> private Instruction ParseCommand(string command) { // Check which regex matches the command, and therefore derive the command's type var matchingRegex = this.Regexes .DefaultIfEmpty(KeyValuePair.Create(InstructionType.Unknown, new Regex(""))) .FirstOrDefault(kvp => kvp.Value.IsMatch(command)); var matchedType = matchingRegex.Key; var rgx = matchingRegex.Value; switch (matchedType) { default: case InstructionType.Unknown: return(NoopInstruction.Create(command)); case InstructionType.Place: { var matches = rgx.Match(command); int x = int.Parse(matches.Groups.ElementAt(1).Value); int y = int.Parse(matches.Groups.ElementAt(2).Value); var direction = Enum.Parse <MovementDirection>(matches.Groups.ElementAt(3).Value.ToTitleCase()); return(PlaceInstruction.Create(x, y, direction, command)); } case InstructionType.Move: return(MoveInstruction.Create(command)); case InstructionType.Rotate: { var matches = rgx.Match(command); var rotationDirection = matches.Groups.ElementAt(1).Value.ToLower() == "right" ? RotationDirection.Clockwise : RotationDirection.CounterClockwise; return(RotateInstruction.Create(rotationDirection, command)); } case InstructionType.Report: return(ReportInstruction.Create(command)); } }
private void clickBack(object sender, EventArgs e) { BackEnd.clock.Stop(); List <PlaceInstruction> placeInstructions = new List <PlaceInstruction>(); PlaceInstruction Instruction = new PlaceInstruction(); LimitOrder order = new LimitOrder(); order.Price = Utils.String2Double(this.lay.Text); order.Size = 5; Instruction.OrderType = OrderType.LIMIT; Instruction.LimitOrder = order; Instruction.Side = Side.BACK; Instruction.SelectionId = this.selectionID; placeInstructions.Add(Instruction); ApiSet.PlaceOrder(placeInstructions); BackEnd.clock.Start(); }
static void Main(string[] args) { //app key and session token are mandatory if (args.Length < 2) { Console.WriteLine("wrong number of arguments"); Environment.Exit(0); } //first argument is the appkey var appkey = args[0]; if (string.IsNullOrEmpty(appkey)) { Console.WriteLine("No App Key"); Environment.Exit(0); } Console.WriteLine("App Key being used: " + appkey); //second argument is the sessionToken var sessionToken = args[1]; if (string.IsNullOrEmpty(sessionToken)) { Console.WriteLine("No Session Token"); Environment.Exit(0); } Console.WriteLine("Session token being used: " + sessionToken); //the third argument is which type of client to use, default is json-rpc IClient client = null; string clientType = null; if (args.Length == 3) { clientType = args[2]; } // if rescript has been passed as the third argument use it otherwise default to json client if (!string.IsNullOrEmpty(clientType) && clientType.Equals("rescript")) { Console.WriteLine("Using RescriptClient"); client = new RescriptClient(Url, appkey, sessionToken); } else { Console.WriteLine("Using JsonRpcClient"); client = new JsonRpcClient(Url, appkey, sessionToken); } Console.WriteLine("\nBeginning sample run!\n"); try { var marketFilter = new MarketFilter(); var eventTypes = client.listEventTypes(marketFilter); // forming a eventype id set for the eventype id extracted from the result ISet <string> eventypeIds = new HashSet <string>(); foreach (EventTypeResult eventType in eventTypes) { if (eventType.EventType.Name.Equals("Horse Racing")) { Console.WriteLine("\nFound event type for Horse Racing: " + JsonConvert.Serialize <EventTypeResult>(eventType)); //extracting eventype id eventypeIds.Add(eventType.EventType.Id); } } //ListMarketCatalogue: Get next available horse races, parameters: var time = new TimeRange(); time.From = DateTime.Now; time.To = DateTime.Now.AddDays(1); marketFilter = new MarketFilter(); marketFilter.EventTypeIds = eventypeIds; marketFilter.MarketStartTime = time; marketFilter.MarketCountries = new HashSet <string>() { "GB" }; marketFilter.MarketTypeCodes = new HashSet <String>() { "WIN" }; var marketSort = MarketSort.FIRST_TO_START; var maxResults = "1"; //as an example we requested runner metadata ISet <MarketProjection> marketProjections = new HashSet <MarketProjection>(); marketProjections.Add(MarketProjection.RUNNER_METADATA); Console.WriteLine("\nGetting the next available horse racing market"); var marketCatalogues = client.listMarketCatalogue(marketFilter, marketProjections, marketSort, maxResults); //extract the marketId of the next horse race String marketId = marketCatalogues[0].MarketId; IList <string> marketIds = new List <string>(); marketIds.Add(marketId); ISet <PriceData> priceData = new HashSet <PriceData>(); //get all prices from the exchange priceData.Add(PriceData.EX_BEST_OFFERS); var priceProjection = new PriceProjection(); priceProjection.PriceData = priceData; Console.WriteLine("\nGetting prices for market: " + marketId); var marketBook = client.listMarketBook(marketIds, priceProjection); if (marketBook.Count != 0) { //get the first runner from the market var runner = marketBook[0].Runners[0]; Console.WriteLine("\nUsing Runner: " + JsonConvert.Serialize <Runner>(runner)); var selectionId = runner.SelectionId; Console.WriteLine("\nPreparing to place bet on runner with Selection Id: " + selectionId + "\nBelonging to marketId: " + marketId + "\nBelow minimum betsize and expecting a INVALID_BET_SIZE response"); IList <PlaceInstruction> placeInstructions = new List <PlaceInstruction>(); var placeInstruction = new PlaceInstruction(); placeInstruction.Handicap = 0; placeInstruction.Side = Side.BACK; placeInstruction.OrderType = OrderType.LIMIT; var limitOrder = new LimitOrder(); limitOrder.PersistenceType = PersistenceType.LAPSE; // place a back bet at rediculous odds so it doesn't get matched limitOrder.Price = 1000; limitOrder.Size = 0.1; // placing a bet below minimum stake, expecting a error in report placeInstruction.LimitOrder = limitOrder; placeInstruction.SelectionId = selectionId; placeInstructions.Add(placeInstruction); var customerRef = "123456"; var placeExecutionReport = client.placeOrders(marketId, customerRef, placeInstructions); ExecutionReportErrorCode executionErrorcode = placeExecutionReport.ErrorCode; InstructionReportErrorCode instructionErroCode = placeExecutionReport.InstructionReports[0].ErrorCode; Console.WriteLine("\nPlaceExecutionReport error code is: " + executionErrorcode + "\nInstructionReport error code is: " + instructionErroCode); if (executionErrorcode != ExecutionReportErrorCode.BET_ACTION_ERROR && instructionErroCode != InstructionReportErrorCode.INVALID_BET_SIZE) { Environment.Exit(0); } Console.WriteLine("\nDONE!"); } else { Console.Write("\nSorry the market has no runner to place a bet on, try again later"); } } catch (APINGException apiExcepion) { Console.WriteLine("Got an exception from Api-NG: " + apiExcepion.ErrorCode); Environment.Exit(0); } catch (System.Exception e) { Console.WriteLine("Unknown exception from application: " + e.Message); Environment.Exit(0); } }