private async Task SetBidOrder(Trading activeTrading = null) { var usdBalance = await _tradingApi.GetCashWallet <Wallet>("usd"); if (usdBalance.Attributes.Available < 1) { throw new Exception("There is not more money left"); } var actualBtcInformation = await _tradingApi.GetBtcPrice <Cryptocurrency>(); var PriceMargin = ((actualBtcInformation.Details.Price) - 6500) .CalculateProfitMargin(minimumProfitPercent, maximumProfitPercent); var order = new TradingOrdenRequest(usdBalance.Attributes.Available, ((actualBtcInformation.Details.Price) - 6500) - PriceMargin, _webJobConfiguration.BitexDefaultMarket, TradingContants.Bids); var attemptOrderData = (await _tradingApi.PlaceOrder <TradingOrder>(order, TradingContants.Bids)).Details; if (activeTrading == null) { await _strategyDatabaseAccess.CreateTradingOrder(attemptOrderData); } else { await _strategyDatabaseAccess.UpdateTradingOrder(attemptOrderData, activeTrading); } }
private async Task SetAskOrder(Trading actualOrder) { var btcBalance = await _tradingApi.GetCoinWallet <Wallet>(_webJobConfiguration.BtcWalletId); if (btcBalance.Attributes.Available < 1) { throw new Exception("There is not more btc left"); } var lastBidPrice = actualOrder.TradingTransactions.Last().CryptocurrencyPrice; var PriceMargin = lastBidPrice.CalculateProfitMargin(minimumProfitPercent, maximumProfitPercent); var order = new TradingOrdenRequest(btcBalance.Attributes.Available, lastBidPrice + PriceMargin, _webJobConfiguration.BitexDefaultMarket, TradingContants.Aks); var attemptOrderData = (await _tradingApi.PlaceOrder <TradingOrder>(order, TradingContants.Aks)).Details; await _strategyDatabaseAccess.UpdateTradingOrder(attemptOrderData, actualOrder); }