public async Task Consume(ConsumeContext <BuyCurrency> context) { var amountInCurrency = await _exchange.RiskManager.GetActualBuyAmount(); var rate = await _exchange.GetActualBuyPrice(); var converter = new TradeCalcService(); var amount = decimal.Round(converter.GetBuyAmount(amountInCurrency, rate), 8); var balanceMinLimit = _exchange.RiskManager.GetBalanceMinLimit(); Log.Information($"GET[BUY] => USD amount [{amount} / {amountInCurrency}] rate [{rate}]"); if (amountInCurrency <= balanceMinLimit) { Log.Warning($"Balance equal {amountInCurrency}. Risk manager stopping FarmMachine.ExchangeBroker"); return; } try { await _protocolService.WriteAsync(new Dictionary <string, object> { { "_id", context.Message.Id }, { "amount", amount }, { "bid", context.Message.Bid }, { "rate", rate }, { "timestamp", context.Message.Created }, { "type", "buy" } }, "BuyCurrency"); } catch (Exception ex) { Log.Warning($"Invalid write to db: {ex}"); } // await _exchange.PlaceOrderOnBuy(amount, rate); }