public (CryptoCoinId best, CryptoCoinId leastWorst, decimal profit, decimal fees) GetBestPair(
            CryptoExchangeId from, CryptoExchangeId to
            )
        {
            var compare = GetAll();

            var(best, leastWorst, profit) = GetBestPair(compare, from, to);
            var fromExchange = Exchanges[from];
            var toExchange   = Exchanges[to];

            decimal wFeeFirst  = 0;
            decimal wFeeSecond = 0;

            try
            {
                wFeeFirst  = fromExchange.WithdrawalFees[best];
                wFeeSecond = toExchange.WithdrawalFees[leastWorst];
            }
            catch { }

            var fees =
                fromExchange[best].Buy(fromExchange.DepositFees[CryptoCoinId.BTC]) +
                fromExchange[best].Sell(wFeeFirst) +
                toExchange[leastWorst].Buy(toExchange.DepositFees[CryptoCoinId.BTC]) +
                toExchange[leastWorst].Sell(wFeeSecond);


            //var fees =
            //    fromExchange[best].Buy(fromExchange.DepositFees[best]) +
            //    fromExchange[best].Sell(fromExchange.WithdrawalFees[best]) +
            //    toExchange[leastWorst].Buy(toExchange.DepositFees[leastWorst]) +
            //    toExchange[leastWorst].Sell(toExchange.WithdrawalFees[leastWorst]);

            return(best, leastWorst, profit, fees);
        }
        public CoinMap GetPair(CryptoExchangeId from, CryptoExchangeId to)
        {
            if (!Exchanges.ContainsKey(from) || !Exchanges.ContainsKey(to))
            {
                return(null);
            }

            var result  = new CoinMap();
            var symbols =
                Exchanges[from].ExchangeData.Keys
                .Intersect(Exchanges[to].ExchangeData.Keys)
                .ToList();

            foreach (var symbol in symbols)
            {
                var buy  = Exchanges[from].ExchangeData[symbol].BuyPrice;
                var sell = Exchanges[to].ExchangeData[symbol].SellPrice;

                if (buy == 0 || sell == 0 || symbol == CryptoCoinId.NULL)
                {
                    continue;
                }

                result[symbol] = (sell - buy) / buy;
            }

            return(result);
        }
 public CryptoExchange Get(CryptoExchangeId id) =>
 Context.Exchanges
 .Include(x => x.WithdrawalFees)
 .Include(x => x.WithdrawalFees.Select(f => f.Coin))
 .Include(x => x.DepositFees)
 .Include(x => x.WithdrawalFees.Select(f => f.Coin))
 .FirstOrDefault(x => x.Id == id);
 public async Task <IEnumerable <CryptoCoinValue> > GetAllAsync(
     CryptoExchangeId exchangeId,
     CancellationToken cancellationToken) =>
 await AllEntities
 .Where(x => x.ExchangeId == exchangeId)
 .ToListAsync(cancellationToken)
 .ConfigureAwait(false);
Пример #5
0
        public CryptoExchange(
            CryptoExchangeId id,
            string name,
            string url,
            string tickerUrl,
            decimal buyFees     = 0,
            decimal sellFees    = 0,
            DateTime?lastUpdate = null,
            DateTime?lastChange = null,
            IDictionary <CryptoCoinId, decimal> withdrawalFees = null,
            IDictionary <CryptoCoinId, decimal> depositFees    = null
            )
        {
            Id         = id;
            Name       = name;
            Url        = url;
            TickerUrl  = tickerUrl;
            BuyFees    = buyFees;
            SellFees   = sellFees;
            LastUpdate = lastUpdate;
            LastChange = lastChange;

            WithdrawalFees = withdrawalFees?
                             .Select(x => new WithdrawalFees(x.Key, id, x.Value))
                             .ToList( );
            DepositFees = depositFees?
                          .Select(x => new DepositFees(x.Key, id, x.Value))
                          .ToList( );
        }
 public PercentChangeSubscription(CryptoExchangeId exchangeId,
                                  decimal threshold,
                                  IEnumerable <string> symbols)
 {
     ExchangeId = exchangeId;
     Threshold  = threshold;
     Symbols    = ImmutableHashSet <string> .Empty.Union(symbols.Select(x => x.ToUpper( )));
 }
Пример #7
0
 public ICryptoExchange this [CryptoExchangeId index]
 {
     get
     {
         Exchanges.TryGetValue(index, out var exchange);
         return(exchange);
     }
 }
 public CryptoCoinValue(
     CryptoCoinId coinId,
     CryptoExchangeId exchangeId,
     decimal lowestAsk,
     decimal highestBid
     ) :
     this(coinId, exchangeId, lowestAsk, highestBid, DateTime.UtcNow)
 {
 }
 public async Task <IEnumerable <CryptoCoinValue> > GetLastAsync(
     CryptoCoinId coinId,
     CryptoExchangeId exchangeId,
     int count, CancellationToken cancellationToken) =>
 await AllEntities
 .Where(x => x.CoinId == coinId && x.ExchangeId == exchangeId)
 .OrderByDescending(x => x.Time)
 .Take(count)
 .ToListAsync(cancellationToken)
 .ConfigureAwait(false);
Пример #10
0
 public CryptoCoinValue(
     CryptoCoinId coinId,
     CryptoExchangeId exchangeId,
     decimal lowestAsk,
     decimal highestBid,
     DateTime time)
 {
     CoinId     = coinId;
     ExchangeId = exchangeId;
     LowestAsk  = lowestAsk;
     HighestBid = highestBid;
     Time       = time;
 }
 public TelegramPercentChangeSubscription(ChatId chatId,
                                          User user,
                                          CryptoExchangeId exchangeId,
                                          decimal threshold,
                                          bool isSilent,
                                          IEnumerable <string> symbols) :
     base(exchangeId, threshold, symbols)
 {
     ChatId    = chatId;
     User      = user;
     Threshold = threshold;
     IsSilent  = isSilent;
 }
 public CryptoCoinValue AddCoinValue(
     CryptoCoinId coinId,
     CryptoExchangeId exchangeId,
     decimal lowestAsk,
     decimal highestBid,
     DateTime time) =>
 Add(new CryptoCoinValue(
         coinId,
         exchangeId,
         lowestAsk,
         highestBid,
         time)
     );
        public static (CryptoCoinId best, CryptoCoinId leastWorst, decimal profit) GetBestPair(
            Dictionary <CryptoExchangeId, ExchangeToCoinMap> compare,
            CryptoExchangeId from,
            CryptoExchangeId to
            )
        {
            var best       = compare[from][to].MaxBy(x => x.Value).Key;
            var leastWorst = compare[to][from].MaxBy(x => x.Value).Key;
            var profit     = (1m + compare[from][to][best])
                             * (1m + compare[to][from][leastWorst])
                             - 1m;

            return(best, leastWorst, profit);
        }
 public void AddExchange(
     CryptoExchangeId id,
     string name,
     string url,
     string tickerUrl,
     decimal buyFees     = 0,
     decimal sellFees    = 0,
     DateTime?lastUpdate = null,
     DateTime?lastChange = null,
     IDictionary <CryptoCoinId, decimal> withdrawalFees = null,
     IDictionary <CryptoCoinId, decimal> depositFees    = null
     ) =>
 Context.Exchanges.Add(new CryptoExchange(id, name, url, tickerUrl,
                                          buyFees, sellFees, lastUpdate, lastChange,
                                          withdrawalFees, depositFees)
                       );
        public ExchangeToCoinMapCompare GetAllCompare(CryptoExchangeId from)
        {
            if (!Exchanges.ContainsKey(from))
            {
                return(null);
            }

            var result = new ExchangeToCoinMapCompare();

            foreach (var to in Exchanges.Keys)
            {
                if (from == to)
                {
                    continue;
                }

                result[to] = GetPairCompare(from, to);
            }

            return(result);
        }
        public TeleSubscription Add(
            CryptoExchangeId exchangeId,
            long chatId,
            string userName,
            decimal threshold,
            IEnumerable <CryptoCoinId> coinIds,
            IDictionary <CryptoCoinId, CryptoCoinValue> lastSignificantPrice = null,
            DateTime?startDate = null,
            DateTime?endDate   = null
            )
        {
            var coins = Context.Coins.ToList( ).Where(x => coinIds.Contains(x.Id));

            var sub = new TeleSubscription(
                exchangeId, chatId, userName, threshold,
                coins, lastSignificantPrice,
                startDate, endDate
                );

            Add(sub);

            return(sub);
        }
Пример #17
0
 public WithdrawalFees(CryptoCoinId coinId, CryptoExchangeId exchangeId, decimal value)
 {
     CoinId     = coinId;
     ExchangeId = exchangeId;
     Value      = value;
 }
        public CoinMapCompare GetPairCompare(CryptoExchangeId from, CryptoExchangeId to)
        {
            if (!Exchanges.ContainsKey(from) || !Exchanges.ContainsKey(to))
            {
                return(null);
            }

            var result  = new CoinMapCompare();
            var symbols =
                Exchanges[from].ExchangeData.Keys
                .Intersect(Exchanges[to].ExchangeData.Keys)
                .ToList();

            foreach (var symbol in symbols)
            {
                var buy  = Exchanges[from].ExchangeData[symbol].BuyPrice;
                var sell = Exchanges[to].ExchangeData[symbol].SellPrice;

                if (buy == 0 || sell == 0 || symbol == CryptoCoinId.NULL)
                {
                    continue;
                }

                CoinMapModel c = new CoinMapModel();

                c.Coin = symbol;
                c.From = from.ToString();
                c.To   = to.ToString();
                c.Buy  = buy;
                c.Sell = sell;

                // var profit = (1m + compare[from][to][best])
                //* (1m + compare[to][from][leastWorst])
                //- 1m;

                c.Profit           = sell - buy;
                c.ProfitINR        = FiatConverter.Convert(c.Profit, FiatCurrency.USD, FiatCurrency.INR); // 0; // TODO
                c.ProfitPercentage = (sell - buy) / buy;

                if (c.Profit <= 0)
                {
                    continue;
                }

                var     fromExchange  = Exchanges[from];
                decimal withdrawalFee = 0;
                try
                {
                    withdrawalFee = fromExchange.WithdrawalFees[symbol];
                }
                catch { }
                c.WithdrawFee = withdrawalFee;

                var fees = fromExchange[symbol].Buy(fromExchange.DepositFees[CryptoCoinId.BTC]) +
                           fromExchange[symbol].Sell(withdrawalFee);

                c.minInvestment = fees / c.Profit;


                result[symbol] = c;
            }

            return(result);
        }
Пример #19
0
 public CryptoCoinValue ToCryptoCoinValue(CryptoExchangeId exchangeId) =>
 new CryptoCoinValue(Id, exchangeId, LowestAsk, HighestBid, Time);
 public IEnumerable <TeleSubscription> GetAll(CryptoExchangeId exchangeId) =>
 AllEntities.Where(x => x.ExchangeId == exchangeId).ToList( );
Пример #21
0
 public DepositFees(CryptoCoinId coinId, CryptoExchangeId exchangeId, decimal value)
 {
     CoinId     = coinId;
     ExchangeId = exchangeId;
     Value      = value;
 }
        public bool UpdateExchange(
            CryptoExchangeId id,
            string name         = null,
            string url          = null,
            string tickerUrl    = null,
            decimal buyFees     = -1,
            decimal sellFees    = -1,
            DateTime?lastUpdate = null,
            DateTime?lastChange = null,
            IDictionary <CryptoCoinId, decimal> withdrawalFees = null,
            IDictionary <CryptoCoinId, decimal> depositFees    = null
            )
        {
            var exchange = Context.Exchanges.FirstOrDefault(x => x.Id == id);

            if (exchange == null)
            {
                return(false);
            }

            if (name != null)
            {
                exchange.Name = name;
            }
            if (url != null)
            {
                exchange.Url = url;
            }
            if (tickerUrl != null)
            {
                exchange.TickerUrl = tickerUrl;
            }
            if (buyFees != -1)
            {
                exchange.BuyFees = buyFees;
            }
            if (sellFees != -1)
            {
                exchange.SellFees = sellFees;
            }
            if (lastUpdate != null)
            {
                exchange.LastUpdate = lastUpdate;
            }
            if (lastChange != null)
            {
                exchange.LastChange = lastChange;
            }
            if (withdrawalFees != null)
            {
                exchange.WithdrawalFees = withdrawalFees
                                          .Select(x => new WithdrawalFees(x.Key, id, x.Value))
                                          .ToList( );
            }
            if (depositFees != null)
            {
                exchange.DepositFees = depositFees
                                       .Select(x => new DepositFees(x.Key, id, x.Value))
                                       .ToList( );
            }

            return(true);
        }
Пример #23
0
 public bool TryGetExchange(CryptoExchangeId exchangeId,
                            out ICryptoExchange exchange) =>
 Exchanges.TryGetValue(exchangeId, out exchange);
 public CryptoExchangeBase this [CryptoExchangeId exchangeId] =>
 Exchanges[exchangeId];
Пример #25
0
		public Graph ( CryptoExchangeId exchangeId ) :
			base ( symbol => new Node ( symbol ) )
		{
			ExchangeId = exchangeId;
		}