Ejemplo n.º 1
0
        public async Task Trade()
        {
            if (!initialized)
            {
                throw new InvalidOperationException("Trader must be Initialized before it can Trade");
            }

            Current = await broker.CheckPriceAsync();

            await reporter.ReportNewPrice(broker, Current);

            LastSale = LastSale ?? Current;
            High     = High == null || High.Value < Current.Value ? Current : High;
            Low      = Low == null || Low.Value > Current.Value ? Current : Low;

            if (Math.Abs(Current.Value - LastSale.Value) < Current.Value * (decimal)config.NoiseThreshold)
            {
                return; // The current activity is too small for us to care
            }
            decimal timeSensitiveThreshold = CalcThresholdWithDecay(Current, LastSale);

            if (Bullish)
            {
                var thresholdValue = High.Value - (timeSensitiveThreshold * (High.Value - Low.Value));
                if (Current.Value < thresholdValue)
                {
                    await reporter.ReportAttemptedSell(broker, Current);

                    await broker.Sell(Current);

                    await reporter.ReportSell(broker, Current);

                    Bullish  = false;
                    Low      = null;
                    LastSale = Current;
                }
            }
            else // if bearish
            {
                var thresholdValue = Low.Value + (timeSensitiveThreshold * (High.Value - Low.Value));
                if (Current.Value > thresholdValue)
                {
                    await reporter.ReportAttemptedBuy(broker, Current);

                    await broker.Buy(Current);

                    await reporter.ReportBuy(broker, Current);

                    Bullish  = true;
                    High     = null;
                    LastSale = Current;
                }
            }
        }
Ejemplo n.º 2
0
        public Boolean Buy()
        {
            MarketOrderBook ob     = _broker.returnMarketOrderBook(_TradedPair, 20);
            Double          amount = SourceWallet.amount;

            while (amount > Convert.ToDouble(ConfigurationManager.AppSettings["Minimum_trade"]))
            {
                TradeDone order = _broker.Buy(_TradedPair, ob.GetTheNextAsks().rate, amount);
                amount = amount - order.totalAmountDoneSourceCurrency;
            }
            return(false);
        }