Пример #1
0
        // TODO no tuple?
        public static async Task <(decimal purchaseAmount, decimal quantity)> CalcPurchasePrice(
            this TradingPair tradingPair,
            decimal purchasePriceInBase)
        {
            decimal purchaseAmount = 0;
            decimal quantity       = 0;

            OrderBook orderBook = await tradingPair.GetOrderBook();

            for (int i = 0; i < orderBook.asksOrOffersYouCanBuy.Length; i++)
            {
                Order   order = orderBook.asksOrOffersYouCanBuy[i];
                decimal purchaseAmountFromOrder = Math.Min(purchasePriceInBase,
                                                           order.price * order.volume);

                purchaseAmount      += purchaseAmountFromOrder;
                quantity            += purchaseAmountFromOrder / order.price;
                purchasePriceInBase -= purchaseAmountFromOrder;

                if (purchasePriceInBase <= 0)
                {
                    break;
                }
            }

            return(purchaseAmount, quantity);
        }
Пример #2
0
        public async Task OrderBook()
        {
            CrypnosticConfig config = new CrypnosticConfig(exchangeName);

            monitor = new CrypnosticController(config);
            await monitor.Start();

            TradingPair tradingPair = popularQuoteCoin.GetTradingPair(popularBaseCoin, exchangeName);
            OrderBook   orderBook   = await tradingPair.GetOrderBook();

            Assert.IsTrue(orderBook.asksOrOffersYouCanBuy.Length > 0);
            Assert.IsTrue(orderBook.asksOrOffersYouCanBuy[0].price > 0);
            Assert.IsTrue(orderBook.asksOrOffersYouCanBuy[0].volume > 0);
            Assert.IsTrue(orderBook.bidsOrOffersYouCanSell.Length > 0);
            Assert.IsTrue(orderBook.bidsOrOffersYouCanSell[0].price > 0);
            Assert.IsTrue(orderBook.bidsOrOffersYouCanSell[0].volume > 0);

            Assert.IsTrue(orderBook.asksOrOffersYouCanBuy[0].price >= orderBook.bidsOrOffersYouCanSell[0].price);
            Assert.IsTrue(orderBook.asksOrOffersYouCanBuy[1].price >= orderBook.asksOrOffersYouCanBuy[0].price);
            Assert.IsTrue(orderBook.bidsOrOffersYouCanSell[0].price >= orderBook.bidsOrOffersYouCanSell[1].price);
        }
Пример #3
0
        public static async Task <decimal> CalcSellPrice(
            this TradingPair tradingPair,
            decimal quantityOfCoin)
        {
            decimal sellAmount = 0;

            OrderBook orderBook = await tradingPair.GetOrderBook();

            for (int i = 0; i < orderBook.bidsOrOffersYouCanSell.Length; i++)
            {
                Order   order = orderBook.bidsOrOffersYouCanSell[i];
                decimal sellAmountFromOrder = Math.Min(quantityOfCoin, order.volume);

                sellAmount     += sellAmountFromOrder * order.price;
                quantityOfCoin -= sellAmountFromOrder;

                if (quantityOfCoin <= 0)
                {
                    break;
                }
            }

            return(sellAmount);
        }