public GameManager(BoxOptionsApiSettings settings, IGameDatabase database, ICoefficientCalculator calculator, IAssetQuoteSubscriber quoteFeed, IWampHostedRealm wampRealm, IMicrographCache micrographCache, IBoxConfigRepository boxConfigRepository, ILogRepository logRepository, ILog appLog, IHistoryHolder historyHolder) { this.database = database; this.calculator = calculator; this._assetQuoteSubscriber = quoteFeed; this.settings = settings; this.logRepository = logRepository; this.appLog = appLog; this.wampRealm = wampRealm; this.boxConfigRepository = boxConfigRepository; this.micrographCache = micrographCache; _historyHolder = historyHolder; _coefficientCache = new CoefficientCache(); if (this.settings != null && this.settings != null && this.settings.GameManager != null) { MaxUserBuffer = this.settings.GameManager.MaxUserBuffer; } GameManagerId = Guid.NewGuid().ToString(); userList = new List <UserState>(); betCache = new List <GameBet>(); assetCache = new Dictionary <string, PriceCache>(); this._assetQuoteSubscriber.MessageReceived += QuoteFeed_MessageReceived; //calculateBoxConfig = null; dbBoxConfig = Task.Run(() => LoadBoxParameters()).Result; Console.WriteLine("Db Box Config = [{0}]", string.Join(",", dbBoxConfig.Select(b => b.AssetPair))); coefStatus = new Dictionary <string, string>(); _historyHolder.InitializationFinished += HistoryHolder_InitializationFinished; }
/// <summary> /// Calculate Box Width acording to BoxSize /// </summary> /// <param name="boxConfig"></param> /// <param name="priceCache"></param> /// <returns></returns> private List <BoxSize> CalculateBoxes(List <BoxSize> boxConfig, IMicrographCache priceCache) { var graphData = priceCache.GetGraphData(); // Only send pairs with graph data var filtered = boxConfig.Where(c => graphData.ContainsKey(c.AssetPair)); // Get Volatility var Volatility = GetVolatilities(); // Calculate BoxWidth according to average prices // BoxWidth = average(asset.midprice) * Box.PriceSize from database var retval = (from b in filtered select new BoxSize { AssetPair = b.AssetPair, BoxesPerRow = b.BoxesPerRow, BoxHeight = b.BoxHeight, TimeToFirstBox = b.TimeToFirstBox, BoxWidth = CalcBoxWidth(b.AssetPair, graphData[b.AssetPair], Volatility[b.AssetPair], b.ScaleK, b.BoxWidth), SaveHistory = b.SaveHistory, GameAllowed = b.GameAllowed }).ToList(); return(retval); }
public WampRpcService(IMicrographCache micrographCacheService, IGameManager gameManager, ILog log, ILogRepository logRepository) { _micrographCacheService = micrographCacheService; _gameManager = gameManager; appLog = log; _logRepository = logRepository; }