Ejemplo n.º 1
0
        private void dgvClosedTrades_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            DataGridViewRow row   = ((DataGridView)sender).Rows[e.RowIndex];
            TradeModel      trade = (TradeModel)DataGridHelper.GetCell(row.Cells, "Trade");

            SetColor(row, trade);
        }
Ejemplo n.º 2
0
        private void PerformSell(TradeModel trade, bool fromSignal)
        {
            OrderModel order       = null;
            var        stopwatch   = new Stopwatch();
            long       elapsedTime = 0;

            txtLogs.AppendText($"{DateTime.Now} - {trade.CurrencyPair} => SELL {(fromSignal ? "(signal)" : "(tol)")} ...{Environment.NewLine}");
            trade.Status = EnumStatus.SELLING;
            dgvCurrentTrades.Refresh();

            stopwatch.Start();
            order = ExecuteOrder.ExecuteBuySell(OrderType.Sell, trade.CurrencyPair, trade.Amount, RealTrade);
            stopwatch.Stop();
            elapsedTime = stopwatch.ElapsedMilliseconds;

            txtLogs.AppendText($"{DateTime.Now} - {trade.CurrencyPair} => OK SOLD ({elapsedTime / 1000} secs){Environment.NewLine}");
            trade.Status = EnumStatus.SOLD;
            trade.Action = "BUY";

            DisposeSubscribeTicker(trade);
            AddClosedTrade(trade);
            trade.Ticker = null;
            trade.Status = EnumStatus.WAITING;
            dgvCurrentTrades.Refresh();
        }
Ejemplo n.º 3
0
        void dataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            DataGridViewRow row   = ((DataGridView)sender).Rows[e.RowIndex];
            TradeModel      trade = (TradeModel)DataGridHelper.GetCell(row.Cells, "Trade");

            SetColor(row, trade);
        }
Ejemplo n.º 4
0
 private void SetColor(DataGridViewRow row, TradeModel trade)
 {
     if (trade.Ticker != null)
     {
         if (trade.Ticker.Profit >= 5)
         {
             row.DefaultCellStyle.BackColor = Color.MediumPurple;
         }
         else if (trade.Ticker.Profit >= 1)
         {
             row.DefaultCellStyle.BackColor = Color.Lime;
         }
         else if (trade.Ticker.Profit >= 0)
         {
             row.DefaultCellStyle.BackColor = Color.LightGreen;
         }
         else
         {
             row.DefaultCellStyle.BackColor = Color.LightPink;
         }
     }
     else
     {
         row.DefaultCellStyle.BackColor = Color.White;
     }
 }
Ejemplo n.º 5
0
 private void AnalyseSignal(TradeModel trade, SignalModel signal)
 {
     if (signal.OrderType == OrderType.Buy)
     {
         if (trade.Status == EnumStatus.WAITING)
         {
             PerformBuy(trade);
         }
         else if (trade.Status == EnumStatus.BOUGHT)
         {
             txtLogs.AppendText($"{DateTime.Now} - {signal.CurrencyPair} => BUY - Already bought{Environment.NewLine}");
         }
     }
     else if (signal.OrderType == OrderType.Sell)
     {
         if (trade.Status == EnumStatus.BOUGHT)
         {
             PerformSell(trade, true);
         }
         else if (trade.Status == EnumStatus.WAITING)
         {
             txtLogs.AppendText($"{DateTime.Now} - {signal.CurrencyPair} => SELL - Already sold{Environment.NewLine}");
         }
     }
 }
Ejemplo n.º 6
0
        private Subject <SignalModel> SetManualSignal()
        {
            Subject <SignalModel> manualSignal = new Subject <SignalModel>();

            this.dgvCurrentTrades.CellContentClick += (object sender, DataGridViewCellEventArgs e) =>
            {
                var senderGrid = (DataGridView)sender;

                if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
                {
                    TradeModel trade = (TradeModel)DataGridHelper.GetCell(dgvCurrentTrades.CurrentRow.Cells, "Trade");

                    OrderType orderType = OrderType.Buy;
                    if (trade.Action == OrderType.Buy.ToString().ToUpper())
                    {
                        orderType = OrderType.Buy;
                    }
                    else if (trade.Action == OrderType.Sell.ToString().ToUpper())
                    {
                        orderType = OrderType.Sell;
                    }

                    SignalModel signal = new SignalModel()
                    {
                        CurrencyPair = trade.CurrencyPair,
                        OrderType    = orderType
                    };

                    manualSignal.OnNext(signal);
                }
            };
            return(manualSignal);
        }
Ejemplo n.º 7
0
        public TradeModel(TradeModel trade)
        {
            CurrencyPair  = trade.CurrencyPair;
            Status        = trade.Status;
            ToleranceBuy  = trade.ToleranceBuy;
            Tolerance     = trade.Tolerance;
            Multiplicator = trade.Multiplicator;
            Amount        = trade.Amount;
            PricePaid     = trade.PricePaid;
            TolAjusted    = trade.TolAjusted;
            TimeBuy       = trade.TimeBuy;
            Action        = trade.Action;

            if (trade.Ticker != null)
            {
                Ticker = new TickerModel()
                {
                    BaseCurrencyTotal = trade.Ticker.BaseCurrencyTotal,
                    HighestPrice      = trade.Ticker.HighestPrice,
                    HighestProfit     = trade.Ticker.HighestProfit,
                    HPDiff            = trade.Ticker.HPDiff,
                    LastTicker        = trade.Ticker.LastTicker,
                    PriceLast         = trade.Ticker.PriceLast,
                    Profit            = trade.Ticker.Profit,
                    UsdtValue         = trade.Ticker.UsdtValue
                };
            }
        }
Ejemplo n.º 8
0
 private void DisposeSubscribeTicker(TradeModel trade)
 {
     if (_subsTickers.TryGetValue(trade.CurrencyPair, out IDisposable subscribe))
     {
         _subsTickers.Remove(trade.CurrencyPair);
         subscribe.Dispose();
     }
 }
Ejemplo n.º 9
0
        private void btnStartBot_Click(object sender, EventArgs e)
        {
            TradeModel trade = new TradeModel()
            {
                CurrencyPair  = CurrencyPair,
                Status        = EnumStatus.WAITING,
                Amount        = GetBotAmount(),
                ToleranceBuy  = double.Parse(lblValueToleranceBuy.Text),
                Tolerance     = double.Parse(Utilities.TryParseDouble(BotLosstolerance).ToString()),
                Multiplicator = double.Parse(Utilities.TryParseDouble(BotMultiplicator).ToString()),
                Action        = "BUY"
            };

            AddBot(trade);
        }
Ejemplo n.º 10
0
        private void UpdateCurrentTrades(TradeModel trade)
        {
            FlatTradeModel flatTrade = _blCurrentTrades.Where(x => object.Equals(x.Trade.CurrencyPair, trade.CurrencyPair)).First();

            flatTrade.Trade = trade;

            dgvCurrentTrades.Refresh();

            if (CheckTolerance(trade))
            {
                PerformSell(trade, false);
            }

            CalculTotalProfit();
        }
Ejemplo n.º 11
0
        private bool CheckTolerance(TradeModel trade)
        {
            if (trade.Ticker == null)
            {
                return(false);
            }

            trade.TolAjusted = trade.Tolerance + (trade.Ticker.HighestProfit * trade.Multiplicator);

            trade.TolAjusted = trade.TolAjusted > trade.Tolerance / 4 ? trade.Tolerance / 4 : trade.TolAjusted;

            if (trade.Ticker.Profit < double.Parse(lblValueToleranceBuy.Text) ||
                trade.Ticker.HPDiff < trade.TolAjusted)
            {
                System.Media.SystemSounds.Exclamation.Play();
                return(true);
            }
            return(false);
        }
Ejemplo n.º 12
0
        private void AddBot(TradeModel trade)
        {
            if (!_blCurrentTrades.Select(x => x.CurrencyPair).Contains(trade.CurrencyPair.ToString()))
            {
                FlatTradeModel flatTrade = new FlatTradeModel(trade);
                _blCurrentTrades.Add(flatTrade);

                Subject <SignalModel> manualSignal = SetManualSignal();

                _signal = new Signal(trade.CurrencyPair);
                _subsSignals.Add(trade.CurrencyPair,
                                 _signal.DataSource
                                 .Merge(manualSignal)
                                 .ObserveOn(WindowsFormsSynchronizationContext.Current)
                                 .Subscribe(x => AnalyseSignal(trade, x)));
            }
            else
            {
                txtLogs.AppendText($"Bot {trade.CurrencyPair} => Already running{Environment.NewLine}");
            }
        }
Ejemplo n.º 13
0
        private void PerformBuy(TradeModel trade)
        {
            OrderModel order       = null;
            var        stopwatch   = new Stopwatch();
            long       elapsedTime = 0;

            txtLogs.AppendText($"{DateTime.Now} - {trade.CurrencyPair} => BUY ...{Environment.NewLine}");
            trade.Status = EnumStatus.BUYING;
            dgvCurrentTrades.Refresh();

            stopwatch.Start();
            order = ExecuteOrder.ExecuteBuySell(OrderType.Buy, trade.CurrencyPair, 0, RealTrade);
            stopwatch.Stop();
            elapsedTime = stopwatch.ElapsedMilliseconds;

            txtLogs.AppendText($"{DateTime.Now} - {trade.CurrencyPair} => OK BOUGHT ({elapsedTime / 1000} secs){Environment.NewLine}");
            trade.Status     = EnumStatus.BOUGHT;
            trade.PricePaid  = order.PricePerCoin;
            trade.TolAjusted = trade.Tolerance;
            trade.TimeBuy    = DateTime.Now;
            trade.Action     = "SELL";

            dgvCurrentTrades.Refresh();

            _ticker = new Ticker(trade.CurrencyPair, trade.Amount, trade.PricePaid, 0);

            if (!_subsTickers.TryGetValue(trade.CurrencyPair, out IDisposable subscribe))
            {
                _subsTickers.Add(trade.CurrencyPair, (_ticker.DataSource
                                                      .ObserveOn(WindowsFormsSynchronizationContext.Current)
                                                      .Subscribe(x =>
                {
                    trade.Ticker = x;
                    UpdateCurrentTrades(trade);
                })));
            }
        }
Ejemplo n.º 14
0
 public FlatTradeModel(TradeModel trade)
 {
     Trade = new TradeModel(trade);
 }
Ejemplo n.º 15
0
        private void AddClosedTrade(TradeModel trade)
        {
            FlatTradeModel flatTrade = new FlatTradeModel(trade);

            _blClosedTrades.Add(flatTrade);
        }