Exemplo n.º 1
0
        /// <summary>
        /// Place a 'fake' order on the 'fake' exchange market
        /// </summary>
        /// <param name="assetName"></param>
        /// <param name="orderType"></param>
        /// <param name="dt"></param>
        /// <param name="price"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        protected virtual bool PlaceOrder(AssetSymbol assetName, Trade.TOrderType orderType, DateTime dt, double price, double amount)
        {
            var t = new Trade();

            t.Timestamp = dt;
            t.RefPrice  = price;
            t.OrderType = orderType;
            t.Asset     = assetName;

            var     bal     = Balances(dt);
            var     balance = bal[assetName.BaseName];
            var     fees    = Fees((price * amount), orderType);
            decimal total   = (decimal)((price * amount) - fees);

            t.Quantity = (double)amount;
            if (orderType == Trade.TOrderType.Buy)
            {
                balance += (decimal)amount;
                _assetPortfolio[assetName.QuoteName] -= (double)total;
            }
            else
            {
                balance -= (decimal)amount;
                _assetPortfolio[assetName.QuoteName] += (double)total;
            }

            _assetPortfolio[assetName.BaseName] = (double)balance;

            _tradeHistory.Add(t);
            return(true);
        }
        /// <summary>
        /// Return the fees for q Buy or Sell transaction.
        /// </summary>
        /// <param name="whole">The value to apply the fee on</param>
        /// <param name="oType">Buy or Sell order.</param>
        /// <returns></returns>
        public virtual double Fees(double whole, Trade.TOrderType oType)
        {
            var fee = oType == Trade.TOrderType.Buy?_krakenFeeBuy:_krakenFeeSell;

            return((whole * fee) / 100);
        }