Beispiel #1
0
 /// <summary>
 /// Cancels an order when the user clicks on the Cancel button
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvOpenOrders_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0 && e.ColumnIndex == colCancel.Index)
     {
         long orderId = (dgvOpenOrders.Rows[e.RowIndex].Tag as OrderDetails).Id;
         var  callRes = _proxy.CancelOrder(orderId);
         if (callRes.Success)
         {
             dgvOpenOrders.Rows.RemoveAt(e.RowIndex);
             EventAggregator.Instance.Publish(new OrderCancelledMessage());
         }
         else
         {
             ErrorHelper.DisplayErrorMessage(callRes);
         }
     }
 }
        private BotInstanceData CancelExistingOrder(IBotInstanceData instance)
        {
            BotInstanceData data = (BotInstanceData)instance;

            foreach (var openOrder in data.OutstandingOrders)
            {
                try
                {
                    Console.WriteLine($"cancelling existing  order with id {openOrder.Reference}");
                    var canceledOrder = _exchange.CancelOrder(openOrder);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Exception canceling order  {openOrder.Reference}" + ex.ToString());
                }
            }
            return(data);
        }
Beispiel #3
0
        /// <summary>
        /// Method called on each new candle
        /// </summary>
        /// <param name="candles">The list of available candles</param>
        public void OnTick(IList <OHLC> candles)
        {
            if (candles.Count == 0)
            {
                return;
            }

            var candle = candles.Last();
            var balRes = _proxy.GetBalance(_settings.Pair);

            if (!balRes.Success)
            {
                return;
            }
            var bal    = balRes.Result;
            var feeRes = _proxy.GetFee(_pair);
            var fee    = feeRes.Result;

            decimal totalAmountItem2 = bal.Balances[_pair.Item2];
            decimal totalAmountItem1 = bal.Balances[_pair.Item1];

            decimal availableAmountItem2ToBuy   = totalAmountItem2 - _settings.MinAmountItem2ToKeep;
            decimal availableAmountItem1ForSell = totalAmountItem1 - _settings.MinAmountItem1ToKeep;

            var ordersRes = _proxy.GetOpenOrders(_settings.Pair);

            if (!ordersRes.Success)
            {
                return;
            }

            bool lastOrderFilled = _lastOrder == null || ordersRes.Result.List.FirstOrDefault(o => o.Id == _lastOrder.Id) == null;

            // return;

            var advice = _tradingIndicator.GetAdvice(candles);

            if (advice != Advice.None)
            {
                System.Diagnostics.Debug.WriteLine(DateTime.Now.ToShortTimeString() + " - Advice: " + advice.ToString());
                if (advice == Advice.Buy)
                {
                    if (_lastAdvice == Advice.Sell)
                    {
                        if (!lastOrderFilled)
                        {
                            var res = _proxy.CancelOrder(_lastOrder.Id);
                            if (res.Success)
                            {
                                availableAmountItem2ToBuy += _lastOrder.Amount * _lastOrder.Price;
                            }
                        }
                    }
                    else if (_lastAdvice == Advice.Buy)
                    {
                    }

                    availableAmountItem2ToBuy = availableAmountItem2ToBuy > _settings.MaxAmountMoneyPerBuyOrder ? _settings.MaxAmountMoneyPerBuyOrder : availableAmountItem2ToBuy;
                    decimal nbUnitsToBuy = Math.Round(availableAmountItem2ToBuy / candle.Close, 8);
                    //TODO: handle fees
                    PlaceBuyOrder(nbUnitsToBuy, candle.Close, candle.Date);
                }
                else if (advice == Advice.Sell)
                {
                    if (_lastAdvice == Advice.Buy)
                    {
                        if (!lastOrderFilled)
                        {
                            var res = _proxy.CancelOrder(_lastOrder.Id);
                            if (res.Success)
                            {
                                availableAmountItem1ForSell += _lastOrder.Amount;
                            }
                        }
                    }
                    else if (_lastAdvice == Advice.Sell)
                    {
                    }
                    decimal transactionFee = Math.Round(availableAmountItem1ForSell * candle.Close * fee.SellFee / 100m, 8);

                    decimal nbUnitsToSell = availableAmountItem1ForSell > _settings.MaxNbBTCPerSellOrder ? _settings.MaxNbBTCPerSellOrder : availableAmountItem1ForSell;
                    //TODO: handle fees
                    //Sell here
                    PlaceSellOrder(nbUnitsToSell, candle.Close, candle.Date);
                }
            }
            _lastAdvice = advice;
        }