예제 #1
0
        public void Start()
        {
            _pricesSeconds.Clear();
            _priceMinutes.Clear();
            using (var context = new MySqlContext())
            {
                int    lastMinute = DateTime.Now.Minute;
                string symbol     = string.Empty;
                var    statInfo   = new PriceStatsSecond();

                _webSocketCache.Subscribe(async evt =>
                {
                    var now = DateTime.Now;
                    foreach (var stat in evt.Statistics)
                    {
                        symbol               = stat.Symbol;
                        statInfo.Name        = symbol;
                        statInfo.LastPrice   = stat.LastPrice;
                        statInfo.Ask         = stat.AskPrice;
                        statInfo.AskQuantity = stat.AskQuantity;
                        statInfo.Bid         = stat.BidPrice;
                        statInfo.BidQuantity = stat.BidQuantity;
                        statInfo.CreateTime  = now;
                    }
                    _pricesSeconds.Add(statInfo.DeepCopy());
                    if (!_isDebug)
                    {
                        await _context.PriceStatsSecond.AddAsync(statInfo);
                    }

                    // 秒単位の通知処理
                    if (_lastMinutePrice.LastPrice > 0)
                    {
                        var secondDiff = Math.Round(100 - ((_lastMinutePrice.LastPrice / statInfo.LastPrice) * 100), 3);
                        await NotifyIfLimitOver(secondDiff, now, statInfo.LastPrice, statInfo.AskQuantity, statInfo.BidQuantity, "秒");
                    }

                    // 分処理
                    if (now.Minute != lastMinute && _pricesSeconds.Any())
                    {
                        await Minute(statInfo.Name, now);
                    }

                    if (!_isDebug)
                    {
                        await _context.SaveChangesAsync();
                    }

                    lastMinute = now.Minute;
                }, new string[] { Symbol.BTC_USDT });
            }
        }
예제 #2
0
 public void SubscribeSymbols()
 {
     webSocketCache = new SymbolStatisticsWebSocketCache();
     //webSocketCache.Error += WebSocketCache_Error;
     webSocketCache.Subscribe(ReceivedSymbol, new string[] { Symbol });
 }