private void RaiseArbitrageChanged(TickerCollection collection)
 {
     if (ArbitrageChanged != null)
     {
         ArbitrageChanged(this, new ArbitrageChangedEventArgs()
         {
             TickersInfo = collection, Arbitrage = collection.Arbitrage
         });
     }
 }
示例#2
0
        public static ResizeableArray <TickerCollection> GetItems(List <Exchange> exchanges)
        {
            ResizeableArray <TickerCollection> arbitrageList = new ResizeableArray <TickerCollection>();
            List <List <Ticker> > markets = GetMarketsList(exchanges);

            if (markets.Count == 0)
            {
                return(arbitrageList);
            }
            //string[] marketItems = new string[] { "ETC", "LTC", "ADA", "XRP", "EOS", "NES", "ETH", "BTC", "STR", "XMR", "DASH", "ZEC", "NXT" };
            var mFirst = markets[0];

            for (int mi = 0; mi < mFirst.Count; mi++)
            {
                Ticker ticker = mFirst[mi];
//if(!marketItems.Contains(ticker.MarketCurrency))
                //    continue;
                //if(ticker.BaseCurrency != "BTC")
                //    continue;
                TickerCollection info = new TickerCollection();
                info.BaseCurrency   = ticker.BaseCurrency;
                info.MarketCurrency = ticker.MarketCurrency;
                info.Add(ticker);
                for (int i = 1; i < markets.Count; i++)
                {
                    Ticker tt = markets[i].FirstOrDefault((t) => t.BaseCurrency == ticker.BaseCurrency && t.MarketCurrency == ticker.MarketCurrency);
                    if (tt == null)
                    {
                        continue;
                    }
                    info.Add(tt);
                }
                if (info.Count < 2)
                {
                    continue;
                }
                info.UsdTicker = mFirst.FirstOrDefault((t) => t.MarketCurrency == info.BaseCurrency && t.BaseCurrency == "USDT");
                arbitrageList.Add(info);
            }
            for (int ai = 0; ai < arbitrageList.Count; ai++)
            {
                TickerCollection coll = arbitrageList[ai];
                for (int i = 0; i < coll.Count; i++)
                {
                    coll.Tickers[i].UpdateMode = TickerUpdateMode.Arbitrage;
                }
            }
            return(arbitrageList);
        }
 void OnUpdateTickers()
 {
     timer.Start();
     while (true)
     {
         for (int i = 0; i < ArbitrageList.Count; i++)
         {
             TickerCollection current = ArbitrageList[i];
             if (current.IsUpdating)
             {
                 continue;
             }
             if (!current.ObtainingData)
             {
                 while (!CanMakeRequest())
                 {
                     Thread.Sleep(10);
                 }
                 UpdateHelper.Update(current, this);
                 continue;
             }
             int currentUpdateTimeMS = (int)(timer.ElapsedMilliseconds - current.StartUpdateMs);
             if (currentUpdateTimeMS > current.NextOverdueMs)
             {
                 current.UpdateTimeMs   = currentUpdateTimeMS;
                 current.IsActual       = false;
                 current.NextOverdueMs += 3000;
                 if (current.UpdateTimeMs > 40000 && !current.RequestOverdue)
                 {
                     current.ObtainingData  = false;
                     current.RequestOverdue = true;
                     LogManager.Default.Warning(current, current.Name, "classic arbitrage request overdue");
                     TelegramBot.Default.SendNotification(current.Name + ": classic arbitrage request overdue");
                 }
             }
             continue;
         }
     }
 }
        void ITickerCollectionUpdateListener.OnUpdateTickerCollection(TickerCollection collection, bool useInvokeForUI)
        {
            collection.RequestOverdue = false;

            ArbitrageInfo info = collection.Arbitrage;

            double prevProfits = info.MaxProfitUSD;
            double prevSpread  = info.Spread;

            collection.IsUpdating = true;
            info.Calculate();
            info.SaveExpectedProfitUSD();
            RaiseArbitrageChanged(collection);
            collection.IsUpdating = false;


            //for(int i = 0; i < collection.Count; i++) {
            //    Ticker ticker = collection.Tickers[i];
            //    if(ticker.OrderBook.BidHipeStarted || ticker.OrderBook.AskHipeStarted)
            //        SendBoostNotification(ticker);
            //    else if(ticker.OrderBook.BidHipeStopped || ticker.OrderBook.AskHipeStopped)
            //        SendBoostStopNotification(ticker);
            //}
        }