Example #1
0
        protected TradingData GetNewTradingData()
        {
            CoinPairHelper cph = new CoinPairHelper(_settings);

            return(new TradingData()
            {
                CoinPair = cph.GetCoinPair()
            });
        }
Example #2
0
        public override void Trade(List <TradingData> tradesList)
        {
            if (tradesList.Count > 0)
            {
                // Check for stop losses
                foreach (TradingData trade in tradesList)
                {
                    OnTradeListItemHandled(trade);
                    if (trade.UpdateMarketPrice(_client.GetPrice(trade.CoinPair)))
                    {
                        // Update PriceChangePercentage
                        trade.SetPriceChangePercentage(trade.Price);

                        decimal stopLossPrice = trade.BuyPriceAfterFees * (1 - _settings.StopLossPerc / 100);
                        if (trade.Price < stopLossPrice)
                        {
                            PlaceCompleteSellOrder(trade, forReal: _settings.ProductionMode);
                        }
                    }
                }

                // cleanup
                tradesList.RemoveAll(td => td.BuyOrderID > -1 && td.SellOrderID > -1 && td.CoinQuantity == 0);
            }

            // Check for new email every second
            EmailHelper agent = new EmailHelper(_settings);

            // Check for new email
            if (!agent.NewMail)
            {
                Bot.WriteConsole($"{DateTime.Now} No new mail!");
                return;
            }

            // buy or sell signal
            if (!string.IsNullOrEmpty(agent.Subject))
            {
                if (!agent.Subject.Contains(_settings.SecretWord))
                {
                    return; // SPAM!
                }

                // Match coin pair
                CoinPair coinPair = new CoinPairHelper(_settings).GetCoinPair(agent.Subject);
                if (coinPair == null)
                {
                    Console.WriteLine("CoinPair not supported!");
                    return;
                }

                if (agent.Subject.Contains("Buy"))
                {
                    _signal = OrderSide.Buy;
                }
                else if (agent.Subject.Contains("Sell"))
                {
                    _signal = OrderSide.Sell;
                }

                // If no buy or sell orders for the required coin pair, then place an order
                TradingData tdSearch = tradesList.Find(x => x.CoinPair.Pair1 == coinPair.Pair1);

                if (tdSearch == null)
                {
                    TradingData trade = new TradingData(coinPair);
                    switch (_signal)
                    {
                    case OrderSide.Buy:
                        PlaceBuyOrder(trade, tradesList, forReal: _settings.ProductionMode);
                        break;
                    }
                }
                else // existing trades detected
                {
                    foreach (TradingData trade in tradesList)
                    {
                        if (_signal == OrderSide.Sell)
                        {
                            if (_settings.SellAllOnSellSignal)
                            {
                                PlaceCompleteSellOrder(trade, _settings.ProductionMode);
                            }
                            else
                            {
                                PlacePartialSellOrder(trade, forReal: _settings.ProductionMode);
                            }
                        }
                    }
                }
            }
        }