Ejemplo n.º 1
0
        public OrdersTask CreateTradeFromSignal(SignalVM signal, decimal investCapital, decimal currentPrice)
        {
            if (signal == null)
            {
                throw new ArgumentNullException("signal");
            }
            if (signal.SellPrice?.Any() == false)
            {
                throw new InvalidOperationException();
            }

            var     sellTasks = new List <TradeTask>(signal.SellPrice.Length);
            decimal amount    = currentPrice / investCapital;
            var     buyTask   = new TradeTask
            {
                Price  = currentPrice,
                Amount = amount,
            };

            decimal sellPortion = amount / signal.SellPrice.Length;

            foreach (var sellPrice in signal.SellPrice)
            {
                sellTasks.Add(new TradeTask
                {
                    Price  = sellPrice,
                    Amount = sellPortion,
                });
            }

            var result = new OrdersTask
            {
                Currency  = signal.Currency,
                StopLoss  = signal.StopLoss,
                BuyTask   = buyTask,
                SellTasks = sellTasks,
            };

            return(result);
        }
Ejemplo n.º 2
0
        public async Task ProcessTask(OrdersTask task, ExchangeBase exchange)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (exchange == null)
            {
                throw new ArgumentNullException("exchange");
            }

            string buyOrder = await exchange.PlaceOrderAsync(task.Currency, OrderType.Buy, task.BuyTask.Amount, task.BuyTask.Price);

            var sellOrders = new List <string>(task.SellTasks.Count);

            foreach (var sellTask in task.SellTasks)
            {
                var sellOrder = await exchange.PlaceLimitStopLossOrderAsync(task.Currency, OrderType.Sell, sellTask.Amount, sellTask.Price, task.StopLoss);

                sellOrders.Add(sellOrder);
            }
        }