private Result <PoolHashrate> GetHashrateEntity(string content, CoinConfig pattern) { try { Regex expression = new Regex(pattern.Pattern); Match match = expression.Match(content); if (!match.Success) { return(Result <PoolHashrate> .Fail($"PoolPull regex failed Name: '{pattern.Name}'")); } var value = double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture); var denomination = pattern.Denomination; if (match.Groups[2].Success) { denomination = DenominationHelper.ToDenomination(match.Groups[2].Value); } var mSolValue = DenominationHelper.ToMSol(value, denomination); var poolHashrate = new PoolHashrate() { Name = pattern.Name, Value = mSolValue, EntryDate = DateTime.UtcNow }; return(Result <PoolHashrate> .Ok(poolHashrate)); } catch (Exception ex) { return(Result <PoolHashrate> .Fail($"PoolPull parse failed Name: '{pattern.Name}', error: '{ex}'")); } }
public void PurchaseWithCorrectChange() { var acceptedCoins = new List <Coin>() { CoinConfig.GetDime(), CoinConfig.GetNickel(), CoinConfig.GetQuarter() }; var productsToStock = new List <Product>() { ProductConfig.GetCandy(), ProductConfig.GetChips(), ProductConfig.GetCola() }; var change = new List <Coin>(); change.AddRange(BulkAddChange(10, CoinConfig.GetQuarter())); change.AddRange(BulkAddChange(10, CoinConfig.GetNickel())); var vendineMachine = SetUpMachine(acceptedCoins, productsToStock, change); var coin = new KeyValuePair <decimal, decimal>(CoinConfig.GetQuarter().Weight, CoinConfig.GetQuarter().Width); var currency = new List <KeyValuePair <decimal, decimal> >(); currency.Add(coin); currency.Add(coin); vendineMachine.AcceptCurrency(currency); vendineMachine.MakeSelection(ProductConfig.GetChips()); }
public void CoinAccepted(CoinConfig config) { Debug.Log($"CoinAccepted {config.Amount}"); CoinCounter--; CurrentSum += config.Amount; DummyCoinAccepted = DummyCoinAccepted || config.IsDummy; coinDropAccept?.Play(); }
private void SpawnCoin(Bounds bounds, Coin coinPrefab, CoinConfig cfg) { var posX = Random.Range(bounds.min.x, bounds.max.x); var posY = Random.Range(bounds.min.y, bounds.max.y); var pos = new Vector3(posX, posY); var rotation = Random.rotation; rotation.y = 0; rotation.x = 0; var obj = Instantiate(coinPrefab, pos, rotation); var coin = obj.GetComponent <Coin>(); coin.Config = cfg; coin.ApplyConfig(); }
public static CoinConfig[] GenerateRandomValues(List <CoinConfig> coinConfigs, int?n = null, int min = 2, int max = 7) { if (!n.HasValue) { n = Random.Range(min, max); } var result = new CoinConfig[n.Value]; for (int i = 0; i < n.Value; i++) { var choice = Random.Range(0, coinConfigs.Count); result[i] = coinConfigs[choice]; } return(result); }
private void Init() { config = Config.LoadConfig(); coinConfigs = CoinConfig.Load(); info = new HFTInfo(config); Symbols = new List <string>(); Symbol = config.Symbol; Platform = config.Platform; robotMarket = new Robot_Market(Platform); robotTrade = new Robot_Trade(coinConfigs, config, Platform, config.ApiKey, config.SecretKey, new List <string>() { Symbol }); robotSession = new Robot_Session(robotTrade, robotMarket, info); robotSession.SessionEvent += RobotHFT_SessionEvent; robotCurrent = new Robot_Current(robotTrade, robotSession, info); robotCurrent.CurrentEvent += RobotHFT_CurrentEvent;; robotReport = new Robot_Report(robotTrade, robotSession, robotMarket, info); }
private void AddLine(CoinConfig coinConfig, Coin coin, int lineIndex) { CoinLine newLine = new CoinLine(coin.ShortName, coinConfig.Index, lineIndex, Width); if (coinConfig.StartupPrice == 0) { coinConfig.StartupPrice = coin.Price; } Invoke((MethodInvoker) delegate { newLine.SetBoughtText(coinConfig.Bought.ToString()); newLine.SetPaidText(coinConfig.Paid.ToString()); Controls.Add(newLine.Table); _coinLines.Add(newLine); Globals.SetTheme(newLine.Table); }); }
public void Purchase() { var acceptedCoins = new List <Coin>() { CoinConfig.GetDime(), CoinConfig.GetNickel(), CoinConfig.GetQuarter() }; var productsToStock = new List <Product>() { ProductConfig.GetCandy(), ProductConfig.GetChips(), ProductConfig.GetCola() }; var change = new List <Coin>(); change.AddRange(BulkAddChange(10, CoinConfig.GetQuarter())); change.AddRange(BulkAddChange(10, CoinConfig.GetNickel())); var vendineMachine = SetUpMachine(acceptedCoins, productsToStock, change); }
public void CoinRejected(CoinConfig config) { Debug.Log($"CoinRejected {config.Amount}"); CoinCounter--; coinDropReject?.Play(); }
private void Init() { coinConfigs = CoinConfig.Load(); robotMarket = new Robot_Market(Platform); var list = coinConfigs.Where(a => a.Platform.ToLower() == Platform.ToLower()).Select(a => a.Symbol).ToList(); robotMarket.Run(new List <string>() { "btcusdt" }); decimal lastTicker = 0; int lastflag = 0; decimal count = 0; decimal guessR = 0; while (true) { try { Thread.Sleep(1000 * 30); if (!robotMarket.Running) { continue; } var depth = robotMarket.GetDepth("btcusdt"); var ticker = robotMarket.GetTicker("btcusdt"); #region depth item = new depth(); item.date = DateTime.Now; item.id = Utils.GetUtcTimeDec(); item.ticker = ticker?.last; item.json = ModelHelper <Depth> .Model2Json(depth);; if (item.ticker != 0 && !string.IsNullOrEmpty(item.json)) { DbHelper.CreateInstance().AddDepth(item); } #endregion StringBuilder sb = new StringBuilder(); if (depth != null && depth.asks.Count > 0 && depth.bids.Count > 0) { var asks = depth.asks.ToArray(); var bids = depth.bids.ToArray(); var firstA = asks.FirstOrDefault(); var firstB = bids.FirstOrDefault(); string ss = "----"; if (ticker.last > lastTicker * 1.02m) { ss = "up"; } if (ticker.last < lastTicker * 0.98m) { ss = "down"; } string sss = "Guess Wrong!"; if (ss == "up" && lastflag == 1) { sss = "Guess Right!"; guessR++; } if (ss == "down" && lastflag == 2) { sss = "Guess Right!"; guessR++; } if (lastflag == 0) { sss = ""; } sb.AppendLine($"depth asks:{asks.Count()} bids:{bids.Count()}"); sb.AppendLine($"lastTicker :{lastTicker.ToString("0.00")} thisTicker:{ticker.last.ToString("0.00")} price go {ss} {sss}"); var rate = count == 0 ? 1 : guessR / count; sb.AppendLine($"GuessCount :{count} Right:{guessR} Rate:{rate.ToString("p")}"); lastTicker = ticker.last; var aSum = asks.Sum(a => a[1]); var bSum = bids.Sum(a => a[1]); sb.AppendLine($"Amount Sum asks:{aSum.ToString("0.000")} bids:{bSum.ToString("0.000")}"); var avA = asks.Sum(a => a[0] * a[1]) / aSum; var avB = bids.Sum(a => a[0] * a[1]) / bSum; sb.AppendLine($"Price Ave asks:{avA.ToString("0.00")} bids:{avB.ToString("0.00")}"); var lastA = asks.LastOrDefault(); var lastB = bids.LastOrDefault(); sb.AppendLine($"depth asks from:{lastA[0].ToString("0.000")},{lastA[1].ToString("0.000")} to:{firstA[0].ToString("0.000")},{firstA[1].ToString("0.000")}"); sb.AppendLine($"depth bids from:{firstB[0].ToString("0.000")},{firstB[1].ToString("0.000")} to:{lastB[0].ToString("0.000")},{lastB[1].ToString("0.000")}"); //sb.AppendLine($"{asks.Where(a => a[0] == 0).Count()}{asks.Where(a => asks.Where(b => b[0] == a[0]).Count() > 1).Count()}"); var isUp = aSum * 2.5m < bSum; var isDown = bSum * 2.5m < aSum; var flag = 0; string str = "----"; if (isUp) { flag = 1; str = "Maybe Up"; count++; } if (isDown) { flag = 2; str = "Maybe Down"; count++; } sb.AppendLine($"{str}"); lastflag = flag; //Console.WriteLine(sb.ToString()); Log4NetUtility.Debug(sb.ToString()); } } catch (Exception e) { Log4NetUtility.Error("while", e.Message); } } }