Exemplo n.º 1
0
        public Account(
            IHdWallet wallet,
            SecureString password,
            ICurrenciesProvider currenciesProvider,
            ISymbolsProvider symbolsProvider)
        {
            Wallet = wallet ?? throw new ArgumentNullException(nameof(wallet));

            Currencies = currenciesProvider.GetCurrencies(Network);
            Symbols    = symbolsProvider.GetSymbols(Network);

            DataRepository = new LiteDbAccountDataRepository(
                pathToDb: $"{Path.GetDirectoryName(Wallet.PathToWallet)}/{DefaultDataFileName}",
                password: password,
                currencies: Currencies,
                network: wallet.Network);

            CurrencyAccounts = Currencies
                               .ToDictionary(
                c => c.Name,
                c => CurrencyAccountCreator.Create(
                    currency: c.Name,
                    wallet: Wallet,
                    dataRepository: DataRepository,
                    currencies: Currencies));

            UserSettings = UserSettings.TryLoadFromFile(
                pathToFile: $"{Path.GetDirectoryName(Wallet.PathToWallet)}/{DefaultUserSettingsFileName}",
                password: password) ?? UserSettings.DefaultSettings;
        }
Exemplo n.º 2
0
        private Symbol[,] GenerateReels()
        {
            var machine = new Symbol[_reelSymbolsCount, _reelsCount];

            for (int symbolIndex = 0; symbolIndex < _reelSymbolsCount; symbolIndex++)
            {
                for (int reelIndex = 0; reelIndex < _reelsCount; reelIndex++)
                {
                    var symbol = _randomSymbolGenerator.Generate(_symbolsProvider.GetSymbols());
                    machine[symbolIndex, reelIndex] = symbol;
                }
            }

            return(machine);
        }
Exemplo n.º 3
0
        public static Task <SwapPriceEstimation> EstimateSwapPriceAsync(
            decimal amount,
            AmountType amountType,
            CurrencyConfig fromCurrency,
            CurrencyConfig toCurrency,
            IAccount account,
            IAtomexClient atomexClient,
            ISymbolsProvider symbolsProvider,
            CancellationToken cancellationToken = default)
        {
            return(Task.Run(() =>
            {
                if (fromCurrency == null)
                {
                    return null;
                }

                if (toCurrency == null)
                {
                    return null;
                }

                var symbol = symbolsProvider
                             .GetSymbols(account.Network)
                             .SymbolByCurrencies(fromCurrency, toCurrency);

                if (symbol == null)
                {
                    return null;
                }

                var side = symbol.OrderSideForBuyCurrency(toCurrency);
                var orderBook = atomexClient.GetOrderBook(symbol);

                if (orderBook == null)
                {
                    return null;
                }

                var baseCurrency = account.Currencies.GetByName(symbol.Base);

                var isSoldAmount = amountType == AmountType.Sold;

                var(estimatedOrderPrice, estimatedPrice) = orderBook.EstimateOrderPrices(
                    side: side,
                    amount: amount,
                    amountDigitsMultiplier: isSoldAmount
                        ? fromCurrency.DigitsMultiplier
                        : toCurrency.DigitsMultiplier,
                    qtyDigitsMultiplier: baseCurrency.DigitsMultiplier,
                    amountType: amountType);

                var(estimatedMaxFromAmount, estimatedMaxToAmount) = orderBook.EstimateMaxAmount(side, fromCurrency.DigitsMultiplier);

                var isNoLiquidity = amount != 0 && estimatedOrderPrice == 0;

                var oppositeAmount = isSoldAmount
                    ? symbol.IsBaseCurrency(toCurrency.Name)
                        ? estimatedPrice != 0
                            ? AmountHelper.RoundDown(amount / estimatedPrice, toCurrency.DigitsMultiplier)
                            : 0m
                        : AmountHelper.RoundDown(amount * estimatedPrice, toCurrency.DigitsMultiplier)
                    : symbol.IsBaseCurrency(toCurrency.Name)
                        ? AmountHelper.RoundDown(amount * estimatedPrice, fromCurrency.DigitsMultiplier)
                        : estimatedPrice != 0
                            ? AmountHelper.RoundDown(amount / estimatedPrice, fromCurrency.DigitsMultiplier)
                            : 0m;

                return new SwapPriceEstimation
                {
                    FromAmount = isSoldAmount ? amount : oppositeAmount,
                    ToAmount = isSoldAmount ? oppositeAmount : amount,
                    OrderPrice = estimatedOrderPrice,
                    Price = estimatedPrice,
                    MaxFromAmount = estimatedMaxFromAmount,
                    MaxToAmount = estimatedMaxToAmount,
                    IsNoLiquidity = isNoLiquidity
                };
            }, cancellationToken));
        }