public static TradingData GetTradingData(MarketTickData marketData, bool splitProfitMargin, decimal buyVolume, TradingFeeData feeData = null) { TradingData tradingData = new TradingData(); decimal profitMargin = splitProfitMargin ? BTCMarketsHelper.ProfitMargin / 2 : BTCMarketsHelper.ProfitMargin; decimal profitMultiplier = profitMargin / 100 + 1; tradingData.BuyVolume = buyVolume; decimal buyPrice = marketData.bestAsk; int roundPos = marketData.currency == "AUD" ? 2 : 8; buyPrice = Math.Round(splitProfitMargin ? buyPrice * (1 - profitMargin / 100) : buyPrice, roundPos); tradingData.BuyPrice = buyPrice; if (feeData == null) { feeData = JsonConvert.DeserializeObject <TradingFeeData>(BTCMarketsHelper.SendRequest(MethodConstants.TRADING_FEE_PATH(marketData.instrument, marketData.currency), null)); } decimal tradingFeeMultiplier = 1 + TradingFeeData.GetTradingFee(feeData); // Bot.Settings.TradingFee / 100.0 + 1; tradingData.SpendTotal = Math.Round(tradingData.BuyVolume * buyPrice * tradingFeeMultiplier, roundPos); tradingData.SellPrice = Math.Round(marketData.bestbid * profitMultiplier, roundPos); tradingData.SellVolume = Math.Round(tradingData.SpendTotal / tradingData.SellPrice, 8); return(tradingData); }
private void UpdateGuiControls() { BTCMarketsHelper.ProfitMargin = listProfitMargins[cboProfitMargin.SelectedIndex]; BTCMarketsHelper.ExchangeType = cboBuySell.Text; string txtUnit1 = cboBuySell.Text.Split('/')[0]; string txtUnit2 = cboBuySell.Text.Split('/')[1]; lblUnit1.Text = lblUnit1_1.Text = txtUnit1; lblUnit2.Text = lblUnit2_1.Text = lblUnit2_2.Text = txtUnit2; btnBuy.Content = lblBuy.Text = $"Buy {txtUnit1}"; btnSell.Content = lblSell.Text = $"Sell {txtUnit2}"; if (IsGuiReady) { if (!string.IsNullOrEmpty(txtVolume1.Text)) { double buyVolume; double.TryParse(txtVolume1.Text, out buyVolume); TradingData tradingData = TradingHelper.GetTradingData(BTCMarketsHelper.MarketTickData, Bot.Settings.ProfitMarginSplit, buyVolume); txtPrice1.Text = tradingData.BuyPrice.ToDecimalString(8); txtVolume2.Text = tradingData.SellVolume.ToDecimalString(8); txtPrice2.Text = tradingData.SellPrice.ToDecimalString(8); lblSpendTotal.Text = tradingData.SpendTotal.ToDecimalString(2); } UpdateTitle(); } }