Example #1
0
        public static DepositLimitsResult DepositLimits(RuntimeConfig rcfg, TradableCurrency ethereumToken)
        {
            //TODO: -> const
            const int cryptoAccuracy = 8;
            var       decimals       = cryptoAccuracy;
            var       min            = 0d;
            var       max            = 0d;

            if (ethereumToken == TradableCurrency.Eth)
            {
                decimals = TokensPrecision.Ethereum;
                min      = rcfg.Gold.PaymentMehtods.EthDepositMinEther;
                max      = rcfg.Gold.PaymentMehtods.EthDepositMaxEther;
            }

            if (min > 0 && max > 0)
            {
                var pow = BigInteger.Pow(10, decimals - cryptoAccuracy);
                return(new DepositLimitsResult()
                {
                    Min = new BigInteger((long)Math.Floor(min * Math.Pow(10, cryptoAccuracy))) * pow,
                    Max = new BigInteger((long)Math.Floor(max * Math.Pow(10, cryptoAccuracy))) * pow,
                });
            }

            throw new NotImplementedException($"{ethereumToken} currency is not implemented");
        }
Example #2
0
        public static BigInteger SellingFeeForCrypto(TradableCurrency ethereumToken, BigInteger amount)
        {
            // 0.1% - round down
            if (ethereumToken == TradableCurrency.Eth)
            {
                return(amount / new BigInteger(1000));
            }

            return(BigInteger.Zero);
        }
Example #3
0
        public static BigInteger AssetPerGold(TradableCurrency ethereumToken, long centsPerAssetRate, long centsPerGoldRate)
        {
            var decimals = 0;

            if (ethereumToken == TradableCurrency.Eth)
            {
                decimals = TokensPrecision.Ethereum;
            }
            else
            {
                throw new NotImplementedException($"Not implemented for { ethereumToken.ToString() }");
            }

            // round down
            return(new BigInteger(centsPerGoldRate) * BigInteger.Pow(10, decimals) / new BigInteger(centsPerAssetRate));
        }
Example #4
0
        public static async Task <SellGoldCryptoResult> SellGoldCryptoRev(
            IServiceProvider services,
            TradableCurrency ethereumToken,
            FiatCurrency fiatCurrency,
            BigInteger requiredCryptoAmountWithFee,
            long?knownGoldRateCents   = null,
            long?knownCryptoRateCents = null
            )
        {
            if (requiredCryptoAmountWithFee <= 0)
            {
                return(new SellGoldCryptoResult());
            }

            var pricer     = services.GetRequiredService <IPriceSource>();
            var cryptoRate = (long?)0L;
            var decimals   = 0;

            if (ethereumToken == TradableCurrency.Eth)
            {
                decimals   = TokensPrecision.Ethereum;
                cryptoRate = pricer.GetPriceInFiat(CurrencyPrice.Eth, fiatCurrency);
            }
            else
            {
                throw new NotImplementedException($"Not implemented for { ethereumToken.ToString() }");
            }

            cryptoRate = knownCryptoRateCents ?? cryptoRate;
            if (cryptoRate == null || cryptoRate <= 0)
            {
                return(new SellGoldCryptoResult()
                {
                    Status = SellGoldStatus.TradingDisallowed,
                });
            }

            var goldRate = knownGoldRateCents ?? pricer.GetPriceInFiat(CurrencyPrice.Gold, fiatCurrency);

            if (goldRate == null || goldRate <= 0)
            {
                return(new SellGoldCryptoResult()
                {
                    Status = SellGoldStatus.TradingDisallowed,
                });
            }

            var assetPerGold = AssetPerGold(ethereumToken, cryptoRate.Value, goldRate.Value);

            // round up
            var goldAmount = (requiredCryptoAmountWithFee * BigInteger.Pow(10, decimals) + assetPerGold - 1) / assetPerGold;

            return(new SellGoldCryptoResult()
            {
                Allowed = true,
                Status = SellGoldStatus.Success,
                Asset = ethereumToken,
                ExchangeCurrency = fiatCurrency,
                CentsPerGoldRate = goldRate.Value,
                CentsPerAssetRate = cryptoRate.Value,
                CryptoPerGoldRate = assetPerGold,
                ResultGoldAmount = goldAmount,
                ResultAssetAmount = requiredCryptoAmountWithFee,
            });
        }
Example #5
0
        public static async Task <BuyGoldCryptoResult> BuyGoldCryptoRev(
            IServiceProvider services,
            TradableCurrency ethereumToken,
            FiatCurrency fiatCurrency,
            BigInteger requiredGoldAmount,
            long?knownGoldRateCents   = null,
            long?knownCryptoRateCents = null,
            double discount           = 0d
            )
        {
            if (requiredGoldAmount <= 0)
            {
                return(new BuyGoldCryptoResult());
            }

            var pricer     = services.GetRequiredService <IPriceSource>();
            var cryptoRate = (long?)0L;

            if (ethereumToken == TradableCurrency.Eth)
            {
                cryptoRate = pricer.GetPriceInFiat(CurrencyPrice.Eth, fiatCurrency);
            }
            else
            {
                throw new NotImplementedException($"Not implemented for { ethereumToken.ToString() }");
            }

            cryptoRate = knownCryptoRateCents ?? cryptoRate;
            if (cryptoRate == null || cryptoRate <= 0)
            {
                return(new BuyGoldCryptoResult()
                {
                    Status = BuyGoldStatus.TradingDisallowed,
                });
            }

            var goldRate = knownGoldRateCents ?? pricer.GetPriceInFiat(CurrencyPrice.Gold, fiatCurrency);

            if (goldRate == null || goldRate <= 0)
            {
                return(new BuyGoldCryptoResult()
                {
                    Status = BuyGoldStatus.TradingDisallowed,
                });
            }

            var assetPerGold = AssetPerGold(ethereumToken, cryptoRate.Value, goldRate.Value);

            // round up
            var cryptoAmount = (requiredGoldAmount * assetPerGold + BigInteger.Pow(10, TokensPrecision.Sumus) - 1) / BigInteger.Pow(10, TokensPrecision.Sumus);

            // discount
            var cryptoAmountMinusDiscount = GetDiscountRevBody(discount, cryptoAmount);

            if (cryptoAmountMinusDiscount < 1)
            {
                cryptoAmountMinusDiscount = 1;
            }

            return(new BuyGoldCryptoResult()
            {
                Allowed = true,
                Status = BuyGoldStatus.Success,
                Asset = ethereumToken,
                ExchangeCurrency = fiatCurrency,
                Discount = discount,
                CentsPerAssetRate = cryptoRate.Value,
                CentsPerGoldRate = goldRate.Value,
                CryptoPerGoldRate = assetPerGold,
                ResultAssetAmount = cryptoAmountMinusDiscount,
                ResultGoldAmount = requiredGoldAmount,
            });
        }