Esempio n. 1
0
        /// <summary>
        /// Removes the specified amount of btc from the components orders of the given order list, starting from the bottom of the lists.
        /// </summary>
        /// <param name="amountToRemove">Amount of btc to remove from each side of this arbitration trade.</param>
        /// <param name="orderList">List of orders to remove the specified amount from.</param>
        private void RemoveAmountFromOrderList(decimal amountToRemove, OrderList orderList)
        {
            //Loop through the list of order components and remove the amount that is being chopped
            //from the round.
            while (amountToRemove > 0)
            {
                //Get the last order from the list
                Order lastOrder = orderList.Last();

                //Remove choppedAmount from the buy and sell sides

                //If the amount to be lost is greater than the order at the bottom of the list,
                //remove that order.
                //Comparison is >= so that when the amount to be chopped is the same as the amount of the order, that order is removed.
                if (amountToRemove >= lastOrder.Amount)
                {
                    amountToRemove -= lastOrder.Amount;
                    orderList.RemoveAt(orderList.Count - 1);
                }

                //Order at the bottom of the tier is larger than the amount that is lost due to rounding;
                //remove chopped amount from only order.
                else
                {
                    lastOrder.Amount -= amountToRemove;

                    //Recalculate the worth for the order with the trade fee multiplier
                    //lastOrder.Worth = lastOrder.Amount*lastOrder.Price*tradeFeeMultiplier;
                    lastOrder.Worth = lastOrder.Amount * lastOrder.Price;

                    //Amount has been subtracted, break from the loop
                    break;
                }
            }
        }
Esempio n. 2
0
        public void CalculateArbitrationOpportunityCosts()
        {
            //Round the amount to 4 decimal places, a requirement for most exchanges.
            RoundAmounts();

            //If all the buy or sell orders were removed, this arbitration opportunity is not valid, so set everything to zero
            if (_buyOrderList.Count <= 0 || _sellOrderList.Count <= 0)
            {
                TotalBuyCost  = 0m;
                TotalSellCost = 0m;
            }

            else
            {
                //Set the buy and sell prices to the price other order on the bottom of each respective list.
                BuyPrice  = _buyOrderList.Last().Price;
                SellPrice = _sellOrderList.Last().Price;

                //Calculate the total buy and sell costs
                TotalBuyCost  = BuyExchange.ApplyFeeToBuyCost(CalculateTotalWorthOfOrderList(_buyOrderList));
                TotalSellCost = SellExchange.ApplyFeeToSellCost(CalculateTotalWorthOfOrderList(_sellOrderList));
            }

            //Calculate profit from total costs
            Profit = TotalSellCost - TotalBuyCost;
        }
        public async Task ColorChosenAsync(EnumColor thisColor)
        {
            var thisCard = OrderList.Last();

            if (thisCard.SpecialType != EnumSpecialType.Wild && thisCard.SpecialType != EnumSpecialType.Change)
            {
                throw new BasicBlankException("Only change or wilds can change colors");
            }
            if (thisColor == EnumColor.None)
            {
                throw new BasicBlankException("Color chosen can't be none");
            }
            if (_delgates.CloseColorScreenAsync == null)
            {
                throw new BasicBlankException("Nobody is closing the color.  Rethink");
            }
            await _delgates.CloseColorScreenAsync.Invoke();

            _gameContainer.SaveRoot !.Status = EnumStatus.Regular;
            Visible = true; //now set this to visible.
            if (_gameContainer.Test !.NoAnimations == false)
            {
                await _gameContainer.Delay !.DelaySeconds(.25);
            }
            if (thisCard.SpecialType == EnumSpecialType.Change)
            {
                if (thisColor == _gameContainer.SaveRoot.TrumpSuit)
                {
                    throw new BasicBlankException("Must choose a different suit for trump");
                }
                _gameContainer.SaveRoot.TrumpSuit = thisColor;
                await base.AfterPlayCardAsync(thisCard);

                return;
            }
            thisCard.Color = thisColor;
            thisCard.Value = 16; //show the highest of the suit.
            await base.AfterPlayCardAsync(thisCard);
        }