public async void Execute() { // Get all open orders var orders = await _plutusService.GetAllOpenOrders(); Parallel.ForEach(orders, async(orderTuple) => { var order = orderTuple.Item2; var key = orderTuple.Item1; // Get the current price of the order var newPrice = await _plutusService.GetPrice(order.Base, order.Symbol); // If current price is bigger than price + ProfitStop, OR if current price is lower than price - LossStop, sell if (newPrice > order.Price + order.ProfitStop || newPrice < order.Price - order.LossStop) { if (_test) { await _plutusService.SellTest(key, order.Symbol, order.Base, order.Amount, newPrice); } else { await _plutusService.Sell(key, order.Symbol, order.Base, order.Amount, newPrice); } } }); }
public void Execute() { Parallel.ForEach(_plutusService.Orders, async(order) => { // Check price of symbol var price = await _plutusService.GetPrice(order.Base, order.Symbol); // Determine if its going up or down var prediction = await _plutusService.GetPricePrediction(order.Base, order.Symbol, Period.Hourly); if (prediction == PricePrediction.Bullish) { // If its going up, var buyAmount = order.BuyAmount; // Calculate cost var cost = price * buyAmount; // Check if balance is sufficent var isBalanceSufficent = await _plutusService.CheckBalance(cost, order.Base); if (isBalanceSufficent) { // If balance is sufficient, buy if (_test) { await _plutusService.BuyTest(order.Symbol, order.Base, buyAmount, price); } else { await _plutusService.Buy(order.Symbol, order.Base, buyAmount, price); } } } }); }