public async Task <XCommasResponse <Deal> > UpdateDealAsync(int dealId, DealUpdateData data) { var path = $"{BaseAddress}/ver1/deals/{dealId}/update_deal"; using (var request = XCommasRequest.Patch(path).WithSerializedContent(data).Sign(this)) { return(await this.GetResponse <Deal>(request).ConfigureAwait(false)); } }
public async Task UpdateDealAsync(DealUpdateData data, Guid xCommasAccount) { var res = await _3CommasClients[xCommasAccount].Item2.UpdateDealAsync(data.DealId, data); if (res.IsSuccess) { _logger.LogInformation($"Deal {data.DealId} updated"); } else { _logger.LogError($"Could not update deal {data.DealId}. Reason: {res.Error}"); } }
public XCommasResponse <Deal> UpdateDeal(int dealId, DealUpdateData data) => this.UpdateDealAsync(dealId, data).Result;
//static List<(int SO, decimal Tp)> tpTargets = new List<(int SO, decimal Tp)> //{ // (0, 0.42m), // (1, 0.42m), // (2, 0.42m), // (3, 1.0m), // (4, 2.0m), // (5, 3.0m), // (6, 4.0m), // (7, 5.0m), // (8, 6.0m) //}; static async Task Main(string[] args) { Console.WriteLine("BlockParty SDCA tool " + typeof(Program).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion); var builder = new ConfigurationBuilder() .AddJsonFile($"appsettings.json", true, false); var config = builder.Build(); var c = config.GetSection("tp"); List <SOTP> tpTargets = new List <SOTP>(); c.Bind(tpTargets); //var list = c.GetChildren().ToList(); var tableData = new List <List <object> >(); foreach (var item in tpTargets) { tableData.Add(new List <object> { item.SO, item.TP + "%" }); } ConsoleTableBuilder .From(tableData) .WithMinLength(new Dictionary <int, int> { { 0, 15 }, { 1, 15 } }) .WithTextAlignment(new Dictionary <int, TextAligntment> { { 0, TextAligntment.Center }, { 1, TextAligntment.Center } }) .WithFormat(ConsoleTableBuilderFormat.Alternative) .WithTitle("TP targets", ConsoleColor.Yellow, ConsoleColor.DarkGray) .WithColumn("SO", "TP") .ExportAndWriteLine(); if (args.Length < 3) { Console.WriteLine($"Please specify bot name and API key"); return; } var botName = args[0]; var apiKey = args[1]; var secret = args[2]; var client = new XCommas.Net.XCommasApi(apiKey, secret); Console.WriteLine($"Bot name {botName}"); var response = await client.GetDealsAsync(limit : 1000, dealScope : DealScope.Active, dealOrder : DealOrder.CreatedAt); if (response.IsSuccess) { var deals = response.Data.Where(deal => deal.BotName == botName); Console.WriteLine($"{deals.Count()} deals."); foreach (var deal in deals) { Console.WriteLine($"{deal.BotName} {deal.Pair} SO {deal.CompletedSafetyOrdersCount} TP {deal.TakeProfit}"); var tpTarget = tpTargets.SingleOrDefault(m => m.SO == deal.CompletedSafetyOrdersCount); if (tpTarget != default) { if (deal.TakeProfit != tpTarget.TP) { decimal takeProfit = tpTarget.TP; DealUpdateData dealUpdateData = new DealUpdateData(deal.Id) { TakeProfit = takeProfit }; Console.WriteLine($"Set take profit {takeProfit}%"); await client.UpdateDealAsync(deal.Id, dealUpdateData); } } } } else { Console.WriteLine(response.Error); } }
public static async Task Main(string[] args) { // Get variables from config file // Generate your api key and secret with Paper Trading enabled const string apiKey = "your-api-key"; const string apiSecret = "your-api-secret"; // Create client Console.WriteLine("Connecting"); var client = new XCommasApi(apiKey, apiSecret); // Perform GET request - Get Currency Rate { var response = await client.GetBotsAsync(botScope : BotScope.Enabled); foreach (var bot in response.Data) { Console.WriteLine($"{bot.Id} - {bot.Name}"); } } Console.WriteLine("Press any key for next query"); Console.ReadKey(); // Perform GET request - Get Active Deals IReadOnlyCollection <Deal> candidatesForTsl; { var response = await client.GetDealsAsync(dealScope : DealScope.Active); var positiveDeals = new HashSet <Deal>(); foreach (var deal in response.Data) { Console .WriteLine($"Bot {deal.BotId} - {deal.Pair} - BO: {deal.BaseOrderVolume} - Bought: {deal.BoughtAmount} - AvgPrice: {deal.BoughtAveragePrice} - Current Price: {deal.CurrentPrice} - Actual Profit: {deal.ActualProfitPercentage} / {deal.ActualProfit} - TP: {deal.TakeProfit} / {deal.TakeProfitPrice}"); if (deal.ActualProfit > decimal.Zero) { positiveDeals.Add(deal); } } Console .WriteLine($"There are {positiveDeals.Count} deals in profit:"); foreach (var deal in positiveDeals) { Console .WriteLine($"{deal.Pair} - +{deal.ActualProfitPercentage} % - +{deal.ActualProfit} {deal.FromCurrency}"); } candidatesForTsl = new HashSet <Deal>(positiveDeals .Where(d => d.ActualProfitPercentage.GetValueOrDefault() > 0.5m)); } // For every candidate for TSL, we calculate and update it foreach (var deal in candidatesForTsl) { var newStopLossPercentage = (deal.ActualProfitPercentage ?? 100) / 2; var isStopLossTakeProfit = deal.StopLossPercentage.HasValue && deal.StopLossPercentage < 0; if ( isStopLossTakeProfit && Math.Abs(newStopLossPercentage) >= newStopLossPercentage ) { continue; } var dealId = deal.Id; var updateBody = new DealUpdateData(dealId) { StopLossPercentage = -newStopLossPercentage }; Console.WriteLine($"Updating deal {dealId} - {deal.Pair}"); var response = await client.UpdateDealAsync(dealId, updateBody); Console .WriteLine($"Success {dealId} - {deal.Pair} - Currently +{deal.ActualProfitPercentage} - TSL to +{newStopLossPercentage}"); Console.WriteLine(response.Error ?? response.RawData); } // Wait until key from dev Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
private async void btnEdit_Click(object sender, EventArgs e) { var ids = tableControl.SelectedIds; if (IsValid(ids)) { var dlg = new EditDealDialog.EditDealDialog(ids.Count, new XCommasLayer(_keys, _logger)); var editData = new EditDealDto(); dlg.EditDto = editData; var dr = dlg.ShowDialog(this); if (dr == DialogResult.OK) { var botMgr = new XCommasLayer(_keys, _logger); await ExecuteBulkOperation($"Are you sure to update {tableControl.SelectedIds.Count} deals?", "Applying new settings", async deal => { var updateData = new DealUpdateData(deal.Id); if (editData.ActiveSafetyOrdersCount.HasValue) { updateData.MaxSafetyOrdersCount = editData.ActiveSafetyOrdersCount.Value; } if (editData.MaxSafetyOrders.HasValue) { updateData.MaxSafetyOrders = editData.MaxSafetyOrders.Value; } if (editData.TakeProfit.HasValue) { updateData.TakeProfit = editData.TakeProfit.Value; } if (editData.TakeProfitType.HasValue) { updateData.TakeProfitType = editData.TakeProfitType.Value; } if (editData.TrailingDeviation.HasValue) { updateData.TrailingDeviation = editData.TrailingDeviation.Value; } if (editData.TrailingEnabled.HasValue) { updateData.TrailingEnabled = editData.TrailingEnabled.Value; } if (editData.StopLossPercentage.HasValue) { updateData.StopLossPercentage = editData.StopLossPercentage.Value; } if (editData.StopLossType.HasValue) { updateData.StopLossType = editData.StopLossType.Value; } if (editData.StopLossTimeoutEnabled.HasValue) { updateData.StopLossTimeoutEnabled = editData.StopLossTimeoutEnabled.Value; } if (editData.StopLossTimeout.HasValue) { updateData.StopLossTimeoutInSeconds = editData.StopLossTimeout.Value; } await botMgr.UpdateDealAsync(updateData, deal.XCommasAccountId); }); } } }