Initial commit
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\.editorconfig" Link=".editorconfig" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="SuccessfulCode.BetfairApi" Version="1.0.11" />
|
||||
<PackageReference Include="SuccessfulCodeTools" Version="1.0.8" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,173 @@
|
||||
//using SuccessfulCode.BetfairApi;
|
||||
//using SuccessfulCode.BetfairApi.BettingModels;
|
||||
//using SuccessfulCode.BetfairApi.BettingModels.Enums;
|
||||
//using Microsoft.EntityFrameworkCore;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Threading.Tasks;
|
||||
//using System.Dynamic;
|
||||
|
||||
//namespace AutoBet.Core
|
||||
//{
|
||||
// public class AutoBetBot
|
||||
// {
|
||||
// private BettingApiClient _client;
|
||||
// private BetfairHorseRacingQueries _horseRacingApi;
|
||||
|
||||
// public AutoBetBot()
|
||||
// {
|
||||
// var auth = new Authentication("TheRocker1987", "reSharper1036!", "H5TT4zKqOlRCpNOr");
|
||||
// _client = new BettingApiClient(auth);
|
||||
// _horseRacingApi = new BetfairHorseRacingQueries(_client);
|
||||
// }
|
||||
|
||||
// public async Task MakeBets()
|
||||
// {
|
||||
// var catalogues = await _horseRacingApi.GetHorseWinCatalogue(DateTime.UtcNow.AddHours(1), DateTime.UtcNow.AddDays(1));
|
||||
// var catalogueIdToCatalogue = catalogues.ToDictionary(e => e.MarketId, e => e);
|
||||
|
||||
// var horseIdToHorseName = catalogues.SelectMany(e1 => e1.Runners)
|
||||
// .ToDictionary(e => e.SelectionId, e => e.RunnerName);
|
||||
|
||||
// using (var mainDb = new ExpandoObject())
|
||||
// {
|
||||
|
||||
// var account = await mainDb.Accounts.LastOrDefaultAsync();
|
||||
// var latestTransaction = await mainDb.Transactions.Where(e => e.AccountId == account.Id).LastOrDefaultAsync();
|
||||
// await CheckBetOutComes(mainDb, account, latestTransaction);
|
||||
// latestTransaction = await mainDb.Transactions.Where(e => e.AccountId == account.Id).LastOrDefaultAsync();
|
||||
// var marketIdsAlreadyBet = await mainDb.Bets.Where(e => e.Transaction.AccountId == account.Id)
|
||||
// .Select(e => e.ExchangeMarketId)
|
||||
// .ToArrayAsync();
|
||||
// var remainingLiability = latestTransaction.ElidgableLiability;
|
||||
|
||||
// var marketBooks = await _horseRacingApi.GetMarketBookPrices(catalogues);
|
||||
// marketBooks = marketBooks.Where(e => !marketIdsAlreadyBet.Contains(e.MarketId)).ToArray();
|
||||
// foreach (var item in marketBooks)
|
||||
// {
|
||||
// // var liabilityUsed = await BetOnBook(item, stake, remainingLiability, catalogueIdToCatalogue, horseIdToHorseName, mainDb, account, latestTransaction);
|
||||
// //remainingLiability -= liabilityUsed;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Console.WriteLine("Finished");
|
||||
// }
|
||||
|
||||
// private async Task CheckBetOutComes(MainDb mainDb, Account account, AccountTransaction transaction)
|
||||
// {
|
||||
// var unselltedBets = mainDb.Bets.Where(e => e.Status == Database.Models.BetStatus.Unsettled).ToDictionary(e => e.ExchangeBetId, e => e);
|
||||
// var settledBets = await _client.ListClearedOrders(SuccessfulCode.BetfairApi.BettingModels.Enums.BetStatus.Settled, betIds: unselltedBets.Keys.ToArray());
|
||||
// foreach(var bet in settledBets.ClearedOrders)
|
||||
// {
|
||||
// if (!unselltedBets.TryGetValue(bet.BetId, out Bet betRecord))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// betRecord.Status = bet.Profit > 0 ? Database.Models.BetStatus.Won : Database.Models.BetStatus.Lost;
|
||||
// if(betRecord.Status == Database.Models.BetStatus.Won)
|
||||
// {
|
||||
// var reserverFunds = 1;//Math.Round(bet.Profit.PercentOf(20.00m) - 0.005m, 2);
|
||||
// var recordTransaction = new AccountTransaction()
|
||||
// {
|
||||
// AccountId = account.Id,
|
||||
// CreatedAt = DateTime.UtcNow,
|
||||
// ElidgableLiability = transaction.ElidgableLiability + betRecord.Liability + (bet.Profit - reserverFunds),
|
||||
// TransactionType = TransactionType.BetPlaced,
|
||||
// ReservedFunds = transaction.ReservedFunds += reserverFunds
|
||||
// };
|
||||
// mainDb.Transactions.Add(recordTransaction);
|
||||
// }
|
||||
// }
|
||||
// await mainDb.SaveChangesAsync();
|
||||
// }
|
||||
|
||||
// private async Task<decimal> BetOnBook(
|
||||
// MarketBook book,
|
||||
// decimal stake,
|
||||
// decimal remainingLiability,
|
||||
// Dictionary<string, MarketCatalogue> catalogueIdToCatalog,
|
||||
// Dictionary<long, string> horseIdToName,
|
||||
// MainDb db,
|
||||
// Account account,
|
||||
// AccountTransaction transaction
|
||||
// )
|
||||
// {
|
||||
// var eventDetails = catalogueIdToCatalog[book.MarketId];
|
||||
// var runners = book.Runners.Where(e => e.ExchangePrices.AvailableToLay.Length > 0)
|
||||
// .OrderBy(e => e.ExchangePrices.AvailableToLay[0].Price)
|
||||
// .ToArray();
|
||||
|
||||
// Console.WriteLine($"{eventDetails.Event.Name} @ {eventDetails.MarketStartTime}");
|
||||
// foreach (var runner in runners)
|
||||
// {
|
||||
// Console.WriteLine($"-{horseIdToName[runner.SelectionId]}:{runner.ExchangePrices.AvailableToLay[0].Price} Liability: {(runner.ExchangePrices.AvailableToLay[0].Price * stake) - stake}");
|
||||
// }
|
||||
|
||||
// if (runners.Length <= 3)
|
||||
// {
|
||||
// Console.WriteLine($"Less than 3 horses to lay against");
|
||||
// return 0m;
|
||||
// }
|
||||
|
||||
// var selectedRunner = runners.Skip(3)
|
||||
// .Where(e => e.ExchangePrices.AvailableToLay[0].Price > 7 && e.ExchangePrices.AvailableToLay[0].Price < 10.001m)
|
||||
// .FirstOrDefault();
|
||||
|
||||
// if (selectedRunner == null)
|
||||
// {
|
||||
// Console.WriteLine("No elidgable runner");
|
||||
// return 0m;
|
||||
// }
|
||||
|
||||
// var liability = (selectedRunner.ExchangePrices.AvailableToLay[0].Price * stake) - stake;
|
||||
// Console.WriteLine($"Selected:{horseIdToName[selectedRunner.SelectionId]}:{selectedRunner.ExchangePrices.AvailableToLay[0].Price} Liability: {liability}");
|
||||
|
||||
// if (liability > remainingLiability)
|
||||
// {
|
||||
// Console.WriteLine($"Passing horse as {liability} need but only {transaction.ElidgableLiability} available");
|
||||
// return 0m;
|
||||
// }
|
||||
// //var placeBetResult = new PlaceExecutionReport()
|
||||
// //{
|
||||
// // InstructionReports = new[]
|
||||
// // {
|
||||
// // new PlaceInstructionReport()
|
||||
// // {
|
||||
// // BetId = "Not real"
|
||||
// // }
|
||||
// // }
|
||||
// //};
|
||||
// var placeBetResult = await _client.PlaceOrders(eventDetails.MarketId, new PlaceInstruction[] {
|
||||
// new PlaceInstruction()
|
||||
// {
|
||||
// SelectionId = selectedRunner.SelectionId,
|
||||
// Side = Side.Lay,
|
||||
// OrderType = OrderType.Limit,
|
||||
// LimitOrder = new LimitOrder
|
||||
// {
|
||||
// Price = selectedRunner.ExchangePrices.AvailableToLay[0].Price,
|
||||
// Size = stake,
|
||||
// PersistenceType = PersistenceType.Lapse
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
// if (placeBetResult.InstructionReports.Length == 0 || String.IsNullOrWhiteSpace(placeBetResult.InstructionReports[0].BetId))
|
||||
// {
|
||||
// Console.WriteLine("Bet failed at exchange");
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// remainingLiability -= liability;
|
||||
|
||||
// var betRecord = CreateBetRecord(stake, horseIdToName, eventDetails, selectedRunner, liability, placeBetResult);
|
||||
// var tranasctionRecord = CreateTransactionRecord(remainingLiability, account, transaction, betRecord);
|
||||
// await SaveTranasction(db, tranasctionRecord);
|
||||
|
||||
// Console.WriteLine("--bet placed");
|
||||
// return remainingLiability;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user