void SendTelegramNotification(TickerCollection collection, double prev)
        {
            ArbitrageInfo info = collection.Arbitrage;

            if (/*!info.Ready || */ collection.Disabled)
            {
                return;
            }
            if (prev <= 0 && info.MaxProfit <= 0)
            {
                return;
            }
            string text      = string.Empty;
            string eventText = string.Empty;

            if (prev <= 0)
            {
                eventText = prev <= 0 ? "<b>new</b> " : "<b>changed</b> ";
            }
            text  = eventText + collection.ShortName;
            text += "<pre> buy:        " + info.LowestAsk.ToString("0.00000000") + "</pre>";
            text += "<pre> sell:       " + info.HighestBid.ToString("0.00000000") + "</pre>";
            text += "<pre> spread:     " + info.Spread.ToString("0.00000000") + "</pre>";
            text += "<pre> amount:     " + info.Amount.ToString("0.00000000") + "</pre>";
            text += "<pre> max profit: " + info.MaxProfitUSD.ToString("0.###") + "</pre>";
            text += "<pre> spend:      " + info.BuyTotal.ToString("0.00000000") + "</pre>";
            text += "<pre></pre>";
            text += "buy on: <a href=\"" + info.LowestAskTicker.WebPageAddress + "\">" + info.LowestAskHost + "</a>";
            text += "<pre></pre>";
            text += "sell on: <a href=\"" + info.HighestBidTicker.WebPageAddress + "\">" + info.HighestBidHost + "</a>";
            TelegramBot.Default.SendNotification(text);
        }
        void ShowDesktopNotification(TickerCollection collection, double prev)
        {
            ArbitrageInfo info = collection.Arbitrage;

            if (MdiParent.WindowState != FormWindowState.Minimized)
            {
                return;
            }
            double delta   = info.MaxProfitUSD - prev;
            double percent = delta / prev * 100;

            string            changed = string.Empty;
            TrendNotification trend   = TrendNotification.New;

            if (prev > 0)
            {
                changed = "Arbitrage changed: <b>" + percent.ToString("+0.###;-0.###;0.###%%") + "</b>";
                trend   = delta > 0 ? TrendNotification.TrendUp : TrendNotification.TrendDown;
            }
            else
            {
                changed = "New Arbitrage possibilities. Up to <b>" + info.MaxProfitUSD.ToString("USD 0.###") + "</b>";
            }
            GetReadyNotificationForm().ShowInfo(this, trend, collection.ShortName, changed, 10000);
        }
 async Task UpdateArbitrageInfoTask(TickerCollection info)
 {
     Task task = Task.Factory.StartNew(() => {
         UpdateHelper.Update(info, this);
     });
     await task;
 }
        private void OnShowTickerChartItemClick(object sender, ItemClickEventArgs e)
        {
            TickerCollection collection = (TickerCollection)this.gridView1.GetFocusedRow();

            if (collection == null)
            {
                return;
            }
            TickerForm form;

            if (e.Item.Tag == null)
            {
                for (int i = 0; i < collection.Tickers.Length; i++)
                {
                    Ticker ticker = collection.Tickers[i];
                    if (ticker == null)
                    {
                        return;
                    }
                    form           = new TickerForm();
                    form.Ticker    = ticker;
                    form.MdiParent = MdiParent;
                    form.Show();
                }
                return;
            }

            form           = new TickerForm();
            form.Ticker    = collection.Tickers[(int)e.Item.Tag];
            form.MdiParent = MdiParent;
            form.Show();
        }
 private void RaiseArbitrageChanged(TickerCollection collection)
 {
     if (ArbitrageChanged != null)
     {
         ArbitrageChanged(this, new ArbitrageChangedEventArgs()
         {
             TickersInfo = collection, Arbitrage = collection.Arbitrage
         });
     }
 }
        void ITickerCollectionUpdateListener.OnUpdateTickerCollection(TickerCollection collection, bool useInvokeForUI)
        {
            ArbitrageInfo info = collection.Arbitrage;

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

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

            if (info.AvailableProfitUSD > 20)
            {
                SelectedCollection     = collection;
                ShouldProcessArbitrage = true;
                checkMaxProfits        = false;
            }
            var action = new Action(() => {
                if (this.bbAllCurrencies.Checked && prevSpread * info.Spread < 0)
                {
                    RefreshGrid();
                }
                else
                {
                    RefreshGridRow(collection);
                }
                if (checkMaxProfits && info.MaxProfitUSD - prevProfits > 20)
                {
                    ShowNotification(collection, prevProfits);
                }
                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);
                    }
                }
            });

            if (useInvokeForUI && IsHandleCreated)
            {
                BeginInvoke(action);
            }
            else
            {
                action();
            }
        }
        private void gridView1_Click(object sender, EventArgs e)
        {
            TickerCollection info = (TickerCollection)this.gridView1.GetRow(this.gridView1.FocusedRowHandle);

            if (info == null)
            {
                return;
            }
            bbTryArbitrage.Tag     = info;
            bbTryArbitrage.Caption = "Try Arbitrage on " + info.ShortName;
        }
        void OnUpdateTickers()
        {
            timer.Start();
            long lastGUIUpdateTime = 0;

            while (true)
            {
                for (int i = 0; i < ArbitrageList.Count; i++)
                {
                    if (ShouldProcessArbitrage)
                    {
                        ProcessSelectedArbitrageInfo();
                    }
                    if (timer.ElapsedMilliseconds - lastGUIUpdateTime > 2000)
                    {
                        lastGUIUpdateTime = timer.ElapsedMilliseconds;
                        if (IsHandleCreated)
                        {
                            BeginInvoke(new Action(RefreshGUI));
                        }
                    }
                    if (this.bbMonitorSelected.Checked && !ArbitrageList[i].IsSelected)
                    {
                        continue;
                    }
                    TickerCollection current = ArbitrageList[i];
                    if (current.IsUpdating)
                    {
                        continue;
                    }
                    if (!current.ObtainingData)
                    {
                        while (concurrentTickersCount > 8)
                        {
                            Thread.Sleep(1);
                        }
                        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 (IsHandleCreated)
                        {
                            BeginInvoke(new Action <TickerCollection>(RefreshGridRow), current);
                        }
                    }
                    continue;
                }
            }
        }
        private void bbOpenWeb_ItemClick(object sender, ItemClickEventArgs e)
        {
            TickerCollection info = (TickerCollection)bbTryArbitrage.Tag;

            if (info == null)
            {
                XtraMessageBox.Show("Arbitrage not selected!");
                return;
            }
            for (int i = 0; i < info.Count; i++)
            {
                System.Diagnostics.Process.Start(info.Tickers[i].WebPageAddress);
            }
        }
        void OnShowOrderBookHistory(object sender, ItemClickEventArgs e)
        {
            TickerCollection collection = (TickerCollection)this.gridView1.GetFocusedRow();

            if (collection == null)
            {
                return;
            }
            OrderBookVolumeHistoryForm form = new OrderBookVolumeHistoryForm();

            form.Ticker    = collection.Tickers[(int)e.Item.Tag];
            form.MdiParent = MdiParent;
            form.Show();
        }
Esempio n. 11
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);
        }
        private void bbShowOrderBookHistory_ItemClick(object sender, ItemClickEventArgs e)
        {
            TickerCollection info = (TickerCollection)this.bbTryArbitrage.Tag;

            if (info == null)
            {
                return;
            }
            OrderBookVolumeHistoryForm form = new OrderBookVolumeHistoryForm();

            form.MdiParent = MdiParent;
            form.Ticker    = info.Arbitrage.LowestAskTicker;
            form.Text      = info.Arbitrage.LowestAskHost + " " + info.ShortName;
            form.Show();
        }
        private void bbMinimalProfitSpread_ItemClick(object sender, ItemClickEventArgs e)
        {
            TickerCollection collection = (TickerCollection)this.bbTryArbitrage.Tag;
            ArbitrageInfo    info       = collection.Arbitrage;
            CalculatorForm   form       = new CalculatorForm();

            if (info != null && info.LowestAskTicker != null)
            {
                form.Text      = info.LowestAskTicker.Name;
                form.Amount    = Convert.ToDouble(info.LowestAskTicker.MarketCurrencyBalance);
                form.BuyPrice  = Convert.ToDouble(info.LowestAskTicker.LowestAsk);
                form.SellPrice = Convert.ToDouble(info.LowestAskTicker.HighestBid);
                form.UsdRate   = Convert.ToDouble(info.UsdTicker.Last);
            }
            form.Show();
        }
        private void btShowCombinedBidAsk_ItemClick(object sender, ItemClickEventArgs e)
        {
            TickerCollection info = (TickerCollection)this.bbTryArbitrage.Tag;

            if (info == null)
            {
                return;
            }
            CombinedBidAskForm form = new CombinedBidAskForm();

            form.MdiParent = MdiParent;
            for (int i = 0; i < info.Count; i++)
            {
                form.AddTicker(info.Tickers[i]);
            }
            form.Text = info.Name;
            form.Show();
        }
        private void pmTickers_BeforePopup(object sender, CancelEventArgs e)
        {
            TickerCollection collection = (TickerCollection)this.gridView1.GetFocusedRow();

            if (collection == null)
            {
                return;
            }


            for (int i = 0; i < collection.Count; i++)
            {
                BarButtonItemLink link = (BarButtonItemLink)this.bsStrategies.ItemLinks.FirstOrDefault(l => l.Item.Caption == collection.Tickers[i].HostName);
                if (link == null)
                {
                    BarButtonItem item = new DevExpress.XtraBars.BarButtonItem(this.ribbonControl1.Manager, collection.Tickers[i].HostName);
                    item.ItemClick += OnStrategyTickerClick;
                    link            = (BarButtonItemLink)this.bsStrategies.ItemLinks.Add(item);
                }
                link.Item.Tag = collection.Tickers[i];
            }
        }
 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;
         }
     }
 }
Esempio n. 17
0
        public static List <TickerCollection> GetItems()
        {
            List <TickerCollection> arbitrageList = new List <TickerCollection>();
            List <List <Ticker> >   markets       = GetMarketsList();

            foreach (Ticker ticker in markets.First())
            {
                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 = markets.First().FirstOrDefault((t) => t.MarketCurrency == info.BaseCurrency && t.BaseCurrency == "USDT");
                arbitrageList.Add(info);
            }
            foreach (TickerCollection coll in arbitrageList)
            {
                for (int i = 0; i < coll.Count; i++)
                {
                    coll.Tickers[i].UpdateMode = TickerUpdateMode.Arbitrage;
                }
            }
            return(arbitrageList);
        }
        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);
            //}
        }
 void ShowNotification(TickerCollection info, double prev)
 {
     SendTelegramNotification(info, prev);
     ShowDesktopNotification(info, prev);
 }
 void RefreshGridRow(TickerCollection info)
 {
     this.gridView1.RefreshRow(this.gridView1.GetRowHandle(ArbitrageList.IndexOf(info)));
 }
        protected virtual bool SyncToHighestBid(TickerCollection info, bool forceUpdateBalance, bool allowLog)
        {
            if (info == null)
            {
                return(false);
            }

            Ticker lowest  = info.Arbitrage.LowestAskTicker;
            Ticker highest = info.Arbitrage.HighestBidTicker;

            if (forceUpdateBalance || lowest.MarketCurrencyBalance == 0)
            {
                if (!lowest.UpdateBalance(lowest.MarketCurrency))
                {
                    if (allowLog)
                    {
                        LogManager.Default.Error("Cant update balance.", lowest.HostName + "-" + lowest.MarketCurrency);
                    }
                    if (allowLog)
                    {
                        LogManager.Default.ShowLogForm();
                    }
                    return(false);
                }
                if (!highest.UpdateBalance(highest.MarketCurrency))
                {
                    if (allowLog)
                    {
                        LogManager.Default.Error("Cant update balance.", highest.HostName + "-" + highest.MarketCurrency);
                    }
                    if (allowLog)
                    {
                        LogManager.Default.ShowLogForm();
                    }
                    return(false);
                }
            }
            string highAddress = highest.GetDepositAddress(highest.MarketCurrency);

            if (string.IsNullOrEmpty(highAddress))
            {
                if (allowLog)
                {
                    LogManager.Default.Error("Cant get deposit address.", highest.HostName + "-" + highest.MarketCurrency);
                }
                if (allowLog)
                {
                    LogManager.Default.ShowLogForm();
                }
                return(false);
            }

            if (allowLog)
            {
                LogManager.Default.Log("Highest Bid Currency Deposit: " + highAddress);
            }

            double amount = lowest.MarketCurrencyBalance;

            if (allowLog)
            {
                LogManager.Default.Log("Lowest Ask Currency Amount = " + amount.ToString("0.00000000"));
            }

            if (lowest.Withdraw(lowest.MarketCurrency, highAddress, "", amount))
            {
                string text = "Withdraw " + lowest.MarketCurrency + " " + lowest.HostName + " -> " + highest.HostName + " succeded.";
                if (allowLog)
                {
                    LogManager.Default.Success(text);
                }
                TelegramBot.Default.SendNotification(text);
                return(true);
            }
            else
            {
                if (allowLog)
                {
                    LogManager.Default.Error("Withdraw " + lowest.MarketCurrency + " " + lowest.HostName + " -> " + highest.HostName + " failed.");
                }
                return(false);
            }
        }