Esempio n. 1
0
        /// <summary>
        /// Executes a sell for the given trade and updated the entity.
        /// </summary>
        /// <param name="trade"></param>
        /// <param name="currentRateBid">Rate to sell for</param>
        /// <param name="balance">Amount to sell for</param>
        /// <returns>Current profit as percentage</returns>
        private async Task <double> ExecuteSellOrder(Trade trade, double currentRateBid, double balance)
        {
            // Calculate our profit.
            var investment = (Constants.AmountOfBtcToInvestPerTrader * (1 - Constants.TransactionFeePercentage));
            var sales      = (trade.Quantity * currentRateBid) - (trade.Quantity * currentRateBid * Constants.TransactionFeePercentage);
            var profit     = 100 * ((sales - investment) / investment);

            // Sell the thing.
            var orderId = await _api.Sell(trade.Market, balance, currentRateBid);

            trade.CloseRate             = currentRateBid;
            trade.CloseProfitPercentage = profit;
            trade.CloseProfit           = sales - investment;
            trade.CloseDate             = DateTime.UtcNow;
            trade.OpenOrderId           = orderId;
            trade.SellOrderId           = orderId;

            return(profit);
        }
Esempio n. 2
0
        public async Task Sell(string coin, double price, double quantity)
        {
            if (price > 1)
            {
                price = price / 100000000;
            }

            ConsoleHelpers.WriteColored($"\tWARNING: GOING TO SELL {quantity:0.00000000} {coin} at a rate of {price:0.00000000}, " +
                                        $"DO YOU WANT TO CONTINUE? (YES/NO) ", ConsoleColor.Yellow);

            if (Console.ReadLine()?.ToLower() == "yes")
            {
                await _bittrexApi.Sell("BTC-" + coin.ToUpper(), quantity, price);

                ConsoleHelpers.WriteColoredLine("\tSell order placed.", ConsoleColor.Green);
            }
            else
            {
                ConsoleHelpers.WriteColoredLine("\tSell cancelled.", ConsoleColor.Red);
            }
        }