コード例 #1
0
ファイル: MainForm.cs プロジェクト: Chuckgith/megabot
        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();
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Chuckgith/megabot
        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);
                })));
            }
        }