public async Task <Runner> GetRunnerDetails(string marketId, long runnerId) { var args = new Dictionary <string, object> { ["marketIds"] = new List <string>() { marketId } }; var priceData = new HashSet <PriceData> { PriceData.EX_TRADED, PriceData.EX_BEST_OFFERS }; var p = new PriceProjection { PriceData = priceData }; args["priceProjection"] = p; args["orderProjection"] = OrderProjection.ALL; args["matchProjection"] = MatchProjection.NO_ROLLUP; var method = "SportsAPING/v1.0/listMarketBook"; var apiClient = await _apiClientFactory.GetApiClient(); var jsonResponse = apiClient.GetData <JsonResponse <List <MarketBook> > >(method, args); var marketBooks = jsonResponse.Result; return(marketBooks.Single().Runners.Single(x => x.SelectionId == runnerId)); }
public static MarketListenerLiveData Create(BetfairClient client, PriceProjection priceProjection, OrderProjection?orderProjection = null, MatchProjection?matchProjection = null, Action <System.Exception, string> logger = null) { return(new MarketListenerLiveData(client, priceProjection, orderProjection, matchProjection, logger)); }
public static void GetAllRiderInfo(ref List <Runner> runners, ref List <RunnerDescription> runnerDescription, ref List <MarketProfitAndLoss> runnerPNL, ref CurrentOrderSummaryReport orders) { PriceData pricedata1 = PriceData.EX_ALL_OFFERS; PriceData pricedata2 = PriceData.EX_TRADED; PriceData pricedata3 = PriceData.EX_BEST_OFFERS; HashSet <PriceData> prijsdata = new HashSet <PriceData>(); prijsdata.Add(pricedata1); prijsdata.Add(pricedata2); prijsdata.Add(pricedata3); PriceProjection priceprojection = new PriceProjection(); OrderProjection orderprojection = new OrderProjection(); MatchProjection matchprojection = new MatchProjection(); orderprojection = OrderProjection.ALL; matchprojection = MatchProjection.ROLLED_UP_BY_AVG_PRICE; priceprojection.PriceData = prijsdata; MarketFilter marketFilter = new MarketFilter(); ISet <string> set = new HashSet <string>(); set.Add(BackEnd.marketID); marketFilter.MarketIds = set; var marketSort = MarketSort.FIRST_TO_START; ISet <MarketProjection> marketProjections = new HashSet <MarketProjection>(); marketProjections.Add(MarketProjection.RUNNER_DESCRIPTION); List <string> marketIds = new List <string>(); marketIds.Add(BackEnd.marketID); try { runners = apiClient.listMarketBook(marketIds, priceprojection, orderprojection, matchprojection)[0].Runners; } catch { } try { runnerDescription = apiClient.listMarketCatalogue(marketFilter, marketProjections, marketSort)[0].Runners; } catch { } try { runnerPNL = apiClient.listMarketProfitAndLoss(marketIds, true, true, true).ToList <MarketProfitAndLoss>(); } catch { } try { orders = apiClient.listCurrentOrders(); } catch { } }
private MarketListener(BetfairClient client, PriceProjection priceProjection, int connectionCount) { this.client = client; this.priceProjection = priceProjection; this.connectionCount = connectionCount; Task.Run(() => PollMarketBooks()); }
private MarketListenerPeriodic(BetfairClient client, PriceProjection priceProjection, double periodInSec) { _client = client; _priceProjection = priceProjection; _polling = Observable.Interval(TimeSpan.FromSeconds(periodInSec), NewThreadScheduler.Default).Subscribe(l => DoWork()); }
public static MarketListener Create(BetfairClient client, PriceProjection priceProjection, int connectionCount) { if (listener == null) { listener = new MarketListener(client, priceProjection, connectionCount); } return(listener); }
public IList<MarketBook> listMarketBook(IList<string> marketIds, PriceProjection priceProjection, OrderProjection? orderProjection = null, MatchProjection? matchProjection = null, string currencyCode = null, string locale = null) { var args = new Dictionary<string, object>(); args[MARKET_IDS]= marketIds; args[PRICE_PROJECTION] = priceProjection; args[ORDER_PROJECTION] = orderProjection; args[MATCH_PROJECTION] = matchProjection; args[LOCALE] = locale; args[CURRENCY_CODE] = currencyCode; return Invoke<List<MarketBook>>(LIST_MARKET_BOOK_METHOD, args); }
public BetfairServerResponse <List <MarketBook> > ListMarketBook( IEnumerable <string> marketIds, PriceProjection priceProjection = null, OrderProjection?orderProjection = null, MatchProjection?matchProjection = null) { return(client.ListMarketBook( marketIds, priceProjection, orderProjection, matchProjection).Result); }
protected BetfairServerResponse <List <MarketBook> > ListMarketBook(List <string> mIDs) { PriceProjection pp = new PriceProjection() { PriceData = new HashSet <PriceData>() { PriceData.EX_ALL_OFFERS } }; return(client.ListMarketBook(mIDs, pp).Result); }
private MarketListenerLiveData(BetfairClient client, PriceProjection priceProjection, OrderProjection?orderProjection, MatchProjection?matchProjection, Action <System.Exception, string> logger) { _client = client; _priceProjection = priceProjection; _orderProjection = orderProjection; _matchProjection = matchProjection; _logger = logger; }
public static PriceProjection HorseRacePriceProjection() { ISet <PriceData> priceData = new HashSet <PriceData>(); //get all prices from the exchange priceData.Add(PriceData.EX_TRADED); priceData.Add(PriceData.EX_ALL_OFFERS); var priceProjection = new PriceProjection(); priceProjection.PriceData = priceData; return(priceProjection); }
public Task <BetfairServerResponse <List <MarketBook> > > ListMarketBook( IEnumerable <string> marketIds, PriceProjection priceProjection = null, OrderProjection?orderProjection = null, MatchProjection?matchProjection = null) { var args = new Dictionary <string, object>(); args[MARKET_IDS] = marketIds; args[PRICE_PROJECTION] = priceProjection; args[ORDER_PROJECTION] = orderProjection; args[MATCH_PROJECTION] = matchProjection; return(networkClient.Invoke <List <MarketBook> >(Endpoint.Betting, LIST_MARKET_BOOK_METHOD, args)); }
public static PriceProjection HorseRacePriceProjection() { ISet <PriceData> priceData = new HashSet <PriceData> { //get all prices from the exchange PriceData.EX_TRADED, PriceData.EX_ALL_OFFERS }; var priceProjection = new PriceProjection { PriceData = priceData }; return(priceProjection); }
public Task <BetfairServerResponse <List <MarketBook> > > ListMarketBook( IEnumerable <string> mIds, PriceProjection priceProjection = null, OrderProjection?orderProjection = null, MatchProjection?matchProjection = null) { var bsr = new BetfairServerResponse <List <MarketBook> >(); bsr.RequestStart = DateTime.Now; bsr.LastByte = DateTime.Now; bsr.LatencyMS = 0L; bsr.HasError = false; bsr.Response = bf.GetMarketBookResponse(mIds); return(Task.Run(() => bsr)); }
internal static bool FindMarket(SportsAPING aping, LineInfo lineInfo, LineDTO line, out string message) { var priceProjection = new PriceProjection(); priceProjection.PriceData = new List <PriceData> { PriceData.EX_ALL_OFFERS, PriceData.EX_BEST_OFFERS }; var markets = aping.ListMarketBook(new List <string> { lineInfo.MarketId }, priceProjection, null, null, "USD"); var market = markets.FirstOrDefault(); if (market == null) { message = "Не найдена ставка. market == null"; return(false); } if (market.Status != MarketStatus.OPEN) { message = $"Рынок закрыт. Статус {market.Status}"; return(false); } var runner = market.Runners.FirstOrDefault(x => x.SelectionId == lineInfo.SelectionId); if (runner == null) { message = "Не найдена ставка. runner == null"; return(false); } foreach (var priceSize in runner.ExchangePrices.AvailableToBack) { if ((decimal)priceSize.Price > line.CoeffValue && (decimal)priceSize.Size > line.Price) { line.CoeffValue = (decimal)priceSize.Price; message = $"Price = {priceSize.Price}. Size = {priceSize.Size}"; return(true); } } message = ""; return(false); }
private MarketListener(BetfairClient client, PriceProjection priceProjection, int connectionCount, int samplePeriod) { this.client = client; this.priceProjection = priceProjection; this.connectionCount = connectionCount; this.samplePeriod = samplePeriod; if (samplePeriod >= 1000) { this.sampleFrequency = samplePeriod / 1000; } else { this.sampleFrequency = samplePeriod / 100; } Task.Run(() => PollMarketBooks()); }
private static MarketCatalogue GetNextRace(out MarketBook mb) { var meetingNames = (from m in Ratings.meetings select m.name).ToList(); mb = null; var race = (from m in Markets where m.Description.MarketTime > DateTime.UtcNow.AddSeconds(-30) && meetingNames.Contains(m.Event.Venue.ToUpper()) orderby m.Description.MarketTime select m).FirstOrDefault(); if (race != null) { var pp = new PriceProjection(); pp.PriceData = new HashSet <PriceData> { PriceData.EX_ALL_OFFERS, PriceData.EX_TRADED }; var prices = Client.listMarketBook(new List <string> { race.MarketId }, pp); mb = prices.FirstOrDefault(); } return(race); }
public static List <LineDTO> Convert(List <MarketCatalogue> list, SportsAPING aping, string bookmaker) { var lines = new List <LineDTO>(); var marketIds = list.Select(x => x.MarketId); var priceProjection = new PriceProjection { PriceData = new List <PriceData> { PriceData.EX_BEST_OFFERS }, ExBestOffersOverrides = new ExBestOffersOverrides { BestPricesDepth = 5 } }; var marketBooks = aping.ListMarketBook(marketIds.ToList(), priceProjection, null, MatchProjection.ROLLED_UP_BY_PRICE, "USD"); foreach (var marketBook in marketBooks.Where(x => x.Status == MarketStatus.OPEN)) { var market = list.FirstOrDefault(x => x.MarketId == marketBook.MarketId); lines.AddRange(Convert(market, marketBook, x => { x.BookmakerName = bookmaker; x.SportKind = Helper.ConvertSport(market.EventType.Name); var teams = market.Event.Name .Replace(" v ", "|") .Replace(" @ ", "|") .Split('|'); x.Team1 = teams.First(); x.Team2 = teams.Last(); x.EventDate = market.MarketStartTime; })); } return(lines); }
public long GetSelectionId(IClient client, string marketId) { IList <string> marketIds = new List <string>(); marketIds.Add(marketId); ISet <PriceData> priceData = new HashSet <PriceData>(); priceData.Add(PriceData.EX_ALL_OFFERS); var priceProjection = new PriceProjection(); priceProjection.PriceData = priceData; IList <MarketBook> marketBook = new List <MarketBook>(); while (marketBook.Count == 0) { marketBook = client.listMarketBook(marketIds, priceProjection); } long selectionId = marketBook[0].Runners[0].SelectionId; // mistake return(selectionId); }
private bool UpdateBFOdds() { Console.WriteLine(DateTime.Now.ToString("yy-MM-dd HH:mm:ss.fff") + " UpdateBFOdds"); IList <Event> events = meetings.SelectMany(m => m.Events).Where(e => e.WinMarketId != null || e.PlaceMarketId != null).ToList(); PriceProjection projection = new PriceProjection() { PriceData = new HashSet <PriceData>() { PriceData.EX_ALL_OFFERS } }; foreach (Event e in events) { if (e.WinMarketId != null) { Console.WriteLine(DateTime.Now.ToString("yy-MM-dd HH:mm:ss.fff") + " List Win Market for " + e.ToString()); IList <MarketBook> mb = bfApi.listMarketBook(new List <string>() { e.WinMarketId }, projection); if (mb.Count > 1) { logger.Warn("Multiple markets found for id " + e.WinMarketId + ", using first returned."); } if (mb.Count == 0) { logger.Error("No market found for id " + e.WinMarketId); } else { Console.WriteLine(DateTime.Now.ToString("yy-MM-dd HH:mm:ss.fff") + " Update Runners"); e.UpdateBFOdds(mb.First().Runners, false); } } if (e.PlaceMarketId != null) { Console.WriteLine(DateTime.Now.ToString("yy-MM-dd HH:mm:ss.fff") + " List Place Market for " + e.ToString()); IList <MarketBook> mb = bfApi.listMarketBook(new List <string>() { e.PlaceMarketId }, projection); if (mb.Count > 1) { logger.Warn("Multiple markets found for id " + e.PlaceMarketId + ", using first returned."); } if (mb.Count == 0) { logger.Error("No market found for id " + e.PlaceMarketId); } else { Console.WriteLine(DateTime.Now.ToString("yy-MM-dd HH:mm:ss.fff") + " Update Runners"); e.UpdateBFOdds(mb.First().Runners, true); } } } //IList<string> marketIds = meetings.SelectMany(m => m.Events).Where(e => e.MarketId != null).Select(e => e.MarketId).ToList(); //List<MarketBook> y = new List<MarketBook>(); //foreach (string id in marketIds) { // y.AddRange(bfApi.listMarketBook(new List<string>() { id }, projection)); //} return(true); }
public static int GetCost(PriceProjection priceProjection) { // TODO Actually more complicated. return(GetCost(priceProjection.PriceData)); }
public static MarketListenerMultiPeriod Create(BetfairClient client, PriceProjection priceProjection) { return(new MarketListenerMultiPeriod(client, priceProjection)); }
private MarketListenerMultiPeriod(BetfairClient client, PriceProjection priceProjection) { _client = client; _priceProjection = priceProjection; }
public static MarketListenerPeriodic Create(BetfairClient client, PriceProjection priceProjection, double periodInSec) { return(new MarketListenerPeriodic(client, priceProjection, periodInSec)); }
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); } }
public void doWork() { if (string.IsNullOrEmpty(sessionToken) && !doLogin()) { onWriteStatus(getLogTitle() + "Login failed!"); return; } initApi(); List <MatchInfo> eventList = new List <MatchInfo>(); try { MarketFilter marketFilter = new MarketFilter(); ISet <string> eventTypeIds = new HashSet <string>(); eventTypeIds.Add("7"); eventTypeIds.Add("4339"); marketFilter.EventTypeIds = eventTypeIds; marketFilter.MarketStartTime = new TimeRange(); marketFilter.MarketStartTime.From = DateTime.Now; marketFilter.MarketStartTime.To = DateTime.Now.AddHours(1); // 한시간후의 경주들을 얻는다. ISet <MarketProjection> marketProjects = new HashSet <MarketProjection>(); marketProjects.Add(MarketProjection.RUNNER_DESCRIPTION); marketProjects.Add(MarketProjection.EVENT); IList <MarketCatalogue> marketCatalogueList = clientDelay.ListMarketCatalogue(marketFilter, marketProjects, null, 100).Result.Response; if (marketCatalogueList == null || marketCatalogueList.Count < 1) { return; } ISet <string> marketIds = new HashSet <string>(); foreach (MarketCatalogue marketCatalogue in marketCatalogueList) { if (marketCatalogue == null || marketCatalogue.Runners == null || marketCatalogue.Runners.Count < 1) { continue; } marketIds.Add(marketCatalogue.MarketId); addMarketEvent(marketCatalogue.MarketId, marketCatalogue.Event); if (marketCatalogue.Runners == null) { continue; } foreach (RunnerCatalog runner in marketCatalogue.Runners) { addSelectionRunner(runner.SelectionId, runner.RunnerName); } } if (marketIds.Count < 1) { return; } // get listmarketbook PriceProjection priceProjection = new PriceProjection(); priceProjection.PriceData = new HashSet <PriceData>(); priceProjection.PriceData.Add(PriceData.EX_ALL_OFFERS); priceProjection.PriceData.Add(PriceData.EX_BEST_OFFERS); priceProjection.PriceData.Add(PriceData.EX_TRADED); priceProjection.PriceData.Add(PriceData.SP_AVAILABLE); priceProjection.PriceData.Add(PriceData.SP_TRADED); int nCnt = 0; ISet <string> tempMarketIds = new HashSet <string>(); List <MarketBook> marketBookList = new List <MarketBook>(); foreach (string marketId in marketIds) { tempMarketIds.Add(marketId); nCnt++; if (nCnt >= 5) { List <MarketBook> tempMarketBookList = clientDelay.ListMarketBook(tempMarketIds, priceProjection).Result.Response; if (tempMarketBookList != null) { marketBookList.AddRange(tempMarketBookList); } nCnt = 0; tempMarketIds.Clear(); } } if (tempMarketIds.Count > 0) { List <MarketBook> tempMarketBookList = clientDelay.ListMarketBook(tempMarketIds, priceProjection).Result.Response; if (tempMarketBookList != null) { marketBookList.AddRange(tempMarketBookList); } } if (marketBookList == null || marketBookList.Count < 1) { return; } foreach (MarketBook marketBook in marketBookList) { if (!Constants.bRun) { break; } if (marketBook.Runners == null) { continue; } MatchInfo matchInfo = new MatchInfo(); matchInfo.id = marketBook.MarketId; string eveName = getEventFromMarketId(marketBook.MarketId); if (string.IsNullOrEmpty(eveName)) { continue; } matchInfo.name = eveName; foreach (Runner runner in marketBook.Runners) { if (runner == null || runner.ExchangePrices == null) { continue; } RunnerInfo runnerInfo = new RunnerInfo(); runnerInfo.id = runner.SelectionId; string runnerName = getRunnerFromSelectionId(runner.SelectionId); if (string.IsNullOrEmpty(runnerName)) { continue; } runnerInfo.name = runnerName; if (runner.ExchangePrices.AvailableToBack != null && runner.ExchangePrices.AvailableToBack.Count > 0) { foreach (PriceSize priceSize in runner.ExchangePrices.AvailableToBack) { PriceInfo priceInfo = new PriceInfo(); priceInfo.odds = priceSize.Price; priceInfo.side = SIDE.Back; priceInfo.stake = priceSize.Size; runnerInfo.prices.Add(priceInfo); } } if (runner.ExchangePrices.AvailableToLay != null && runner.ExchangePrices.AvailableToLay.Count > 0) { foreach (PriceSize priceSize in runner.ExchangePrices.AvailableToLay) { PriceInfo priceInfo = new PriceInfo(); priceInfo.odds = priceSize.Price; priceInfo.side = SIDE.Lay; priceInfo.stake = priceSize.Size; runnerInfo.prices.Add(priceInfo); } } if (runnerInfo.prices.Count > 0) { matchInfo.runners.Add(runnerInfo); } } if (matchInfo.runners.Count > 0) { eventList.Add(matchInfo); } } } catch (Exception e) { } if (eventList.Count > 0) { onSendMatchBetfair(eventList); } }