From c03e38de497c0715341443ac1468a77b148686d0 Mon Sep 17 00:00:00 2001 From: konard Date: Thu, 11 Sep 2025 13:08:36 +0300 Subject: [PATCH 1/3] Initial commit with task details for issue #184 Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: https://github.com/linksplatform/Bot/issues/184 --- CLAUDE.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..b551b815 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,5 @@ +Issue to solve: https://github.com/linksplatform/Bot/issues/184 +Your prepared branch: issue-184-61e8c188 +Your prepared working directory: /tmp/gh-issue-solver-1757585312259 + +Proceed. \ No newline at end of file From 04bf2d9161b5a2e9723a9c70e61f40d6dd6ca0e1 Mon Sep 17 00:00:00 2001 From: konard Date: Thu, 11 Sep 2025 13:08:53 +0300 Subject: [PATCH 2/3] Remove CLAUDE.md - PR created successfully --- CLAUDE.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index b551b815..00000000 --- a/CLAUDE.md +++ /dev/null @@ -1,5 +0,0 @@ -Issue to solve: https://github.com/linksplatform/Bot/issues/184 -Your prepared branch: issue-184-61e8c188 -Your prepared working directory: /tmp/gh-issue-solver-1757585312259 - -Proceed. \ No newline at end of file From 2debc80fa666a3668f71c053af8fa4f9bec46efc Mon Sep 17 00:00:00 2001 From: konard Date: Thu, 11 Sep 2025 13:17:15 +0300 Subject: [PATCH 3/3] Add request tracking ID logging for Tinkoff API calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modified PlaceBuyOrder to log x-tracking-id header from PostOrderAsync - Modified PlaceSellOrder to log x-tracking-id header from PostOrderAsync - Modified CancelOrder to log x-tracking-id header from CancelOrderAsync - Added example demonstrating tracking ID extraction and logging - Tracking IDs are essential for efficient communication with Tinkoff support 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- csharp/TraderBot/TradingService.cs | 33 ++++++++++++++++++++-- examples/TrackingIdExample.cs | 45 ++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 examples/TrackingIdExample.cs diff --git a/csharp/TraderBot/TradingService.cs b/csharp/TraderBot/TradingService.cs index 0302809b..c22adadf 100644 --- a/csharp/TraderBot/TradingService.cs +++ b/csharp/TraderBot/TradingService.cs @@ -826,8 +826,17 @@ private async Task PlaceSellOrder(long amount, decimal price) // { // throw new InvalidOperationException($"Not enough amount to sell {amount} assets. Available amount: {securityPosition.Balance}"); // } - var response = await InvestApi.Orders.PostOrderAsync(sellOrderRequest).ResponseAsync; + using var call = InvestApi.Orders.PostOrderAsync(sellOrderRequest); + var headers = await call.ResponseHeadersAsync; + var response = await call.ResponseAsync; + + var trackingId = headers.GetValue("x-tracking-id"); Logger.LogInformation($"Sell order placed: {response}"); + if (!string.IsNullOrEmpty(trackingId)) + { + Logger.LogInformation($"Tinkoff request tracking ID: {trackingId}"); + } + return response; } @@ -847,21 +856,39 @@ private async Task PlaceBuyOrder(long amount, decimal price) // { // throw new InvalidOperationException($"Not enough money to buy {CurrentInstrument.Figi} asset."); // } - var response = await InvestApi.Orders.PostOrderAsync(buyOrderRequest).ResponseAsync; + using var call = InvestApi.Orders.PostOrderAsync(buyOrderRequest); + var headers = await call.ResponseHeadersAsync; + var response = await call.ResponseAsync; + + var trackingId = headers.GetValue("x-tracking-id"); var total = amount * price; SetCashBalance(CashBalanceFree - total, CashBalanceLocked + total); Logger.LogInformation($"Buy order placed: {response}"); + if (!string.IsNullOrEmpty(trackingId)) + { + Logger.LogInformation($"Tinkoff request tracking ID: {trackingId}"); + } + return response; } private async Task CancelOrder(string orderId) { - var response = await InvestApi.Orders.CancelOrderAsync(new CancelOrderRequest + using var call = InvestApi.Orders.CancelOrderAsync(new CancelOrderRequest { AccountId = CurrentAccount.Id, OrderId = orderId, }); + var headers = await call.ResponseHeadersAsync; + var response = await call.ResponseAsync; + + var trackingId = headers.GetValue("x-tracking-id"); Logger.LogInformation($"Order cancelled: {response}"); + if (!string.IsNullOrEmpty(trackingId)) + { + Logger.LogInformation($"Tinkoff request tracking ID: {trackingId}"); + } + return response; } diff --git a/examples/TrackingIdExample.cs b/examples/TrackingIdExample.cs new file mode 100644 index 00000000..a07285cc --- /dev/null +++ b/examples/TrackingIdExample.cs @@ -0,0 +1,45 @@ +using System; +using Grpc.Core; +using Microsoft.Extensions.Logging; + +namespace TraderBot.Examples +{ + /// + /// This example demonstrates how the tracking ID logging would work + /// when the Tinkoff API returns the x-tracking-id header + /// + public class TrackingIdExample + { + private readonly ILogger _logger; + + public TrackingIdExample(ILogger logger) + { + _logger = logger; + } + + /// + /// Example of how tracking ID is extracted and logged + /// This simulates what happens in the actual PlaceBuyOrder/PlaceSellOrder/CancelOrder methods + /// + public void SimulateTrackingIdLogging() + { + // Simulate a response with x-tracking-id header + var metadata = new Metadata + { + { "x-tracking-id", "550e8400-e29b-41d4-a716-446655440000" } + }; + + // Extract tracking ID (as done in the actual implementation) + var trackingId = metadata.GetValue("x-tracking-id"); + + // Log the tracking ID (as done in the actual implementation) + _logger.LogInformation($"Buy order placed: [order response details]"); + if (!string.IsNullOrEmpty(trackingId)) + { + _logger.LogInformation($"Tinkoff request tracking ID: {trackingId}"); + } + + Console.WriteLine($"Tracking ID logged: {trackingId}"); + } + } +} \ No newline at end of file