private void listView_symbols_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         if (listView_symbols.FocusedItem.Bounds.Contains(e.Location) == true)
         {
             if (listView_symbols.SelectedObject != null)
             {
                 //CalculatorItem item = listView.SelectedObject as CalculatorItem;
                 ExchangeTicker    item     = listView_symbols.SelectedObject as ExchangeTicker;
                 ContextMenuStrip  menu     = new ContextMenuStrip();
                 ToolStripMenuItem menuItem = new ToolStripMenuItem()
                 {
                     Text = "Remove " + item.symbol + "/" + item.market,
                     Tag  = item.symbol + "_" + item.market
                 };
                 menuItem.Click += new EventHandler(RemoveSymbolItem_Menu_Click);
                 menu.Items.Add(menuItem);
                 menu.Show(Cursor.Position);
             }
         }
     }
 }
示例#2
0
        public static async Task LoadSources()
        {
            lock (loadLock)
            {
                if (sources.Count == 0)
                {
                    var exchangeMB = new Exchange()
                    {
                        Name = "Mercado Bitcoin", Image = @"BitCoin_Advisor.Images.mb.png", Fee = 0.99m, Currency = "BRL", IsEnabled = true
                    };
                    var exchangeBitCoinTrade = new Exchange()
                    {
                        Name = "BitCoin Trade", Image = @"BitCoin_Advisor.Images.bitcointrade.png", Fee = 0.99m, Currency = "BRL", IsEnabled = true
                    };
                    var exchangeBistamp = new Exchange()
                    {
                        Name = "BitStamp", Image = @"BitCoin_Advisor.Images.bitstamp.png", Fee = 0.99m, Currency = "USD", IsEnabled = true
                    };
                    var exchangeFoxBit = new Exchange()
                    {
                        Name = "FoxBit", Image = @"BitCoin_Advisor.Images.foxbit.png", Fee = 0.995m, Currency = "BRL", IsEnabled = true
                    };
                    var exchangeCoinfloor = new Exchange()
                    {
                        Name = "CoinFloor", Image = @"BitCoin_Advisor.Images.coinfloor.png", Fee = 0.99m, Currency = "GBP", IsEnabled = true
                    };

                    exchanges = new ObservableRangeCollection <Exchange>()
                    {
                        exchangeMB, exchangeBitCoinTrade, exchangeBistamp, exchangeFoxBit, exchangeCoinfloor
                    };

                    var btc = new Symbol()
                    {
                        Name = "BTC"
                    };

                    var sourceMB = new ExchangeTicker()
                    {
                        Exchange = exchangeMB, TickerUrl = "https://www.mercadobitcoin.net/api/BTC/ticker/", Symbol = btc
                    };
                    var sourceBitCoinTrade = new ExchangeTicker()
                    {
                        Exchange = exchangeBitCoinTrade, TickerUrl = "https://api.bitcointrade.com.br/v1/public/BTC/ticker", Symbol = btc
                    };
                    var sourceBistamp = new ExchangeTicker()
                    {
                        Exchange = exchangeBistamp, TickerUrl = "https://www.bitstamp.net/api/ticker/", Symbol = btc
                    };
                    var sourceFoxBit = new ExchangeTicker()
                    {
                        Exchange = exchangeFoxBit, TickerUrl = "https://api.blinktrade.com/api/v1/BRL/ticker", Symbol = btc
                    };
                    var sourceCoinfloor = new ExchangeTicker()
                    {
                        Exchange = exchangeCoinfloor, TickerUrl = "https://webapi.coinfloor.co.uk:8090/bist/XBT/GBP/ticker/", Symbol = btc
                    };

                    //sources.Add(sourceCoinfloor);
                    sources.Add(sourceBistamp);
                    sources.Add(sourceMB);
                    sources.Add(sourceBitCoinTrade);
                    sources.Add(sourceFoxBit);
                }

                if (arbitrages.Count == 0)
                {
                    foreach (var s in sources)
                    {
                        foreach (var s2 in sources)
                        {
                            if (s != s2)
                            {
                                arbitrages.Add(new Arbitrage(s, s2));
                            }
                        }
                    }
                }
            }

            var tasks = sources.Select(async item =>
            {
                await GetTicker(item);
            });
            await Task.WhenAll(tasks);

            BLExchangeRate bLExchangeRate = new BLExchangeRate();

            foreach (var arbitrage in arbitrages)
            {
                arbitrage.Conversion = await bLExchangeRate.GetExchangeRate(arbitrage.From.Exchange.Currency, arbitrage.To.Exchange.Currency);

                arbitrage.CalculateNet();
            }
        }
示例#3
0
        /*
         * public static List<ExchangeTicker> getExchangeTickerList()
         * {
         *  List<ExchangeTicker> list = new List<ExchangeTicker>();
         *  List<GDAXProductTicker> tickerList = getProductTickerList();
         *
         *  foreach (GDAXProductTicker ticker in tickerList)
         *  {
         *      list.Add(ticker.GetExchangeTicker());
         *  }
         *  return list;
         * }
         */
        // UPDATERS
        public async static void updateExchangeBalanceList(bool clear = false)
        {
            List <GDAXAccount> list = await getAccountList();

            ExchangeTicker btcTicker = getExchangeTicker("CryptoCompare", "BTC", USDSymbol);

            //LogManager.AddLogMessage(Name, "updateExchangeBalanceList", list.Count + " | " + btcTicker.last + " | " + btcTicker.exchange, LogManager.LogMessageType.EXCHANGE);

            if (list.Count > 0)
            {
                if (clear)
                {
                    ClearBalances(Name);
                }

                foreach (GDAXAccount balance in list)
                {
                    if (balance.balance > 0)
                    {
                        if (balance.currency != "BTC" && balance.currency != USDSymbol)
                        {
                            // GET TICKER FOR PAIR IN BTC MARKET
                            ExchangeTicker ticker = getExchangeTicker("CryptoCompare", balance.currency.ToUpper(), "BTC");

                            if (ticker != null)
                            {
                                //Decimal orders = balance.Balance - balance.Available;
                                if (balance.hold > 0)
                                {
                                    balance.TotalInBTCOrders = balance.hold * ticker.last;
                                }

                                balance.TotalInBTC = balance.balance * ticker.last;
                                balance.TotalInUSD = btcTicker.last * balance.TotalInBTC;
                            }
                            else
                            {
                                LogManager.AddLogMessage(Name, "updateExchangeBalanceList", "EXCHANGE TICKER WAS NULL : " + Name + " | " + balance.currency.ToUpper(), LogManager.LogMessageType.EXCHANGE);
                            }
                        }
                        else
                        {
                            //LogManager.AddLogMessage(Name, "updateExchangeBalanceList", "CHECKING CURRENCY :" + balance.Currency, LogManager.LogMessageType.DEBUG);
                            if (balance.currency == "BTC")
                            {
                                if (balance.hold > 0)
                                {
                                    balance.TotalInBTCOrders = balance.hold;
                                }

                                balance.TotalInBTC = balance.balance;
                                balance.TotalInUSD = btcTicker.last * balance.balance;
                            }
                            else if (balance.currency == USDSymbol)
                            {
                                if (btcTicker.last > 0)
                                {
                                    if (balance.hold > 0)
                                    {
                                        balance.TotalInBTCOrders = balance.hold / btcTicker.last;
                                    }

                                    balance.TotalInBTC = balance.balance / btcTicker.last;
                                }
                                balance.TotalInUSD = balance.balance;
                            }
                        }
                        //LogManager.AddLogMessage(Name, "updateExchangeBalanceList", balance.Currency + " | " + balance.Balance + " | " + balance.TotalInBTC + " | " + balance.TotalInUSD, LogManager.LogMessageType.DEBUG);
                        processBalance(balance.GetExchangeBalance());
                    }
                }
            }
        }
示例#4
0
 public static string ToCsv(this ExchangeTicker t)
 {
     //var timeString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
     return(string.Format("{0},{1},{2},{3}", t.Bid, t.Ask, t.Last, t.Volume.BaseVolume));
 }
示例#5
0
 public static string CsvHeaders(this ExchangeTicker t)
 {
     return("Bid,Ask,Last,Volume");
 }
        public async Task <OperationResult <ExchangeTicker> > GetByAddress(string exchangeAddress)
        {
            var exchangeEntity = await _exchangeRepository.FindByAsync(exchangeAddress : exchangeAddress);

            if (exchangeEntity == null)
            {
                return(new OperationResult <ExchangeTicker>());
            }

            var exchangeEvents = await _repository.GetForLastDayByExchangeAddressAsync(exchangeAddress);

            if (!exchangeEvents.Any())
            {
                return(new OperationResult <ExchangeTicker>(null));
            }

            var orderedPurchaseEvents = exchangeEvents
                                        .Where(IsEthOrTokenPurchaseEvent)
                                        .OrderBy(x => x.BlockNumber)
                                        .ThenBy(x => x.LogIndex);

            var ticker = new ExchangeTicker();

            if (orderedPurchaseEvents.Any())
            {
                var firstTrade = orderedPurchaseEvents.First();

                var lastTrade = orderedPurchaseEvents.Last();

                var startPrice = firstTrade.TokenAmount / firstTrade.EthAmount;

                var priceChange = UniswapUtils.CalculateMarginalRate(lastTrade.EthLiquidityBeforeEvent,
                                                                     lastTrade.TokenLiquidityBeforeEvent) -
                                  UniswapUtils.CalculateMarginalRate(firstTrade.EthLiquidityBeforeEvent,
                                                                     firstTrade.TokenLiquidityBeforeEvent);

                var ethTradeVolume = orderedPurchaseEvents.Sum(@event => @event.EthAmount);

                var highPrice = orderedPurchaseEvents.Max(@event =>
                                                          UniswapUtils.CalculateMarginalRate(@event.EthLiquidityBeforeEvent,
                                                                                             @event.TokenLiquidityBeforeEvent));

                var lowPrice = orderedPurchaseEvents.Min(@event =>
                                                         UniswapUtils.CalculateMarginalRate(@event.EthLiquidityBeforeEvent,
                                                                                            @event.TokenLiquidityBeforeEvent));

                var weightedAveragePrice =
                    orderedPurchaseEvents.Sum(@event =>
                                              @event.EthAmount *
                                              UniswapUtils.CalculateMarginalRate(@event.EthLiquidityBeforeEvent,
                                                                                 @event.TokenLiquidityBeforeEvent)) / ethTradeVolume;

                ticker.Count             = orderedPurchaseEvents.Count();
                ticker.LowPrice          = lowPrice;
                ticker.HighPrice         = highPrice;
                ticker.LastTradeErc20Qty = lastTrade.TokenAmount;
                ticker.LastTradeEthQty   = lastTrade.EthAmount;
                ticker.LastTradePrice    = UniswapUtils.CalculateMarginalRate(lastTrade.EthLiquidityBeforeEvent,
                                                                              lastTrade.TokenLiquidityBeforeEvent);
                ticker.PriceChange        = priceChange;
                ticker.TradeVolume        = ethTradeVolume;
                ticker.PriceChangePercent = priceChange / startPrice;
                ticker.WeightedAvgPrice   = weightedAveragePrice;
            }

            ticker.EndTime        = DateTime.UtcNow.ToUnixTimestamp();
            ticker.Erc20Liquidity = exchangeEntity.TokenLiquidity;
            ticker.EthLiquidity   = exchangeEntity.EthLiquidity;
            ticker.Price          =
                UniswapUtils.CalculateMarginalRate(exchangeEntity.EthLiquidity, exchangeEntity.TokenLiquidity);
            ticker.InvPrice =
                UniswapUtils.CalculateInvMarginRate(exchangeEntity.EthLiquidity, exchangeEntity.TokenLiquidity);
            ticker.Symbol    = exchangeEntity.TokenSymbol;
            ticker.StartTime = DateTime.UtcNow.Subtract(TimeSpan.FromDays(1)).ToUnixTimestamp();
            ticker.Theme     = exchangeEntity.Theme;

            return(new OperationResult <ExchangeTicker>(ticker));
        }
示例#7
0
 public long AddUpdateExchangeTicker(ExchangeTicker exchangeTicker)
 {
     throw new NotImplementedException();
 }
示例#8
0
        // GETTERS

        /*
         * public static List<ExchangeBalance> getExchangeBalanceList()
         * {
         *  List<ExchangeBalance> list = new List<ExchangeBalance>();
         *  List<CCEXBalance> balanceList = getBalanceList();
         *
         *  foreach (CCEXBalance balance in balanceList)
         *  {
         *      list.Add(balance.GetExchangeBalance());
         *  }
         *  return list;
         * }
         *
         * public static List<ExchangeTicker> getExchangeTickerList()
         * {
         *  List<ExchangeTicker> list = new List<ExchangeTicker>();
         *  List<CCEXMarketSummary> tickerList = getMarketSummariesList();
         *
         *  foreach (CCEXMarketSummary ticker in tickerList)
         *  {
         *      list.Add(ticker.GetExchangeTicker());
         *  }
         *  return list;
         * }
         */
        // UPDATERS
        public static void updateExchangeBalanceList(bool clear = false)
        {
            List <CCEXBalance> list      = getBalanceList();
            ExchangeTicker     btcTicker = getExchangeTicker(Name, "BTC", USDSymbol);

            if (list.Count > 0)
            {
                if (clear)
                {
                    ClearBalances(Name);
                }

                foreach (CCEXBalance balance in list)
                {
                    if (balance.Balance > 0)
                    {
                        if (balance.Currency != "BTC" && balance.Currency != USDSymbol)
                        {
                            // GET TICKER FOR PAIR IN BTC MARKET
                            ExchangeTicker ticker = getExchangeTicker(Name, balance.Currency.ToUpper(), "BTC");

                            if (ticker != null)
                            {
                                Decimal orders = balance.Balance - balance.Available;
                                if (orders > 0)
                                {
                                    balance.TotalInBTCOrders = orders * ticker.last;
                                }

                                balance.TotalInBTC = balance.Balance * ticker.last;
                                balance.TotalInUSD = btcTicker.last * balance.TotalInBTC;
                            }
                            else
                            {
                                LogManager.AddLogMessage(Name, "updateExchangeBalanceList", "EXCHANGE TICKER WAS NULL : " + Name + " | " + balance.Currency.ToUpper());
                            }
                        }
                        else
                        {
                            //LogManager.AddLogMessage(Name, "updateExchangeBalanceList", "CHECKING CURRENCY :" + balance.Currency, LogManager.LogMessageType.DEBUG);
                            if (balance.Currency == "BTC")
                            {
                                Decimal orders = balance.Balance - balance.Available;
                                if (orders > 0)
                                {
                                    balance.TotalInBTCOrders = orders;
                                }

                                balance.TotalInBTC = balance.Balance;
                                balance.TotalInUSD = btcTicker.last * balance.Balance;
                            }
                            else if (balance.Currency == USDSymbol)
                            {
                                Decimal orders = balance.Balance - balance.Available;
                                if (orders > 0)
                                {
                                    balance.TotalInBTCOrders = orders / btcTicker.last;
                                }

                                if (btcTicker.last > 0)
                                {
                                    balance.TotalInBTC = balance.Balance / btcTicker.last;
                                }
                                balance.TotalInUSD = balance.Balance;
                            }
                        }
                        //LogManager.AddLogMessage(Name, "updateExchangeBalanceList", balance.Currency + " | " + balance.Balance + " | " + balance.TotalInBTC + " | " + balance.TotalInUSD, LogManager.LogMessageType.DEBUG);
                        processBalance(balance.GetExchangeBalance());
                    }
                }
            }
        }
示例#9
0
 // Extension method to calculate ExchangeTicker bid/ask spread
 public static decimal BidAskSpread(this ExchangeTicker t)
 {
     return(t.Ask - t.Bid);
 }
示例#10
0
 // Extension method to calculate ExchangeTicker mid price (bid/ask average price--not weighted)
 public static decimal MidPrice(this ExchangeTicker t)
 {
     return((t.Bid + t.Ask) / 2.0M);
 }