public BittrexExchangeMarket(BittrexExchange aExchangeInstance, ICurrencyIdentity aCurrency, GetWalletIDDelegate aGetWalletIDFunction, BittrexSymbol aMarketPair) : base(aExchangeInstance)
 {
     SellingCurrencyInfo = aCurrency;
     BuyingCurrencyInfo  = new CurrencyInfo(aGetWalletIDFunction)
     {
         Ticker = aMarketPair.BaseCurrency == aCurrency.Ticker ? aMarketPair.QuoteCurrency : aMarketPair.BaseCurrency,
         Name   = aMarketPair.BaseCurrency == aCurrency.Ticker ? aMarketPair.QuoteCurrency : aMarketPair.BaseCurrency,
         Id     = aGetWalletIDFunction?.Invoke(aMarketPair.BaseCurrency == aCurrency.Ticker ? aMarketPair.QuoteCurrency : aMarketPair.BaseCurrency) ?? 0
     };
     MarketPairID           = aMarketPair.Symbol;
     MarketBaseCurrencyInfo = string.Equals(aMarketPair.BaseCurrency, aCurrency.Ticker, StringComparison.OrdinalIgnoreCase) ? BuyingCurrencyInfo : SellingCurrencyInfo;
     MinimumTrade           = aMarketPair.MinTradeSize;
 }
Пример #2
0
 public CurrencyInfo(GetWalletIDDelegate aGetWalletIDFunction)
 {
     FGetWalletIDFunction = aGetWalletIDFunction;
 }
        public IEnumerable <IExchangeMarket> GetMarketCoins(ICurrencyIdentity aCurrency, GetWalletIDDelegate aGetWalletIDFunction)
        {
            DoUpdateMarketCoins().Wait();
            if (!FLocalCacheOfMarkets.TryGetValue(aCurrency.Id, out IEnumerable <BittrexExchangeMarket> lCoinMarkets))
            {
                lCoinMarkets = FMarkets.Where(x => x.Status == SymbolStatus.Online && (x.QuoteCurrency == aCurrency.Ticker || x.BaseCurrency == aCurrency.Ticker))
                               .Select(lMarket => new BittrexExchangeMarket(this, aCurrency, aGetWalletIDFunction, lMarket)).ToArray();
                if (aGetWalletIDFunction != null)
                {
                    FLocalCacheOfMarkets.TryAdd(aCurrency.Id, lCoinMarkets);
                }
            }

            return(lCoinMarkets);
        }
Пример #4
0
        /// <summary>
        /// Loads currency exchange orders from disk. This should only be called once or to reload orders.
        /// </summary>
        /// <param name="aCurrencyTicker"></param>
        /// <param name="aCurrencyID"></param>
        /// <returns></returns>
        public IEnumerable <UserTradeOrder> LoadOrders(ICurrencyIdentity aCurrency, IPandoraExchangeFactory lExchangeFactory, GetWalletIDDelegate aGetWalletIDFunction)
        {
            var lResult   = new List <UserTradeOrder>();
            var lDBOrders = FSaveManager.ReadOrders(aCurrency);

            if (lDBOrders != null && lDBOrders.Any())
            {
                int lErrorCounter;
                var lMarketCache = new Dictionary <int, IEnumerable <IExchangeMarket> >();
                foreach (var lDBOrder in lDBOrders)
                {
                    bool lOrdersLogs = FSaveManager.ReadOrderLogs(lDBOrder.InternalID, out List <OrderMessage> lMessages);
                    lMessages     = lMessages.OrderBy(lMessage => lMessage.Time).ToList();
                    lErrorCounter = 0;
                    for (int it2 = 0; it2 < lMessages.Count; it2++)
                    {
                        OrderMessage lIndividualMessage = lMessages[it2];

                        switch (lIndividualMessage.Level)
                        {
                        case OrderMessage.OrderMessageLevel.Error:
                            lErrorCounter += 60;
                            break;

                        case OrderMessage.OrderMessageLevel.StageChange:
                            lErrorCounter = 0;
                            break;

                        case OrderMessage.OrderMessageLevel.FatalError:
                            lErrorCounter = -1;
                            break;
                        }
                        if (lErrorCounter == -1)
                        {
                            break;
                        }
                    }

                    var lExchanger = lExchangeFactory.GetPandoraExchange((AvailableExchangesList)lDBOrder.ExchangeID);
                    if (!lMarketCache.TryGetValue(lDBOrder.ExchangeID, out IEnumerable <IExchangeMarket> lMarkets))
                    {
                        lMarkets = lExchanger.GetMarketCoins(aCurrency, aGetWalletIDFunction);
                        lMarketCache.Add(lDBOrder.ExchangeID, lMarkets);
                    }
                    var lUserOrder = new UserTradeOrder
                    {
                        InternalID   = lDBOrder.InternalID,
                        ID           = lDBOrder.ID,
                        Name         = lDBOrder.Name,
                        SentQuantity = lDBOrder.SentQuantity,
                        Status       = lDBOrder.Status,
                        CoinTxID     = lDBOrder.CoinTxID,
                        StopPrice    = lDBOrder.StopPrice,
                        OpenTime     = lDBOrder.OpenTime,
                        Rate         = lDBOrder.Rate,
                        ProfileID    = lDBOrder.ProfileID,
                        ErrorCounter = lErrorCounter,
                        Completed    = lDBOrder.Completed,
                        Cancelled    = lDBOrder.Cancelled,
                        Market       = lMarkets.FindByMarketID(lDBOrder.MarketID)
                    };
                    if (lUserOrder.Market == null)
                    {
                        Log.Write(LogLevel.Warning, $"Exchange: Unable to find market for order of id {lUserOrder.InternalID} of exchange {lExchanger.Name}");
                        continue;
                    }
                    lResult.Add(lUserOrder);
                    SetOrderInCache(lUserOrder, lDBOrder.ExchangeID);
                }
            }
            return(lResult);
        }
Пример #5
0
            public BitfinexExchangeMarket(BitfinexExchange aExchangeInstance, ICurrencyIdentity aCurrency, GetWalletIDDelegate aGetWalletIDFunction, BitfinexPair aPair) : base(aExchangeInstance)
            {
                var lIsBaseCurrency = string.Equals(aPair.BaseCurrency.FullName, aCurrency.Name, StringComparison.OrdinalIgnoreCase);

                SellingCurrencyInfo = aCurrency;
                var lBuyingCurrencyTicker = lIsBaseCurrency ? aPair.DestinationCurrency.Name : aPair.BaseCurrency.Name;

                BuyingCurrencyInfo = new CurrencyInfo(aGetWalletIDFunction)
                {
                    Ticker = lBuyingCurrencyTicker,
                    Name   = lIsBaseCurrency ? aPair.DestinationCurrency.FullName : aPair.BaseCurrency.FullName,
                    Id     = aGetWalletIDFunction?.Invoke(lBuyingCurrencyTicker) ?? 0
                };
                MarketPairID           = aPair.MarketDetails.Pair;
                MarketBaseCurrencyInfo = lIsBaseCurrency ? SellingCurrencyInfo : BuyingCurrencyInfo;
                MinimumTrade           = aPair.MarketDetails?.MinimumOrderSize ?? 0;
            }
Пример #6
0
 public IEnumerable <IExchangeMarket> GetMarketCoins(ICurrencyIdentity aCurrency, GetWalletIDDelegate aGetWalletIDFunction)
 {
     DoUpdatemarketCoins().Wait();
     if (!FLocalCacheOfMarkets.TryGetValue(aCurrency.Id, out IEnumerable <BitfinexExchangeMarket> lCoinMarkets))
     {
         var lMarketsWithCompleteData = FMarkets.Where(lMarket => lMarket?.BaseCurrency?.FullName != null && lMarket?.DestinationCurrency?.FullName != null);
         lCoinMarkets = lMarketsWithCompleteData.Where(lMarket => string.Equals(lMarket.DestinationCurrency.FullName, aCurrency.Name, StringComparison.OrdinalIgnoreCase) || string.Equals(lMarket.BaseCurrency.FullName, aCurrency.Name, StringComparison.OrdinalIgnoreCase))
                        .Select(lMarket => new BitfinexExchangeMarket(this, aCurrency, aGetWalletIDFunction, lMarket));
         if (aGetWalletIDFunction != null)
         {
             FLocalCacheOfMarkets.TryAdd(aCurrency.Id, lCoinMarkets);
         }
     }
     return(lCoinMarkets);
 }
Пример #7
0
            public PoloniexExchangeMarket(PoloniexExchange aExchangeInstance, ICurrencyIdentity aCurrency, GetWalletIDDelegate aGetWalletIDFunction, string aPairName) : base(aExchangeInstance)
            {
                MarketPairID = string.IsNullOrEmpty(aPairName) ? throw new ArgumentException("Poloniex pair name can not be null or empty") : aPairName;
                var lPoloniexBuyingTicker = GetPairTicker(aPairName, aCurrency.Ticker, out bool lIsBase);
                var lPoloniexBuyingName   = aExchangeInstance.GetPoloniexCurrency(lPoloniexBuyingTicker)?.name ?? throw new Exception("market currency pair info not found");

                SellingCurrencyInfo = aCurrency;
                BuyingCurrencyInfo  = new CurrencyInfo(aGetWalletIDFunction)
                {
                    Ticker = lPoloniexBuyingTicker,
                    Name   = lPoloniexBuyingName,
                    Id     = aGetWalletIDFunction?.Invoke(lPoloniexBuyingTicker) ?? 0
                };
                MarketBaseCurrencyInfo = lIsBase ? BuyingCurrencyInfo : SellingCurrencyInfo;
                MinimumTrade           = 0.0001M; //This info I found it at the web
            }
Пример #8
0
        public IEnumerable <IExchangeMarket> GetMarketCoins(ICurrencyIdentity aCurrency, GetWalletIDDelegate aGetWalletIDFunction)
        {
            DoUpdateMarketCoins().Wait();
            if (!FLocalCacheOfMarkets.TryGetValue(aCurrency.Id, out IEnumerable <PoloniexExchangeMarket> lCoinMarkets))
            {
                lCoinMarkets = FCacheMarkets.Where(lPair => lPair.Key.EndsWith($"_{aCurrency.Ticker}") || lPair.Key.StartsWith($"{aCurrency.Ticker}_"))
                               .Select(lPair => new PoloniexExchangeMarket(this, aCurrency, aGetWalletIDFunction, lPair.Key));
                if (aGetWalletIDFunction != null)
                {
                    FLocalCacheOfMarkets.TryAdd(aCurrency.Id, lCoinMarkets);
                }
            }

            return(lCoinMarkets);
        }